diff options
author | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2008-06-28 15:48:25 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2008-06-28 15:48:25 +0530 |
commit | a8b8677fb457bb6d0a5d1c585c0b95277212a7d0 (patch) | |
tree | ba4deea22f8f4fac97f280085deece71b43b920d /slave/autotua | |
parent | - Implement basic jobuild parsing (jobuild.sh, jobuild-functions.sh, jobuild/... (diff) | |
download | autotua-a8b8677fb457bb6d0a5d1c585c0b95277212a7d0.tar.gz autotua-a8b8677fb457bb6d0a5d1c585c0b95277212a7d0.tar.bz2 autotua-a8b8677fb457bb6d0a5d1c585c0b95277212a7d0.zip |
- Implement jobuild atom parsing and autotua.jobuild.Jobuild()._best_jobuild() (incomplete)
- Always use a tuple in autotua.sync.Command()._get_args(); fixes a nasty runtime bug
- Use subprocess module in autotua.chroot
- Implement an (incomplete) autotua.chroot.WorkChroot().clean()
- Implement an (incomplete) autotua.Job().clean() which calls autotua.chroot.WorkChroot().clean()
- Pass around jobdir = '/var/tmp/autotua/work/<job_atom>/' instead of jobtagedir, chrootdir etc
- Add testing for autotua.Job() in test_modules.py
- scripts/init-autotua-tmpdirs.sh for initialising the tmpdir structure
- Add README
Diffstat (limited to 'slave/autotua')
-rw-r--r-- | slave/autotua/__init__.py | 11 | ||||
-rw-r--r-- | slave/autotua/chroot/__init__.py | 33 | ||||
-rw-r--r-- | slave/autotua/jobuild/__init__.py | 40 | ||||
-rw-r--r-- | slave/autotua/sync/__init__.py | 12 |
4 files changed, 61 insertions, 35 deletions
diff --git a/slave/autotua/__init__.py b/slave/autotua/__init__.py index c774415..7fee008 100644 --- a/slave/autotua/__init__.py +++ b/slave/autotua/__init__.py @@ -33,12 +33,12 @@ class Job: self.maint = job_data['maintainer'] self.name = job_data['name'] self.stage = self._stage_fetchable(job_data) - self.jobtagedir = osp.join(const.WORKDIR, self.maint, self.name, 'jobtage') + self.jobdir = osp.join(const.WORKDIR, self.maint, self.name) self.jobtagerev = job_data['jobtagerev'] self.jobuilds = [] for atom in job_data['jobuilds']: - self.jobuilds.append(jobuild.Jobuild(atom)) - self.chroot = chroot.WorkChroot(self.maint, self.name, self.stage.filename) + self.jobuilds.append(jobuild.Jobuild(self.jobdir, atom)) + self.chroot = chroot.WorkChroot(self.jobdir, self.stage.filename) def __repr__(self): return '<%s: %s>' % (self.name, 'Job object') @@ -94,7 +94,7 @@ class Job: # Sync jobtage tree sync.Syncer().sync() # Branch local jobtage tree - sync.Syncer(uri=const.JOBTAGE_DIR, destdir=self.jobtagedir, + sync.Syncer(uri=const.JOBTAGE_DIR, destdir=osp.join(self.jobdir, 'jobtage'), rev=self.jobtagerev, scheme="bzr-export").sync() ## Read config, get portage snapshot if required #self._fetch_portage_snapshot() @@ -108,3 +108,6 @@ class Job: def run(self): print "Rheeet, it's running!~ NOT." + + def clean(self): + self.chroot.clean() diff --git a/slave/autotua/chroot/__init__.py b/slave/autotua/chroot/__init__.py index d29d0e0..9d410af 100644 --- a/slave/autotua/chroot/__init__.py +++ b/slave/autotua/chroot/__init__.py @@ -79,16 +79,18 @@ class WorkChroot(object): """ Chroot where all the action happens """ - def __init__(self, job_maint, job_name, stage_file): + def __init__(self, jobdir, stage_file): """ @param job: Job to be run inside the chroot @type job: L{autotua.Job} """ self.pristine = PristineChroot(stage_file) - self.dir = osp.join(const.WORKDIR, job_maint, job_name, 'chroot') + self.dir = osp.join(jobdir, 'chroot') # Hmmmm. Maybe all this should be in a module of it's own. - def _clean_mounts(self, chrootdir): + def _clean_mounts(self, chrootdir=None): + if not chrootdir: + chrootdir = self.dir for dir in ['dev', 'proc', 'sys', osp.join('usr','portage')]: if osp.ismount(osp.join(chrootdir, dir)): result = subprocess.check_call('umount "%s"' % osp.join(chrootdir, dir), shell=True) @@ -96,18 +98,13 @@ class WorkChroot(object): return None return True - def _prepare_mounts(self, chrootdir): + def _prepare_mounts(self, chrootdir=None): + if not chrootdir: + chrootdir = self.dir for dir in ['dev', 'sys']: result = subprocess.check_call('mount -o bind "%s" "%s"' % (osp.join('/', dir), osp.join(chrootdir, dir)), shell=True) - if not result == 0: - return None result = subprocess.check_call('mount -t proc proc "%s"' % osp.join(chrootdir, 'proc'), shell=True) - if not result == 0: - return None result = subprocess.check_call('mount -o bind "%s" "%s"' % (const.PORTAGE_DIR, osp.join(chrootdir, 'usr', 'portage')), shell=True) - if not result == 0: - return None - return True def prepare(self): """ @@ -117,13 +114,15 @@ class WorkChroot(object): """ if not self.pristine.prepare(): return False - result = self._clean_mounts(self.dir) - if not result: - sys.exit('Cleaning mounts failed.') + self._clean_mounts() # self.chroot.dir/ => rsync *contents* to self.dir syncer = sync.Syncer(uri=self.pristine.dir+"/", destdir=self.dir, scheme='rsync') syncer.sync() - result = self._prepare_mounts(self.dir) - if not result: - sys.exit('Preparing mounts failed.') + self._prepare_mounts() print "Work Chroot ready." + + def clean(self): + """ + Cleanup when done. + """ + self._clean_mounts() diff --git a/slave/autotua/jobuild/__init__.py b/slave/autotua/jobuild/__init__.py index 76b8e52..1e0e2cf 100644 --- a/slave/autotua/jobuild/__init__.py +++ b/slave/autotua/jobuild/__init__.py @@ -15,18 +15,41 @@ from .. import const class Jobuild(object): """A jobuild""" - def __init__(self, atom): + def __init__(self, jobdir, atom): self.name = atom - # Hardcoding to central jobtagedir now, proper resolver, version parsing crap later. - parts = self.split_atom(atom) - self.jobuild = '%s/%s/%s/%s-%s.jobuild' % (const.JOBTAGE_DIR, parts[1], parts[2], parts[2], parts[3]) + self.jobdir = jobdir + self.jobuild = self._best_jobuild(atom) def __str__(self): return '%s jobuild object' % self.name - def split_atom(self, atom): - regex = re.compile(r'([=<>]*)([a-zA-Z0-9_+-]*)/([a-zA-Z0-9_+-]*)-([0-9\.]*)') # Implement reusing of this later. - return regex.sub(r'\1 \2 \3 \4', atom).split() + def _split_atom(self, atom): + regex = re.compile(r'^([<>]?=)?([a-zA-Z0-9_+-]+)/([a-zA-Z0-9_+-]+)(-|$)([0-9]+\.[0-9]+)?') # Fancy regex aye? + # >= bheekling / test-beagle - 1.0 + # bheekling / build-brasero + parts = regex.findall(atom) + if not parts: + # FIXME: Custom exceptions + raise 'Invalid atom %s' % atom + parts = parts[0] + if parts[3] and not parts[4]: + # FIXME: Custom exceptions + raise 'Invalid atom %s' % atom + parts = (parts[0], parts[1], parts[2], parts[4],) + if (parts[0] and not parts[3]) or (parts[3] and not parts[0]): + # FIXME: Custom exceptions + raise 'Invalid atom %s' % atom + return parts + + def _best_jobuild(self, atom): + parts = self._split_atom(atom) + data = {'maint': parts[1], + 'pn': parts[2], + 'pv': parts[3], + 'jobtage': '%s/jobtage' % self.jobdir} + # FIXME: Add support for overlays, [<>]=, and unqualified atoms + jobuild = '%(jobtage)s/%(maint)s/%(pn)s/%(pn)s-%(pv)s.jobuild' % data + return jobuild def get_var(self, var): """ @@ -41,6 +64,7 @@ class Jobuild(object): process.stdin.write('ping\n') response = process.stderr.readline()[:-1] # Remove trailing newline if not response == 'pong': - sys.exit('Communication error: received %s when expecting "pong"' % response) + # FIXME: Custom exceptions + raise 'Communication error: received %s when expecting "pong"' % response response = process.stderr.readline()[:-1] print response diff --git a/slave/autotua/sync/__init__.py b/slave/autotua/sync/__init__.py index b8eb45f..cd1189e 100644 --- a/slave/autotua/sync/__init__.py +++ b/slave/autotua/sync/__init__.py @@ -66,16 +66,16 @@ class Command(object): def _get_args(self, action): if self.scheme == 'bzr': if action == 'init': - return 'bzr branch -r"%s" "%s" "%s"' % (self.rev, self.uri, self.destdir) + return 'bzr branch -r"%s" "%s" "%s"' % (self.rev, self.uri, self.destdir), elif action == 'sync': - return 'bzr pull --overwrite -r"%s" -d "%s" "%s"' % (self.rev, self.destdir, self.uri) + return 'bzr pull --overwrite -r"%s" -d "%s" "%s"' % (self.rev, self.destdir, self.uri), elif self.scheme == 'bzr-export': if action == 'init': - return 'bzr export -r"%s" "%s" "%s"' % (self.rev, self.destdir, self.uri) + return 'bzr export -r"%s" "%s" "%s"' % (self.rev, self.destdir, self.uri), elif action == 'sync': - return 'bzr export -r"%s" "%s" "%s"' % (self.rev, self.destdir, self.uri), {'rmtree': 'destdir'} + return 'bzr export -r"%s" "%s" "%s"' % (self.rev, self.destdir, self.uri), {'rmtree': self.destdir}, elif self.scheme == 'rsync': - return 'rsync -a --delete "%s" "%s"' % (self.uri, self.destdir) + return 'rsync -a --delete "%s" "%s"' % (self.uri, self.destdir), print "Unknown scheme: %s" % self.scheme return None @@ -87,4 +87,4 @@ class Command(object): params = args[1] if params.has_key('rmtree'): shutil.rmtree(params['rmtree']) - subprocess.check_call(args, shell=True) + subprocess.check_call(args[0], shell=True) |