Mercurial > treepkg
view bin/publishpackages.py @ 250:b3f9cc956acc
Make the Status class usable without a filename and provide methods to
(de-)serialize to and from memory to make writing tests easier.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 09 Apr 2009 18:20:04 +0000 |
parents | a3f106580525 |
children | 8052aabada8b |
line wrap: on
line source
#! /usr/bin/python2.4 # 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 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 = ["distribution", "section", "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" " 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")) 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) 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) # update apt archive call(cmdexpand("ssh $publish_user$@$publish_host" " $publish_apt_archive_update", **config)) def main(): options, args = parse_commandline() publish_packages(options.config_file, options.track, options.revision, options.dist, options.section) main()