Mercurial > treepkg
view bin/publishpackages.py @ 419:eac71f066037 treepkg-status
make treepkg compatible to python 2.4
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Mon, 26 Jul 2010 13:46:19 +0000 |
parents | a798edae0844 |
children | c7f4da26f1d4 |
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. """Publishes selected packages created by treepkg""" import sys import os import shutil import shlex from optparse import OptionParser from ConfigParser import SafeConfigParser import treepkgcmd from treepkg.readconfig import read_config_section, convert_bool from treepkg.run import call, capture_output from treepkg.cmdexpand import cmdexpand from treepkg.util import ensure_directory, listdir_abs from treepkg.publish import remove_trailing_slashes, expand_filename, prefix_for_remote_command, copy_to_publishdir config_desc = ["distribution", "section", "num_newest", "build_user", "build_host", "build_listpackages", "publish_user", "publish_host", ("after_upload_hook", shlex.split), ("publish_remove_old_packages", convert_bool), ("publish_dir", remove_trailing_slashes), ("cachedir", lambda s: expand_filename(remove_trailing_slashes(s)))] def read_config(filename): parser = SafeConfigParser() parser.read([filename]) return read_config_section(parser, "publishpackages", config_desc) def parse_commandline(): parser = OptionParser() parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir, "publishpackages.cfg"), quiet=False) parser.add_option("--config-file", help=("The configuration file." " Default is publishpackages.cfg")) parser.add_option("--revision", help=("The revision whose files are to be published." " If not given, the latest revision is used" " The value may be given as REV-RULESREV to specify" " both the main source revision and the revision of" " the packaging rules")) parser.add_option("--dist", help=("The debian distribution name to use on" " the publishing system")) parser.add_option("--section", help=("The debian distribution section name to use on" " the publishing system")) parser.add_option("--track", help=("The package track whose files are to be" " published. If not given, files of all tracks" " will be published")) parser.add_option("--quiet", action="store_true", help=("Do not print progress meters or other" " informational output")) return parser.parse_args() def copy_to_cache(variables, track, revision, arch, quiet): listpackages_vars = variables.copy() if arch == "source": listpackages_vars["pkgtype"] = "--source" else: listpackages_vars["pkgtype"] = "--binary" if track: listpackages_vars["track"] = ["--track", track] else: listpackages_vars["track"] = [] if revision: listpackages_vars["revision"] = ["--revision", revision] else: listpackages_vars["revision"] = [] runremote = prefix_for_remote_command(variables["build_user"], variables["build_host"]) files = capture_output(cmdexpand("@runremote $build_listpackages" " @track @revision $pkgtype" " --newest=$num_newest", runremote=runremote, **listpackages_vars)).splitlines() # scp the packages to the cache dir cachedir = variables["cachedir"] shutil.rmtree(cachedir, ignore_errors=True) ensure_directory(cachedir) if files: if variables["build_host"]: userhost = "%(build_user)s@%(build_host)s:" % variables files = [userhost + filename for filename in files] scp_flags = [] if quiet: scp_flags.append("-q") call(cmdexpand("scp -p @scp_flags @files $cachedir/", files=files, scp_flags=scp_flags, **variables)) def publish_packages_arch(variables, track, revision, dist, section, arch, quiet): copy_to_cache(variables, track, revision, arch, quiet) copy_to_publishdir(variables, dist, section, arch, quiet) def publish_packages(config_filename, track, revision, dist, section, quiet): config = read_config(config_filename) if dist is None: dist = config["distribution"] if section is None: section = config["section"] for arch in ["binary-i386", "source"]: publish_packages_arch(config, track, revision, dist, section, arch, quiet) # update apt archive call(config["after_upload_hook"]) def main(): options, args = parse_commandline() publish_packages(options.config_file, options.track, options.revision, options.dist, options.section, options.quiet) main()