Mercurial > treepkg > treepkg
view treepkg/report.py @ 52:78cf5f6778ec
Rename 'packagel ine' -> 'package track'
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 03 Apr 2007 20:33:33 +0200 |
parents | f7ec40638a06 |
children | ee32f709a374 |
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_track, 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_track(**opts) for opts in packager_opts], **treepkg_opts) def status_class(status): """Returns the CSS class for a status""" if status.finished: return "finished" elif status.error: 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.status.description, start=format_time(status.start), stop=format_time(status.stop), cls=status_class(status.status)) def prepare_report(group): revisions = {} columns = [] tracks = group.get_package_tracks() num_columns = len(tracks) for column, track in enumerate(tracks): columns.append((column, track.name)) for revision in track.get_revisions(): row = revisions.setdefault(revision.revision, [None] * num_columns) row[column] = struct(revno=revision.revision, revision=revision, column=column, name=track.name, status=prepare_status(revision.status)) # convert the revisions dict into a sorted list of (revno, row) # pairs revisions = revisions.items() revisions.sort() revisions.reverse() return struct(columns=columns, revisions=revisions)