diff bin/publishpackages.py @ 89:3caf4a5ecbf0

Add scripts that help publish the packages produced by the tree packager
author Bernhard Herzog <bh@intevation.de>
date Tue, 11 Sep 2007 13:48:18 +0000
parents
children ce03e24f6d0f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/publishpackages.py	Tue Sep 11 13:48:18 2007 +0000
@@ -0,0 +1,123 @@
+#! /usr/bin/python2.4
+# Copyright (C) 2007 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"))
+    return parser.parse_args()
+
+
+def publish_packages_arch(variables, track, revision, dist, section, arch):
+    # create web-page on build host
+    if arch == "source":
+        variables["pkgtype"] = "--source"
+    else:
+        variables["pkgtype"] = "--binary"
+
+    files = capture_output(cmdexpand("ssh $build_user$@$build_host"
+                                     " $build_listpackages"
+                                     " --track $track @revision $pkgtype",
+                                     **variables)).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)
+
+    variables = config.copy()
+    variables["track"] = track
+    if revision:
+        variables["revision"] = ["--revision", revision]
+    else:
+        variables["revision"] = []
+
+    for arch in ["binary-i386", "source"]:
+        publish_packages_arch(variables, track, revision, dist, section, arch)
+
+    # update apt archive
+    call(cmdexpand("ssh $publish_user$@$publish_host"
+                   " $publish_apt_archive_update",
+                   **variables))
+
+def main():
+    options, args = parse_commandline()
+    for required_opt in ["track", "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()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)