Mercurial > treepkg
view bin/updatetreepkg.py @ 310:26c15a0f0e52
When stopping because of an error, do not raise the exception again as
it leads to confusing double tracebacks in the log. Instead, simply log
the reason for the stopping and stop in the same way a stop instruction
is handled.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Wed, 02 Dec 2009 14:46:37 +0000 |
parents | 1fcdffbeb9de |
children | 5fa56edeb606 |
line wrap: on
line source
#! /usr/bin/python # 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. """Script to help update a tree packager installation to the current version. The script updates the information stored in the filesystem for the individual revisions in the following ways: - Rename the build log from build.log to log/build_log.txt - Rename the build log from build_log.txt to log/build_log.txt - Rename the directory name of the revision from <revision>-1 to <revision>-0 The second number is now the revision of the packaging rules if they're managed by SVN and always 0 for manual management of the rules. """ import os import treepkgcmd from treepkg.options import create_parser from treepkg.packager import create_package_track, PackagerGroup from treepkg.readconfig import read_config def rename_file(old_name, new_name, dry_run): if os.path.exists(old_name): new_dir = os.path.dirname(new_name) if not os.path.isdir(new_dir): print "mkdir %s" % (new_dir,) if not dry_run: os.mkdir(new_dir) print "mv %s %s" % (old_name, new_name) if not dry_run: os.rename(old_name, new_name) def update_rules_revision_in_directory_names(track, dry_run): revisions = track.get_revisions() rules_revisions = set(revision.rules_revision for revision in revisions) if rules_revisions == set([1]): for revision in revisions: rename_file(revision.base_dir, revision.base_dir[:-2] + "-0", dry_run) def update_treepkg(config_file, dry_run): treepkg_opts, packager_opts = read_config(config_file) for opts in packager_opts: opts["handle_dependencies"] = False group = PackagerGroup([create_package_track(**opts) for opts in packager_opts], **treepkg_opts) for track in group.get_package_tracks(): for revision in track.get_revisions(): # Originally, the build logs were called build.log and were # in the base directory of a revision rename_file(os.path.join(revision.base_dir, "build.log"), revision.build_log, dry_run) # for a while, the build logs were called build_log.txt but # still were in the base directory rename_file(os.path.join(revision.base_dir, "build_log.txt"), revision.build_log, dry_run) # Revision directories used to end with "-1". Now that number # is the revision of the packaging rules which default to 0 for # the traditional manual rules management without a version # control system. Rename those directories if necessary update_rules_revision_in_directory_names(track, dry_run) def parse_commandline(): parser = create_parser() parser.set_defaults(dry_run=False) parser.add_option("-n", "--dry-run", action="store_true", help="Do not actually change anything") return parser.parse_args() def main(): options, args = parse_commandline() update_treepkg(options.config_file, options.dry_run) main()