comparison 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
comparison
equal deleted inserted replaced
88:3ae54f99db26 89:3caf4a5ecbf0
1 #! /usr/bin/python2.4
2 # Copyright (C) 2007 by Intevation GmbH
3 # Authors:
4 # Bernhard Herzog <bh@intevation.de>
5 #
6 # This program is free software under the GPL (>=v2)
7 # Read the file COPYING coming with the software for details.
8
9 """Publishes selected packages created by treepkg"""
10
11 import sys
12 import os
13 import shutil
14 from optparse import OptionParser
15 from ConfigParser import SafeConfigParser
16
17 import treepkgcmd
18 from treepkg.readconfig import read_config_section
19 from treepkg.run import call, capture_output
20 from treepkg.cmdexpand import cmdexpand
21 from treepkg.util import ensure_directory, listdir_abs
22
23
24 def remove_trailing_slashes(s):
25 return s.rstrip("/")
26
27 def expand_filename(filename):
28 """
29 Applies os.path.expanduser and os.path.expandvars to filename
30 """
31 return os.path.expandvars(os.path.expanduser(filename))
32
33 config_desc = ["build_user", "build_host", "build_listpackages",
34 "publish_user", "publish_host", "publish_apt_archive_update",
35 ("publish_dir", remove_trailing_slashes),
36 ("cachedir",
37 lambda s: expand_filename(remove_trailing_slashes(s)))]
38
39 def read_config(filename):
40 parser = SafeConfigParser()
41 parser.read([filename])
42 return read_config_section(parser, "publishpackages", config_desc)
43
44 def parse_commandline():
45 parser = OptionParser()
46 parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir,
47 "publishpackages.cfg"))
48 parser.add_option("--config-file",
49 help=("The configuration file."
50 " Default is publishpackages.cfg"))
51 parser.add_option("--revision",
52 help=("The revision whose files are to be published."
53 " If not given, the latest revision is used"))
54 parser.add_option("--dist",
55 help=("The debian distribution name to use on"
56 " the publishing system"))
57 parser.add_option("--section",
58 help=("The debian distribution section name to use on"
59 " the publishing system"))
60 parser.add_option("--track",
61 help=("The package track whose files are to be"
62 " published"))
63 return parser.parse_args()
64
65
66 def publish_packages_arch(variables, track, revision, dist, section, arch):
67 # create web-page on build host
68 if arch == "source":
69 variables["pkgtype"] = "--source"
70 else:
71 variables["pkgtype"] = "--binary"
72
73 files = capture_output(cmdexpand("ssh $build_user$@$build_host"
74 " $build_listpackages"
75 " --track $track @revision $pkgtype",
76 **variables)).strip().split("\n")
77 # scp the packages to the cache dir
78 cachedir = variables["cachedir"]
79 shutil.rmtree(cachedir, ignore_errors=True)
80 ensure_directory(cachedir)
81 userhost = "%(build_user)s@%(build_host)s:" % variables
82 call(cmdexpand("scp @files $cachedir/",
83 files = [userhost + filename for filename in files],
84 **variables))
85
86 # copy the packages to the remote publishing host. Create the
87 # destination directory if it doesn't exist yet.
88 destdir = os.path.join(variables["publish_dir"], dist, section, arch)
89 call(cmdexpand("ssh $publish_user$@$publish_host mkdir --parents $destdir",
90 destdir=destdir, **variables))
91 call(cmdexpand("scp @files $publish_user$@$publish_host:$destdir",
92 files=listdir_abs(cachedir), destdir=destdir,
93 **variables))
94
95
96 def publish_packages(config_filename, track, revision, dist, section):
97 config = read_config(config_filename)
98
99 variables = config.copy()
100 variables["track"] = track
101 if revision:
102 variables["revision"] = ["--revision", revision]
103 else:
104 variables["revision"] = []
105
106 for arch in ["binary-i386", "source"]:
107 publish_packages_arch(variables, track, revision, dist, section, arch)
108
109 # update apt archive
110 call(cmdexpand("ssh $publish_user$@$publish_host"
111 " $publish_apt_archive_update",
112 **variables))
113
114 def main():
115 options, args = parse_commandline()
116 for required_opt in ["track", "dist", "section"]:
117 if getattr(options, required_opt) is None:
118 print >>sys.stderr, "The --%s option must be given" % required_opt
119 sys.exit(1)
120 publish_packages(options.config_file, options.track, options.revision,
121 options.dist, options.section)
122
123 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)