summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-07 20:37:17 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-07 20:37:17 -0500
commit6d3b33fa6c32c8702bab887e621f9cf61aaf9108 (patch)
treee6b0c221300434404a012f1e99c58269e3d7f64f
parenta7bcebe96bd00388fea1c2cf01e0691534f61744 (diff)
downloadfedora-devshell-6d3b33fa6c32c8702bab887e621f9cf61aaf9108.tar.gz
fedora-devshell-6d3b33fa6c32c8702bab887e621f9cf61aaf9108.tar.xz
fedora-devshell-6d3b33fa6c32c8702bab887e621f9cf61aaf9108.zip
Adds working customizable profiles with mock configurations
-rw-r--r--base/profiles.py48
-rw-r--r--base/util.py8
-rw-r--r--base/vars.py1
-rw-r--r--modules/build.py14
-rw-r--r--modules/mock.py60
-rw-r--r--modules/package.py4
-rw-r--r--modules/profile.py68
7 files changed, 133 insertions, 70 deletions
diff --git a/base/profiles.py b/base/profiles.py
index 667dcf6..0e09317 100644
--- a/base/profiles.py
+++ b/base/profiles.py
@@ -38,10 +38,10 @@ def join_defines(*defines):
return flatten(defines)
def dist_defines(dist, distvar, distval):
- dist = define('dist', dist)
- distvar = define(distvar, distval)
- distdef = define(distdef(dist), 1)
- return join_defines([dist, distvar, distdef])
+ _dist = define('dist', dist)
+ _distvar = define(distvar, distval)
+ _distdef = define(distdef(dist), 1)
+ return join_defines([_dist, _distvar, _distdef])
head_branch = 'devel'
@@ -60,6 +60,7 @@ def dir_defines(some_dir):
defs.append(define('_rpmdir', join(some_dir, 'RPMS')))
return join_defines(defs)
+# The logic behind this comes from the Makefile.common in Fedora
def ver_rel(spec_file, defines=''):
rpm_p = Popen('rpm %s -q --qf "%%{VERSION} %%{RELEASE}\n" --specfile %s' % \
(defines, spec_file), stdout=PIPE, shell=True)
@@ -67,31 +68,32 @@ def ver_rel(spec_file, defines=''):
verrel = verrels.split('\n')[0]
return verrel.split(' ')
+# The logic behind this comes from the Makefile.common in Fedora
def name(spec_file, defines=''):
rpm_p = Popen('rpm %s -q --qf "%%{NAME}\n" --specfile %s' % \
(defines, spec_file), stdout=PIPE, shell=True)
return rpm_p.communicate()[0].split('\n')[0]
#taken from CVS for now
-distro = [{'RHL-7':('rhl7','.rhl7','rhl','7'),
- 'RHL-8':('rhl8','.rhl8','rhl','8'),
- 'RHL-9':('rhl9','.rhl9','rhl','9'),
- 'OLPC-2':('dist-olpc2','.olpc2','olpc','2'),
- 'OLPC-3':('dist-olpc3','.olpc3','olpc','3'),
- 'EL-4':('el4','.el4','epel','4'),
- 'EL-5':('el5','.el5','epel','5'),
- 'FC-1':('fc1','.fc1','fedora','1'),
- 'FC-2':('fc2','.fc2','fedora','2'),
- 'FC-3':('fc3','.fc3','fedora','3'),
- 'FC-4':('fc4','.fc4','fedora','4'),
- 'FC-5':('fc5','.fc5','fedora','5'),
- 'FC-6':('fc6','.fc6','fedora','6'),
- 'F-7':('dist-fc7','.fc7','fedora','7'),
- 'F-8':('dist-f8','.fc8','fedora','8'),
- 'F-9':('dist-f9','.fc9','fedora','9'),
- 'F-10':('dist-f10','.fc10','fedora','10'),
- 'F-11':('dist-f11','.fc11','fedora','11'),
- 'devel':('dist-devel','.devel','fedora','10')}]
+distro = {'RHL-7':('rhl7','.rhl7','rhl','7'),
+ 'RHL-8':('rhl8','.rhl8','rhl','8'),
+ 'RHL-9':('rhl9','.rhl9','rhl','9'),
+ 'OLPC-2':('dist-olpc2','.olpc2','olpc','2'),
+ 'OLPC-3':('dist-olpc3','.olpc3','olpc','3'),
+ 'EL-4':('el4','.el4','epel','4'),
+ 'EL-5':('el5','.el5','epel','5'),
+ 'FC-1':('fc1','.fc1','fedora','1'),
+ 'FC-2':('fc2','.fc2','fedora','2'),
+ 'FC-3':('fc3','.fc3','fedora','3'),
+ 'FC-4':('fc4','.fc4','fedora','4'),
+ 'FC-5':('fc5','.fc5','fedora','5'),
+ 'FC-6':('fc6','.fc6','fedora','6'),
+ 'F-7':('dist-fc7','.fc7','fedora','7'),
+ 'F-8':('dist-f8','.fc8','fedora','8'),
+ 'F-9':('dist-f9','.fc9','fedora','9'),
+ 'F-10':('dist-f10','.fc10','fedora','10'),
+ 'F-11':('dist-f11','.fc11','fedora','11'),
+ 'devel':('dist-devel','.devel','fedora','11')}
# this class is temporary, it's only for mimickng CVS for now
# later we'll come up with a better way to do custom profiles
diff --git a/base/util.py b/base/util.py
index 0d4723c..e192b94 100644
--- a/base/util.py
+++ b/base/util.py
@@ -25,6 +25,7 @@ from os import symlink as sym
from os.path import abspath, lexists, isdir, islink, isfile
from shutil import copyfileobj, rmtree
from shutil import move as mv
+from shutil import copytree as cpthree
from urllib import urlopen
from base import log
@@ -77,6 +78,13 @@ def move(src, dst):
mv(src, dst)
return dst
+def copytree(src, dst):
+ if lexists(dst):
+ rm(dst)
+ # cee-pee-tree in jamaica, mon!
+ cpthree(src, dst)
+ return dst
+
def one(l, f):
for x in l:
if f(x):
diff --git a/base/vars.py b/base/vars.py
index 231322a..901fd49 100644
--- a/base/vars.py
+++ b/base/vars.py
@@ -23,6 +23,7 @@ __description__ = 'A shell for hacking on the Fedora project'
FEDORA_DIR = join(expanduser('~'), 'code')
DEVSHELL_DIR = join(expanduser('~'), '.devshell')
+MOCK_CFG_DIR = '/etc/mock'
header = lambda x: "%s %s %s" % ('=' * 2, x, '=' * (76 - len(x)))
prompt = ['\033[34;1mfedora\033[0m']
diff --git a/modules/build.py b/modules/build.py
index 9955512..cc61868 100644
--- a/modules/build.py
+++ b/modules/build.py
@@ -33,6 +33,7 @@ from base.profiles import dir_defines, join_defines, dist_defines, Profile
from modules.directory import Directory
from modules.dirfactory import DirFactory
from modules.package import Package
+from modules.profile import Profile
class Build(Directory):
_type = 'build'
@@ -47,11 +48,11 @@ class Build(Directory):
for patch in patches:
symlink(patch, join(self.dir, 'SOURCES', patch))
- def build_quick_rpm(self, package):
- self.rpmbuild('-ba', package)
+ def build_quick_rpm(self, package, profile=None):
+ self.rpmbuild('-ba', package, profile)
- def build_source_rpm(self, package):
- self.rpmbuild('-bs', package)
+ def build_source_rpm(self, package, profile=None):
+ self.rpmbuild('-bs', package, profile)
def rpmbuild(self, param, package, profile=None):
pkg = DirFactory(package)
@@ -73,14 +74,15 @@ class Build(Directory):
p.wait()
log.debug(p.returncode)
- def fetch_rpms(self):
+ def fetch_rpms(self, target_dir):
with pwd(self.dir):
for path, dirs, files in walk('.'):
for f in files:
if f.endswith('.rpm'):
#TODO: Gotta figure out what should be FEDORA_DIR
# Probably something involving "Project" or i dunno what
- move(join(path, f), join(FEDORA_DIR, f))
+ # it's something temporary for now, don't commi this
+ move(join(path, f), join(target_dir, f))
def fetch_build(self, package):
pkg = DirFactory(package)
diff --git a/modules/mock.py b/modules/mock.py
index a49231f..aaa0108 100644
--- a/modules/mock.py
+++ b/modules/mock.py
@@ -17,47 +17,47 @@
#
from __future__ import with_statement
+from subprocess import Popen
+
+from base.base import log
from base.module import Module
-from base.vars import FEDORA_DIR
-from base.profiles import ver_rel, Profile
+from base.profiles import ver_rel
+from base.util import pwd
+
from modules.build import Build
+from modules.dirfactory import DirFactory
from modules.package import Package
+from modules.profile import Profile
class Mock(Module):
- def __init__(self, target_dir, name, profile):
- self.target_dir = target_dir
- self.name = name
- self.pkg = Package(name)
- self.build = Build(name, target_dir)
- # for now we're using the old profile form, namely a branch
- # TODO: fix real profiles
+ def __init__(self, profile, build):
+ self.build = Build(build)
self.profile = Profile(profile)
- def build_rpm(self, target_dir=None):
- if not target_dir:
- if self.target_dir:
- target_dir = self.target_dir
- else:
- raise ExecutionException(None, 'no Target Dir specified')
-
- self.build.build_source_rpm(target_dir, self.profile)
- self.build.fetch_rpms(target_dir)
-
- srpm_name = self.pkg.get_srpm_name(self.profile)
+ def build_rpm(self, package):
+ pkg = DirFactory(package)
+
+ self.build.build_source_rpm(package, self.profile)
+ self.build.fetch_rpms(self.profile.result_dir)
+
+ srpm_name = pkg.get_srpm_name(self.profile)
mock_cfg = self.profile.mock_cfg
result_dir = self.profile.result_dir
- config_dir = self.profile.config_dir
- with pwd(self.pkg.code_dir):
+ config_dir = self.profile.mock_cfg_dir
+ cmd = ['mock', '-r %s' % mock_cfg,
+ '--configdir=%s' % config_dir,
+ '--resultdir=%s' % result_dir,
+ srpm_name]
+ log.debug('cmd is ' + str(cmd))
+ with pwd(pkg.dir):
with file('mock.log', 'w') as mock_out:
- with pwd(FEDORA_DIR):
- p = Popen(['/usr/bin/mock',
- '-r %s' % mock_cfg,
- '--configdir=%s' % config_dir,
- '--resultdir=%s' % result_dir,
- srpm_name],
- stdout=mock_out, stderr=mock_out)
- log.info('quick compiling %s... please wait' % srpm_name)
+ with pwd(result_dir):
+ p = Popen(cmd, stdout=mock_out, stderr=mock_out)
+ log.info('mock compiling %s... please wait' % srpm_name)
p.wait()
+ def close(self):
+ self.build.close()
+ self.profile.close()
__all__ = ['Mock']
diff --git a/modules/package.py b/modules/package.py
index d123446..983a2aa 100644
--- a/modules/package.py
+++ b/modules/package.py
@@ -69,12 +69,12 @@ class Package(Directory):
def get_srpm_name(self, profile):
with pwd(self.code_dir):
- ver, rel = ver_rel(self.spec_file, profile.dist_defines())
+ ver, rel = ver_rel(self.spec_file, profile.dist_defines)
return '%s-%s-%s.src.rpm' % (self.pkg_name, ver, rel)
def ver(self, profile=None):
with pwd(self.dir):
- ver, rel = ver_rel(self.spec_file, profile.dist_defines() if profile else '')
+ ver, rel = ver_rel(self.spec_file, profile.dist_defines if profile else '')
return ver
def source_dir(self, *args):
diff --git a/modules/profile.py b/modules/profile.py
index 40b38ae..56639cb 100644
--- a/modules/profile.py
+++ b/modules/profile.py
@@ -15,17 +15,67 @@
#
# Authors: Yaakov M. Nemoy <ynemoy@redhat.com>
#
+from __future__ import with_statement
+
+from os.path import join
-from base.module import Module
from base.exceptions import ExecutionException
+from base.profiles import dist_defines, get_mock_cfg, distro, TARGET, DIST, DISTVAR, DISTVAL
+from base.util import pwd, copytree
+from base.vars import MOCK_CFG_DIR
+
+from modules.directory import Directory
+
+class Profile(Directory):
+ _type = 'profile'
+ @property
+ def dist(self):
+ '''eg .fc7 or .olpc2
+ used in rpmmacro %dist'''
+ return self.cfg['dist']
+
+ @property
+ def distvar(self):
+ 'eg: fedora or rhel'
+ return self.cfg['distvar']
+
+ @property
+ def distval(self):
+ 'eg: 10 or 3 (string form)'
+ return self.cfg['distval']
+
+ @property
+ def koji_target(self):
+ 'eg: dist-f11'
+ return self.cfg['koji_target']
+
+ @property
+ def dist_defines(self):
+ return dist_defines(self.dist, self.distvar, self.distval)
+
+ # i'm not sure this is 100% relevant, mock cfg's might be named only after the arch used
+ @property
+ def mock_cfg(self):
+ # TODO: buildarchs need to be handled somehow
+ # yes i'm lame and i did this i386 only for now
+ return get_mock_cfg(self.distvar, self.distval, 'i386')
+
+ @property
+ def mock_cfg_dir(self):
+ return join(self.dir, 'mock')
-class Profile(Module):
- def __init__(self, name=None, branch=None):
- if branch:
- pass
- elif name:
- pass
- else:
- raise ExecutionException('need a saved profile or a branch to lookup')
+ @property
+ def result_dir(self):
+ return self.dir
+ def configure_from_system(self, branch):
+ self.cfg['branch'] = branch
+ d = distro[branch]
+ self.cfg['koji_target'] = d[TARGET]
+ self.cfg['distval'] = d[DISTVAL]
+ self.cfg['distvar'] = d[DISTVAR]
+ self.cfg['dist'] = d[DIST]
+ with pwd(self.dir):
+ copytree(MOCK_CFG_DIR, self.mock_cfg_dir)
+
__all__ = ['Profile']