Mercurial > treepkg > treepkg
view treepkg/report.py @ 19:0cdda44240a6
Add treepkg/report.py for reporting and use it in reportstatus.py
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 13 Mar 2007 19:21:37 +0100 |
parents | |
children | 22192fad1f79 |
line wrap: on
line source
# Copyright (C) 2007 by Intevation GmbH # Authors: # Bernhard Herzog <bh@intevation.de> # # This program is free software under the GPL (>=v2) # Read the file COPYING coming with the software for details. """Support for status reports""" from packager import create_package_line, PackagerGroup from readconfig import read_config class struct(object): """Class to create simple struct like objects All keyword arguments passed to the constructor are available as instance variables. """ def __init__(self, **kw): self.__dict__.update(kw) def __repr__(self): fields = ["%s=%r" % item for item in self.__dict__.items()] return "struct(" + ", ".join(fields) + ")" def get_packager_group(config_file): treepkg_opts, packager_opts = read_config(config_file) return PackagerGroup([create_package_line(**opts) for opts in packager_opts], **treepkg_opts) status_expansions = dict( binary_package_created="build successful", creating_binary_package="building binary packages", source_package_created="source package created", creating_source_package="creating source package", error="error") def status_finished(status): return status.status == "binary_package_created" def status_error(status): return status.status == "error" def status_class(status): """Returns the CSS class for a status""" if status_finished(status): return "finished" elif status_error(status): return "error" else: return "inprogress" def format_time(timestamp): """Formats a datetime object for a status report if the argument is true, the return value is simply str applied to the argument, which for datetime objects is a string with the format 'YYYY-MM-DD hh:mm:ss'. If the argument is false, the return value is '<unknown>'. """ if timestamp: return str(timestamp) else: return "<unknown>" def prepare_status(status): return struct(desc=status_expansions.get(status.status, status.status), start=format_time(status.start), stop=format_time(status.stop), cls=status_class(status)) def prepare_report(group): revisions = [] columns = [] pkglines = group.get_package_lines() num_columns = len(pkglines) for column, line in enumerate(pkglines): columns.append((column, line.name)) for revision in line.get_revisions(): row = [None] * num_columns row[column] = struct(revno=revision.revision, revision=revision, column=column, name=line.name, status=prepare_status(revision.status)) revisions.append((revision.revision, row)) revisions.sort() revisions.reverse() return struct(columns=columns, revisions=revisions)