# HG changeset patch # User Andre Heinecke # Date 1284042395 0 # Node ID 5fda6768bef6ec647634bb1bfe5fd4afe66034fe # Parent 52f841330c166773f9478d4912f6cbe2c3973f29 Enable a status_hook to be set and executed on status changes diff -r 52f841330c16 -r 5fda6768bef6 demo.cfg --- a/demo.cfg Thu Sep 09 13:49:37 2010 +0000 +++ b/demo.cfg Thu Sep 09 14:26:35 2010 +0000 @@ -87,8 +87,17 @@ # Release file in the pbuilder's extra-pkg directory. # You can override this in the pkg_ sections if you need package # specific values -#signing_key_id: +#signing_key_id: +# Use the status_hook vaiable to set a command you want to execute once +# the status of a treepkg has changed +# The envrionment variables set before this hook is called: +# TREEPKG_TRACK - The name of the track currently on +# TREEPKG_BASE_DIR - The name of the base directory of the current build +# TREEPKG_STATE - The state in which the track is currently (e.g. error) +# TREEPKG_STATENAME - The name of the current state +# (e.g. creating_binary_package) +# status_hook: [treepkg] # Section for general tree packager configuration diff -r 52f841330c16 -r 5fda6768bef6 treepkg/packager.py --- a/treepkg/packager.py Thu Sep 09 13:49:37 2010 +0000 +++ b/treepkg/packager.py Thu Sep 09 14:26:35 2010 +0000 @@ -15,6 +15,7 @@ import shutil import datetime import new +import sys import util from subversion import SvnRepository, SvnWorkingCopy, ManualWorkingCopy @@ -294,7 +295,8 @@ self.base_dir = self.track.pkg_dir_for_revision(self.revision, rules_revision) self.status = status.RevisionStatus(os.path.join(self.base_dir, - "status")) + "status"), + self.after_setattr) if tag: util.ensure_directory(self.base_dir) self.status.tags = tag @@ -305,6 +307,21 @@ src_dir = util.filenameproperty("src") build_log = util.filenameproperty("build_log.txt", dir_attr="log_dir") + def after_setattr(self, status, attr): + ''' + Execute a hook set in the source_hook configuration attribute + every time the status changes. + ''' + if not self.track.status_hook: return + logging.info("Executing status hook: %s" % self.track.status_hook ) + status_env = { + "TREEPKG_TRACK" : self.track.name, + "TREEPKG_BASE_DIR" : self.base_dir, + "TREEPKG_STATE" : attr, + "TREEPKG_STATENAME" : status.status.name + } + run.call(cmdexpand(self.track.status_hook), extra_env=status_env) + def find_dsc_file(self): for filename in os.listdir(self.src_dir): if filename.endswith(".dsc"): @@ -337,7 +354,7 @@ if os.path.isfile(f): files.append((self.get_log_title(f),f)) return files - + def list_log_files(self, logs): """Returns a list describing the logfiles available for the revision. Each list item is a tuple of the form (TITLE, FILENAME) where @@ -419,7 +436,7 @@ rules_svn_url=None, deb_build_options="", pkg_basename="", changelog_msg_template="Update to r%(revision)s", svn_subset=(), svn_externals=(), git_branch="", git_url="", - os=""): + os="", status_hook=""): self.name = name # Convert the builder_cls option to a class @@ -454,6 +471,7 @@ self.pkg_dir_template = "%(revision)s-%(rules_revision)s" self.pkg_dir_regex = re.compile(r"(?P[0-9a-f]+)" r"-(?P[0-9a-f]+)$") + self.status_hook = status_hook externals = svn_externals if not externals: externals = self.svn_external_subdirs diff -r 52f841330c16 -r 5fda6768bef6 treepkg/readconfig.py --- a/treepkg/readconfig.py Thu Sep 09 13:49:37 2010 +0000 +++ b/treepkg/readconfig.py Thu Sep 09 14:26:35 2010 +0000 @@ -80,7 +80,8 @@ ("git_branch", str,""), ("git_url", str,""), ("os", str, ""), - ("builder_cls",str,"PBuilder") + ("builder_cls", str, "PBuilder"), + ("status_hook", str, "") ] treepkg_desc = [ diff -r 52f841330c16 -r 5fda6768bef6 treepkg/status.py --- a/treepkg/status.py Thu Sep 09 13:49:37 2010 +0000 +++ b/treepkg/status.py Thu Sep 09 14:26:35 2010 +0000 @@ -121,11 +121,12 @@ # Derived classes may extend a copy of this set with more instance # variables. - _attrs = set(["_filename", "_values"]) + _attrs = set(["_filename", "_values", "_after_setattr"]) - def __init__(self, filename): + def __init__(self, filename, after_setattr=None): self._values = dict() self._filename = filename + self._after_setattr = after_setattr if self._filename is not None: assert os.path.isabs(self._filename) self.read() @@ -178,6 +179,8 @@ if attr in self._fields: self._values[attr] = value self.write() + if self._after_setattr is not None: + self._after_setattr(self, attr) elif attr in self._attrs: self.__dict__[attr] = value else: