# HG changeset patch # User Bernhard Herzog # Date 1212428659 0 # Node ID dd54ef8a9244d38ce1a57faa057a4428e34ed215 # Parent ddd141e09e8f67839a8515f1779669736f18e4c1 New file. Script to update an existing treepkg installation to the filesystem layout of the current version diff -r ddd141e09e8f -r dd54ef8a9244 bin/updatetreepkg.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/updatetreepkg.py Mon Jun 02 17:44:19 2008 +0000 @@ -0,0 +1,66 @@ +#! /usr/bin/python2.4 +# Copyright (C) 2007, 2008 by Intevation GmbH +# Authors: +# Bernhard Herzog +# +# 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 +""" + +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_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) + +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()