bh@89: #! /usr/bin/python2.4 bh@200: # Copyright (C) 2007, 2008 by Intevation GmbH bh@89: # Authors: bh@89: # Bernhard Herzog bh@89: # bh@89: # This program is free software under the GPL (>=v2) bh@89: # Read the file COPYING coming with the software for details. bh@89: bh@89: """Publishes selected packages created by treepkg""" bh@89: bh@89: import sys bh@89: import os bh@89: import shutil bh@89: from optparse import OptionParser bh@89: from ConfigParser import SafeConfigParser bh@89: bh@89: import treepkgcmd bh@89: from treepkg.readconfig import read_config_section bh@89: from treepkg.run import call, capture_output bh@89: from treepkg.cmdexpand import cmdexpand bh@89: from treepkg.util import ensure_directory, listdir_abs bh@89: bh@89: bh@89: def remove_trailing_slashes(s): bh@89: return s.rstrip("/") bh@89: bh@89: def expand_filename(filename): bh@89: """ bh@89: Applies os.path.expanduser and os.path.expandvars to filename bh@89: """ bh@89: return os.path.expandvars(os.path.expanduser(filename)) bh@89: bh@89: config_desc = ["build_user", "build_host", "build_listpackages", bh@89: "publish_user", "publish_host", "publish_apt_archive_update", bh@89: ("publish_dir", remove_trailing_slashes), bh@89: ("cachedir", bh@89: lambda s: expand_filename(remove_trailing_slashes(s)))] bh@89: bh@89: def read_config(filename): bh@89: parser = SafeConfigParser() bh@89: parser.read([filename]) bh@89: return read_config_section(parser, "publishpackages", config_desc) bh@89: bh@89: def parse_commandline(): bh@89: parser = OptionParser() bh@89: parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir, bh@89: "publishpackages.cfg")) bh@89: parser.add_option("--config-file", bh@89: help=("The configuration file." bh@89: " Default is publishpackages.cfg")) bh@89: parser.add_option("--revision", bh@89: help=("The revision whose files are to be published." bh@89: " If not given, the latest revision is used")) bh@89: parser.add_option("--dist", bh@89: help=("The debian distribution name to use on" bh@89: " the publishing system")) bh@89: parser.add_option("--section", bh@89: help=("The debian distribution section name to use on" bh@89: " the publishing system")) bh@89: parser.add_option("--track", bh@89: help=("The package track whose files are to be" bh@200: " published. If not given, files of all tracks" bh@200: " will be published")) bh@89: return parser.parse_args() bh@89: bh@89: bh@89: def publish_packages_arch(variables, track, revision, dist, section, arch): bh@89: # create web-page on build host bh@200: listpackages_vars = variables.copy() bh@200: bh@89: if arch == "source": bh@200: listpackages_vars["pkgtype"] = "--source" bh@89: else: bh@200: listpackages_vars["pkgtype"] = "--binary" bh@200: bh@200: if track: bh@200: listpackages_vars["track"] = ["--track", track] bh@200: else: bh@200: listpackages_vars["track"] = [] bh@200: bh@200: if revision: bh@200: listpackages_vars["revision"] = ["--revision", revision] bh@200: else: bh@200: listpackages_vars["revision"] = [] bh@89: bh@89: files = capture_output(cmdexpand("ssh $build_user$@$build_host" bh@89: " $build_listpackages" bh@200: " @track @revision $pkgtype", bh@200: **listpackages_vars)).strip().split("\n") bh@200: bh@89: # scp the packages to the cache dir bh@89: cachedir = variables["cachedir"] bh@89: shutil.rmtree(cachedir, ignore_errors=True) bh@89: ensure_directory(cachedir) bh@89: userhost = "%(build_user)s@%(build_host)s:" % variables bh@89: call(cmdexpand("scp @files $cachedir/", bh@89: files = [userhost + filename for filename in files], bh@89: **variables)) bh@89: bh@89: # copy the packages to the remote publishing host. Create the bh@89: # destination directory if it doesn't exist yet. bh@89: destdir = os.path.join(variables["publish_dir"], dist, section, arch) bh@89: call(cmdexpand("ssh $publish_user$@$publish_host mkdir --parents $destdir", bh@89: destdir=destdir, **variables)) bh@89: call(cmdexpand("scp @files $publish_user$@$publish_host:$destdir", bh@89: files=listdir_abs(cachedir), destdir=destdir, bh@89: **variables)) bh@89: bh@89: bh@89: def publish_packages(config_filename, track, revision, dist, section): bh@89: config = read_config(config_filename) bh@89: bh@89: for arch in ["binary-i386", "source"]: bh@200: publish_packages_arch(config, track, revision, dist, section, arch) bh@89: bh@89: # update apt archive bh@89: call(cmdexpand("ssh $publish_user$@$publish_host" bh@89: " $publish_apt_archive_update", bh@200: **config)) bh@89: bh@89: def main(): bh@89: options, args = parse_commandline() bh@200: for required_opt in ["dist", "section"]: bh@89: if getattr(options, required_opt) is None: bh@89: print >>sys.stderr, "The --%s option must be given" % required_opt bh@89: sys.exit(1) bh@89: publish_packages(options.config_file, options.track, options.revision, bh@89: options.dist, options.section) bh@89: bh@89: main()