Mercurial > treepkg > treepkg
view treepkg/report.py @ 570:44c0f8404983
Refactor git pull command out of update
Tag MUST NOT use update because therefore it always changes the current local branch!
For listing the tags it's enough to pull the latest repo changes
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Fri, 02 Sep 2011 11:46:29 +0000 |
parents | f1be9657c1d2 |
children |
line wrap: on
line source
# Copyright (C) 2007, 2008, 2009 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""" import os from operator import attrgetter import datetime 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 timestamp.strftime("%Y-%m-%d %H:%M:%SZ") 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), tag=status.tags) class Revisions(object): def __init__(self, tracks, logs): self.tracks = sorted(tracks, key=attrgetter("name")) self.logs = logs def sorted_by_revision(self): revisions = {} num_columns = len(self.tracks) for column, track in enumerate(self.tracks): for revision in track.get_revisions(): row = revisions.setdefault((revision.revision, revision.rules_revision), [None] * num_columns) log_files = [(title, os.path.basename(filename)) for title, filename in revision.list_log_files(self.logs)] row[column] = struct(revno=revision.revision, rulesrev=revision.rules_revision, revision=revision, column=column, name=track.name, log_files=log_files, 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 revisions def sorted_by_startdate(self): revisions = [] for column, track in enumerate(self.tracks): for revision in track.get_revisions(): if not revision.status or not revision.status.start: continue revisions.append((revision.status.start, struct(revno=revision.revision, revision=revision, rulesrev=revision.rules_revision, log_files = [(title, os.path.basename(filename)) for title, filename in revision.list_log_files( self.logs)], column=column, name=track.name, new_date = None, status=prepare_status(revision.status)))) revisions.sort() revisions.reverse() last_date = None for start, rev in revisions: if last_date != start.date(): last_date = start.date() rev.new_date = str(last_date) return revisions def prepare_report(group, logs): return struct(revisions=Revisions(group.get_package_tracks(), logs), date=format_time(datetime.datetime.utcnow()))