Mercurial > treepkg
view bin/publishpackages.py @ 236:065d20fb4691
Use better names for the rules revision in the structs in the reports.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 13 Jan 2009 16:58:02 +0000 |
parents | ce03e24f6d0f |
children | 55337021fe5b |
line wrap: on
line source
#! /usr/bin/python2.4 # Copyright (C) 2007, 2008 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 from optparse import OptionParser from ConfigParser import SafeConfigParser import treepkgcmd from treepkg.readconfig import read_config_section from treepkg.run import call, capture_output from treepkg.cmdexpand import cmdexpand from treepkg.util import ensure_directory, listdir_abs def remove_trailing_slashes(s): return s.rstrip("/") def expand_filename(filename): """ Applies os.path.expanduser and os.path.expandvars to filename """ return os.path.expandvars(os.path.expanduser(filename)) config_desc = ["build_user", "build_host", "build_listpackages", "publish_user", "publish_host", "publish_apt_archive_update", ("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")) 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")) 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")) return parser.parse_args() def publish_packages_arch(variables, track, revision, dist, section, arch): # create web-page on build host 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"] = [] files = capture_output(cmdexpand("ssh $build_user$@$build_host" " $build_listpackages" " @track @revision $pkgtype", **listpackages_vars)).strip().split("\n") # scp the packages to the cache dir cachedir = variables["cachedir"] shutil.rmtree(cachedir, ignore_errors=True) ensure_directory(cachedir) userhost = "%(build_user)s@%(build_host)s:" % variables call(cmdexpand("scp @files $cachedir/", files = [userhost + filename for filename in files], **variables)) # copy the packages to the remote publishing host. Create the # destination directory if it doesn't exist yet. destdir = os.path.join(variables["publish_dir"], dist, section, arch) call(cmdexpand("ssh $publish_user$@$publish_host mkdir --parents $destdir", destdir=destdir, **variables)) call(cmdexpand("scp @files $publish_user$@$publish_host:$destdir", files=listdir_abs(cachedir), destdir=destdir, **variables)) def publish_packages(config_filename, track, revision, dist, section): config = read_config(config_filename) for arch in ["binary-i386", "source"]: publish_packages_arch(config, track, revision, dist, section, arch) # update apt archive call(cmdexpand("ssh $publish_user$@$publish_host" " $publish_apt_archive_update", **config)) def main(): options, args = parse_commandline() for required_opt in ["dist", "section"]: if getattr(options, required_opt) is None: print >>sys.stderr, "The --%s option must be given" % required_opt sys.exit(1) publish_packages(options.config_file, options.track, options.revision, options.dist, options.section) main()