diff options
author | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2008-07-04 11:45:11 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2008-07-04 11:45:11 +0530 |
commit | 57e96d5a47e759ddeb5e157598fb1d4489954686 (patch) | |
tree | 284e78ad9693a0e9d106c784d20f70450d34a6e5 | |
parent | - Make PORTDIR and DISTDIR chroot bind mounting optional (diff) | |
download | autotua-57e96d5a47e759ddeb5e157598fb1d4489954686.tar.gz autotua-57e96d5a47e759ddeb5e157598fb1d4489954686.tar.bz2 autotua-57e96d5a47e759ddeb5e157598fb1d4489954686.zip |
- Move running of commands to autotua.daemon
* Makes the jobuild processor cleaner
- Fix a bug in autotua.Job()._fetch_src() -- processing is no longer handled via the Jobuild() object
- Update TODO to reflect this commit
-rw-r--r-- | slave/TODO | 1 | ||||
-rw-r--r-- | slave/autotua/__init__.py | 8 | ||||
-rw-r--r-- | slave/autotua/daemon/__init__.py | 26 | ||||
-rw-r--r-- | slave/autotua/jobuild/__init__.py | 13 |
4 files changed, 36 insertions, 12 deletions
@@ -4,6 +4,5 @@ Do: ----- -[ ] Separate module for running commands [~] Atom parsing, jobuild searching, etc etc [ ] Auto-detect SCM of source jobtage repo for syncer.Sync().sync() diff --git a/slave/autotua/__init__.py b/slave/autotua/__init__.py index a21934e..3ab594e 100644 --- a/slave/autotua/__init__.py +++ b/slave/autotua/__init__.py @@ -88,8 +88,10 @@ class Job: def _fetch_src(self): job_src = [] fetcher = fetch.Fetcher(const.JOBFILE_DIR) - for jobuild in self.jobuilds: - src_uri = jobuild.get_var('SRC_URI').split() + processor = jobuild.Processor(None, self.chroot) + for one in self.jobuilds: + processor.jobuild = one + src_uri = processor.get_var('SRC_URI').split() for i in src_uri: job_src.append(fetch.Fetchable(uri=[i])) for fetchable in job_src: @@ -126,7 +128,7 @@ class Job: def tidy(self): print 'Tidying up..' self.chroot.tidy() - print 'Done. The workdir has not been removed (default)' + print 'The workdir has not been removed (default)' def clean(self): shutil.rmtree(self.jobdir) diff --git a/slave/autotua/daemon/__init__.py b/slave/autotua/daemon/__init__.py new file mode 100644 index 0000000..c83cafd --- /dev/null +++ b/slave/autotua/daemon/__init__.py @@ -0,0 +1,26 @@ +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com> +# License: GPL-2 +# +# Immortal lh! +# + +import subprocess +from .. import const + +class Spawn(object): + """Spawn a daemonized sub-process in a shell""" + + def __init__(self, command, logfile=const.LOGFILE): + """ + @param command: The (properly quoted) command to be run in the shell + It should listen on stdin and send replies to fd 3 + @type command: string + """ + self.logfile = logfile + # Messages goto 3 and then to /dev/tty1 + # stderr goes to stdout + # stdout goes to self.logfile + self.command = '%s 3>&2 2>&1 | tee -a \"%s\"' % (command, self.logfile) + self.process = subprocess.Popen(self.command, shell=True, stderr=subprocess.PIPE, stdin=subprocess.PIPE) diff --git a/slave/autotua/jobuild/__init__.py b/slave/autotua/jobuild/__init__.py index 98d6a8e..6831b11 100644 --- a/slave/autotua/jobuild/__init__.py +++ b/slave/autotua/jobuild/__init__.py @@ -11,7 +11,7 @@ import re, subprocess, sys, os import os.path as osp -from .. import const +from .. import const, daemon class Jobuild(object): """A jobuild""" @@ -123,14 +123,11 @@ class Processor(object): return self._msg('GET_VAR "%(var)s" "%(jobuild)s"' % args) def _msg(self, msg): - # Messages goto 3 and then to /dev/tty1 - # stderr goes to stdout - # stdout goes to ${LOGFILE} - process = subprocess.Popen('\"%s\"/bin/jobuild.sh %s 3>&2 2>&1 | tee -a \"%s\"' % (const.AUTOTUA_DIR, msg, const.LOGFILE), shell=True, stderr=subprocess.PIPE, stdin=subprocess.PIPE) - process.stdin.write('ping\n') - response = process.stderr.readline()[:-1] # Remove trailing newline + proc = daemon.Spawn('\"%s\"/bin/jobuild.sh %s' % (const.AUTOTUA_DIR, msg)) + proc.process.stdin.write('ping\n') + response = proc.process.stderr.readline()[:-1] # Remove trailing newline if not response == 'pong': # FIXME: Custom exceptions raise 'Communication error: received %s when expecting "pong"' % response - response = process.stderr.read()[:-1] # Remove trailing newline + response = proc.process.stderr.read()[:-1] # Remove trailing newline return response |