changeset 464:5fda6768bef6

Enable a status_hook to be set and executed on status changes
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 09 Sep 2010 14:26:35 +0000
parents 52f841330c16
children 296d26453e2a
files demo.cfg treepkg/packager.py treepkg/readconfig.py treepkg/status.py
diffstat 4 files changed, 38 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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<revision>[0-9a-f]+)"
                                         r"-(?P<rules_revision>[0-9a-f]+)$")
+        self.status_hook = status_hook
         externals = svn_externals
         if not externals:
             externals = self.svn_external_subdirs
--- 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 = [
--- 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:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)