changeset 372:ef87d30468b6

Added the option to expose additional log files from the log directory. To enable this one can either set a build_logs value in the staticweb.cfg or call createstaticweb with the parameter --show-logs. Default behavior is to only publish the build log, although the title is now capitalized.
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 21 Jun 2010 08:23:30 +0000
parents d0304bc2d378
children c7d22fd36815
files bin/createstaticweb.py bin/publishstaticweb.py demostaticweb.cfg treepkg/packager.py treepkg/report.py treepkg/web.py
diffstat 6 files changed, 64 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/bin/createstaticweb.py	Tue Jun 15 10:56:44 2010 +0000
+++ b/bin/createstaticweb.py	Mon Jun 21 08:23:30 2010 +0000
@@ -18,21 +18,31 @@
 def parse_commandline():
     parser = create_parser()
     parser.set_defaults(status_template="status-by-startdate.html")
+    parser.set_defaults(show_logs="build_log.txt.gz")
     parser.add_option("--status-template",
                       help=("The template file to use for the status page."
                             " Relative filenames are interpreted"
                             " relative to the web subdirectory."
                             " Default is status-by-startdate.html."))
+    parser.add_option("--show-logs",
+                      help=("A comma seperated list of filenames of the" 
+                            " logs that should be included in the status page."
+                            " Valid names are filenames of the files"
+                            " in the log dir of a package. e.g."  
+                            " --show-logs=tarball_log.txt,dpkg_source.txt"
+                            " Default is build_log.txt.gz"))
     return parser.parse_args()
 
-def create_static_site(treepkg_config, status_template, destdir):
-    status = Status(treepkg_config=treepkg_config, template=status_template)
+def create_static_site(treepkg_config, status_template, show_logs, destdir):
+    status = Status(treepkg_config=treepkg_config, template=status_template,
+                    logs=show_logs.split(","))
     status.create_static_site(destdir)
 
 def main():
     options, args = parse_commandline()
     create_static_site(options.config_file,
                        options.status_template,
+                       options.show_logs,
                        args[0])
 
 main()
--- a/bin/publishstaticweb.py	Tue Jun 15 10:56:44 2010 +0000
+++ b/bin/publishstaticweb.py	Mon Jun 21 08:23:30 2010 +0000
@@ -29,14 +29,21 @@
     return os.path.expandvars(os.path.expanduser(filename))
 
 staticweb_desc = ["build_user", "build_host", "build_create", "build_template",
+                  "build_logs",
                   ("build_dir", remove_trailing_slashes),
                   "publish_user", "publish_host",
                   ("publish_dir", remove_trailing_slashes),
                   ("cachedir",
                    lambda s: expand_filename(remove_trailing_slashes(s)))]
 
+#Default values for the configuration options can be set here
+staticweb_defaults = [("build_logs", "build_log.txt.gz")]
+
 def read_config(filename):
     parser = SafeConfigParser()
+    parser.add_section("staticweb")
+    for value in staticweb_defaults:
+        parser.set("staticweb", value[0], value[1])
     parser.read([filename])
     return read_config_section(parser, "staticweb", staticweb_desc)
 
@@ -58,6 +65,7 @@
 
     # create web-page on build host
     call(cmdexpand("ssh $build_user$@$build_host $build_create"
+                   " --show-logs=$build_logs"
                    " --status-template=$build_template $build_dir",
                    **config))
 
--- a/demostaticweb.cfg	Tue Jun 15 10:56:44 2010 +0000
+++ b/demostaticweb.cfg	Mon Jun 21 08:23:30 2010 +0000
@@ -23,6 +23,12 @@
 # to the ~/treepkg/web/ directory.
 build_template: status-by-startdate.html
 
+# Additional log files can be configured here, those can have non standard 
+# names as long as they are contained in the log directory of a package.
+# Filenames have to be seperated by a comma.
+# Default is: build_log.txt.gz
+# build_logs: build_log.txt.gz,tarball_log.txt,pkits_log.txt
+
 # the directory on build_host where the static web-site should be put.
 # This value is used as the parameter to the build_create command on
 # build_host.
--- a/treepkg/packager.py	Tue Jun 15 10:56:44 2010 +0000
+++ b/treepkg/packager.py	Mon Jun 21 08:23:30 2010 +0000
@@ -308,20 +308,39 @@
     def has_build_log(self):
         return os.path.exists(self.get_log_file())
 
+    def get_log_title(self, f):
+        if not os.path.isfile(f):
+            return None
+        title = os.path.basename(f)
+        title = title.replace("_"," ")
+        title = title[:title.find(".")]
+        title = title.title()
+        return title
+
     def get_log_file(self):
         if os.path.exists(self.build_log + ".gz"):
             return self.build_log + ".gz"
         return self.build_log
 
-    def list_log_files(self):
+    def get_log_files(self, logs):
+        files = []
+        for f in os.listdir(self.log_dir):
+            if f in logs:
+                f = os.path.join(self.log_dir,f)
+                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
-        TITLE is a string with a title usable in e. g. a web-page, and
+        TITLE is a string with the filename without directory or ending in
+        which _ is replaced with a whitespace and words are capitalized.
         FILENAME is the absolute filename of the log file.
         """
-        files = []
-        if self.has_build_log():
-            files.append(("build log", self.get_log_file()))
+        files = self.get_log_files(logs)
+        if not files:
+            return []
         return files
 
     def list_source_files(self):
--- a/treepkg/report.py	Tue Jun 15 10:56:44 2010 +0000
+++ b/treepkg/report.py	Mon Jun 21 08:23:30 2010 +0000
@@ -68,8 +68,9 @@
 
 class Revisions(object):
 
-    def __init__(self, tracks):
+    def __init__(self, tracks, logs):
         self.tracks = sorted(tracks, key=attrgetter("name"))
+        self.logs = logs 
 
     def sorted_by_revision(self):
         revisions = {}
@@ -80,7 +81,8 @@
                                             revision.rules_revision),
                                            [None] * num_columns)
                 log_files = [(title, os.path.basename(filename))
-                              for title, filename in revision.list_log_files()]
+                              for title, filename in
+                                  revision.list_log_files(self.logs)]
                 row[column] = struct(revno=revision.revision,
                                      rulesrev=revision.rules_revision,
                                      revision=revision,
@@ -107,7 +109,8 @@
                                          log_files =
                                            [(title, os.path.basename(filename))
                                             for title, filename
-                                            in revision.list_log_files()],
+                                            in revision.list_log_files(
+                                                                   self.logs)],
                                          column=column,
                                          name=track.name,
                                          new_date = None,
@@ -122,6 +125,6 @@
                 rev.new_date = str(last_date)
         return revisions
 
-def prepare_report(group):
-    return struct(revisions=Revisions(group.get_package_tracks()),
+def prepare_report(group, logs):
+    return struct(revisions=Revisions(group.get_package_tracks(), logs),
                   date=format_time(datetime.datetime.utcnow()))
--- a/treepkg/web.py	Tue Jun 15 10:56:44 2010 +0000
+++ b/treepkg/web.py	Mon Jun 21 08:23:30 2010 +0000
@@ -22,9 +22,10 @@
 
     """Implements the tree packager status pages"""
 
-    def __init__(self, treepkg_config, template):
+    def __init__(self, treepkg_config, template, logs):
         self.treepkg_config = treepkg_config
         self.template = template
+        self.logs = logs
         self.loader = TemplateLoader([os.path.join(os.path.dirname(__file__),
                                                    os.path.pardir,
                                                    "web")])
@@ -33,7 +34,7 @@
     def index(self):
         group = report.get_packager_group(self.treepkg_config)
         tmpl = self.loader.load(self.template)
-        stream = tmpl.generate(report=report.prepare_report(group))
+        stream = tmpl.generate(report=report.prepare_report(group, self.logs))
         return stream.render('html')
 
     def determine_log_filename(self, package_track_name, revdir, log_basename):
@@ -46,7 +47,8 @@
                 for revision in track.get_revisions():
                     if (revision.revision == revno
                         and revision.rules_revision == rulesrev):
-                        for title, filename in revision.list_log_files():
+                        for title, filename in revision.list_log_files(
+                                                                self.logs):
                             if os.path.basename(filename) == log_basename:
                                 return filename
 
@@ -88,7 +90,7 @@
                     if not os.path.isdir(trackdir):
                         os.mkdir(trackdir)
                     os.mkdir(revdir)
-                    for title, filename in revision.list_log_files():
+                    for title, filename in revision.list_log_files(self.logs):
                         os.symlink(filename,
                                    os.path.join(revdir,
                                                 os.path.basename(filename)))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)