[Treepkg-commits] r424 - in trunk: . treepkg
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Sep 9 16:26:36 CEST 2010
Author: aheinecke
Date: 2010-09-09 16:26:35 +0200 (Thu, 09 Sep 2010)
New Revision: 424
Modified:
trunk/demo.cfg
trunk/treepkg/packager.py
trunk/treepkg/readconfig.py
trunk/treepkg/status.py
Log:
Enable a status_hook to be set and executed on status changes
Modified: trunk/demo.cfg
===================================================================
--- trunk/demo.cfg 2010-09-09 13:49:37 UTC (rev 423)
+++ trunk/demo.cfg 2010-09-09 14:26:35 UTC (rev 424)
@@ -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
Modified: trunk/treepkg/packager.py
===================================================================
--- trunk/treepkg/packager.py 2010-09-09 13:49:37 UTC (rev 423)
+++ trunk/treepkg/packager.py 2010-09-09 14:26:35 UTC (rev 424)
@@ -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
Modified: trunk/treepkg/readconfig.py
===================================================================
--- trunk/treepkg/readconfig.py 2010-09-09 13:49:37 UTC (rev 423)
+++ trunk/treepkg/readconfig.py 2010-09-09 14:26:35 UTC (rev 424)
@@ -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 = [
Modified: trunk/treepkg/status.py
===================================================================
--- trunk/treepkg/status.py 2010-09-09 13:49:37 UTC (rev 423)
+++ trunk/treepkg/status.py 2010-09-09 14:26:35 UTC (rev 424)
@@ -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:
More information about the Treepkg-commits
mailing list