comparison bin/publishdebianpackages.py @ 406:52e3c3976e53 treepkg-status

inital checkin for new publishpackages processing
author Bjoern Ricks <bricks@intevation.de>
date Tue, 13 Jul 2010 16:46:17 +0000
parents
children 02d498ee90b8
comparison
equal deleted inserted replaced
405:eaf04fc0f615 406:52e3c3976e53
1 #! /usr/bin/python
2 # Copyright (C) 2007 - 2010 by Intevation GmbH
3 # Authors:
4 # Bernhard Herzog <bh@intevation.de>
5 # Bjoern Ricks <bjoern.ricks@intevation.de>
6 #
7 # This program is free software under the GPL (>=v2)
8 # Read the file COPYING coming with the software for details.
9
10 """Publishes selected packages created by treepkg"""
11
12 import os
13 import sys
14 import shlex
15
16 from optparse import OptionParser
17 from ConfigParser import SafeConfigParser
18
19 import treepkgcmd
20 from treepkg.readconfig import read_config_section, convert_bool
21 from treepkg.run import call, capture_output
22 from treepkg.cmdexpand import cmdexpand
23 from treepkg.publish import *
24 from treepkg.util import md5sum
25 from treepkg.info.status import TreepkgInfo
26
27 config_desc = ["distribution", "section", "num_newest",
28 "build_user", "build_host", "build_listpackages",
29 "publish_user", "publish_host",
30 ("architectures", shlex.split, "i386, source"),
31 ("after_upload_hook", shlex.split),
32 ("publish_remove_old_packages", convert_bool),
33 ("publish_dir", remove_trailing_slashes),
34 ("cachedir",
35 lambda s: expand_filename(remove_trailing_slashes(s)))]
36
37 def read_config(filename):
38 if not os.path.exists(filename):
39 print >>sys.stderr, "Config file %s does not exist" % filename
40 sys.exit(1)
41 parser = SafeConfigParser()
42 parser.read([filename])
43 return read_config_section(parser, "publishpackages", config_desc)
44
45 def parse_commandline():
46 parser = OptionParser()
47 parser.set_defaults(config_file=os.path.join(treepkgcmd.topdir,
48 "publishpackages.cfg"),
49 quiet=False)
50 parser.add_option("--config-file",
51 help=("The configuration file."
52 " Default is publishpackages.cfg"))
53 parser.add_option("--dist",
54 help=("The debian distribution name to use on"
55 " the publishing system"))
56 parser.add_option("--section",
57 help=("The debian distribution section name to use on"
58 " the publishing system"))
59 parser.add_option("--track",
60 help=("The package track whose files are to be"
61 " published. If not given, files of all tracks"
62 " will be published"))
63 parser.add_option("--quiet", action="store_true",
64 help=("Do not print progress meters or other"
65 " informational output"))
66 return parser.parse_args()
67
68 def get_treepkg_info(variables):
69 runremote = prefix_for_remote_command(variables["build_user"],
70 variables["build_host"])
71 xml = capture_output(cmdexpand("@runremote $build_listpackages"
72 " --newest=$num_newest",
73 #runremote=runremote,
74 runremote="",
75 **variables)).splitlines()
76 treepkginfo = TreepkgInfo.fromxml(xml)
77
78 def get_binary_arch(arch):
79 if not arch == "source":
80 if not arch.startswith("binary"):
81 arch = "binary-" + arch
82 return arch
83
84 def check_package_is_new(packagename, destdir, packagemd5sum):
85 destpackage = os.path.join(destdir, packagename)
86 if not os.path.isfile(destpackage):
87 return True
88 destmd5sum = md5sum(destpackage)
89 return destmd5sum == packagemd5sum
90
91 def copy_to_cache(variables, track, revision, quiet, architectures=None):
92 scp_flags = []
93 if quiet:
94 scp_flags.append("-q")
95 treepkginfo = get_treepkg_info(variables)
96 treepkgroot = treepkginfo.root
97 binaryarchs = []
98 # change e.g. armel in binary-armel
99 for arch in architectures:
100 binaryarchs.append(get_binary_arch(arch))
101 # add binary-all to requested packages
102 if not binaryarchs is None:
103 binaryarchs.append("binary-all")
104
105 for track in treepkgroot.tracks:
106 files = []
107 for rev in track.revisions:
108 for package in rev.packages:
109 # only copy requested archs (+ all)
110 if not binaryarchs is None and \
111 not package.arch in binaryarchs:
112 break
113 destdir = os.path.join(variables["cachedir"],
114 package.arch,
115 track.name)
116 print "package: %s, destdir: %s" % (package.name, destdir)
117 md5sum = ""
118 for checksum in package.checksums:
119 if checksum.type == "md5":
120 md5sum = checksum.checksum
121 break
122 # update only if the packages differ
123 if check_package_is_new(package.name, destdir, md5sum):
124 files.append(package.path)
125 # scp the packages of a track to the cache dir
126 #call(cmdexpand("scp -p @scp_flags @files $cachedir/", files=files,
127 # scp_flags=scp_flagsd, cachedir=destdir))
128
129 def publish_packages_arch(variables, track, revision, dist, section,
130 quiet, architectures):
131 copy_to_cache(variables, track, revision, quiet, architectures)
132 # copy_to_publishdir(variables, dist, section, arch, quiet)
133
134 def publish_packages(config_filename, track, revision, dist, section, quiet):
135 config = read_config(config_filename)
136
137 if dist is None:
138 dist = config["distribution"]
139 if section is None:
140 section = config["section"]
141
142 architectures = config["architectures"]
143 publish_packages_arch(config, track, revision, dist, section,
144 quiet, architectures)
145
146 # update apt archive
147 # call(config["after_upload_hook"])
148
149 def main():
150 options, args = parse_commandline()
151 revision = None # for future use cases
152 publish_packages(options.config_file, options.track, revision,
153 options.dist, options.section, options.quiet)
154
155 if __name__ == "__main__":
156 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)