annotate bin/initpbuilder.py @ 87:08d8ffd40f27

add some tests for the PackageTrack.last_packaged_revision() method
author Bernhard Herzog <bh@intevation.de>
date Tue, 11 Sep 2007 10:05:15 +0000
parents 9a602d8eaa60
children e6cfe3b80956
rev   line source
78
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
1 #! /usr/bin/python2.4
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
2 # Copyright (C) 2007 by Intevation GmbH
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
3 # Authors:
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
4 # Bernhard Herzog <bh@intevation.de>
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
5 #
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
6 # This program is free software under the GPL (>=v2)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
7 # Read the file COPYING coming with the software for details.
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
8
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
9 """Script to initialize the pbuilder environment for the tree packager
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
10
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
11 The script assumes that the config file for the tree packager already
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
12 contains the pbuilder settings. Also, this script assumes that there is
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
13 only one pbuilder setting for all packagers.
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
14 """
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
15
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
16 import sys
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
17 import os
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
18 from optparse import OptionParser
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
19
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
20 import treepkgcmd
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
21 from treepkg.options import create_parser
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
22 from treepkg.packager import create_package_track, PackagerGroup
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
23 from treepkg.readconfig import read_config
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
24 from treepkg.util import ensure_directory, writefile
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
25 from treepkg.run import call
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
26
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
27
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
28 pbuilderrc_template = '''\
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
29 # This file was automatically generated by initpbuilder.py.
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
30 # for the possible settings see "man pbuilderrc"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
31
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
32 BASETGZ=%(basedir)s/base.tgz
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
33 BUILDPLACE=%(builddir)s
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
34 USEPROC=yes
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
35 USEDEVPTS=yes
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
36 BUILDRESULT=%(resultdir)s
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
37 DISTRIBUTION=%(distribution)s
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
38 APTCACHE=%(basedir)s/aptcache
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
39 APTCACHEHARDLINK=yes
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
40 REMOVEPACKAGES=lilo
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
41 MIRRORSITE="%(mirrorsite)s"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
42 OTHERMIRROR="%(othermirror)s"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
43 BINDMOUNTS="%(extra-pkgdir)s"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
44 PKGNAME_LOGFILE=yes
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
45 '''
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
46
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
47
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
48 def init_pbuilder(pbuilderrc, distribution, mirrorsite, extramirrors, root_cmd):
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
49 if not os.path.isabs(pbuilderrc):
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
50 print >>sys.stderr, "pbuilderrc must be an absolute filename"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
51 sys.exit(1)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
52
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
53 if os.path.exists(pbuilderrc):
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
54 print >>sys.stderr, "pbuilderrc %r already exists." % pbuilderrc
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
55 sys.exit(1)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
56
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
57 basedir = os.path.dirname(pbuilderrc)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
58 replacements = dict(basedir=basedir,
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
59 distribution=distribution,
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
60 mirrorsite=mirrorsite)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
61
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
62 # create the pbuilder directories. basedir is created implicitly by
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
63 # creating its subdirectories.
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
64 for subdir in ["base", "build", "result", "aptcache", "extra-pkg"]:
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
65 directory = os.path.join(basedir, subdir)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
66 replacements[subdir + "dir"] = directory
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
67 print "creating directory:", repr(directory)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
68 ensure_directory(directory)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
69
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
70 # build OTHERMIRROR value. We always include the extra-pkg dir.
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
71 othermirror = "deb file://%(extra-pkgdir)s ./" % replacements
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
72 if extramirrors:
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
73 othermirror += " | " + extramirrors
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
74 replacements["othermirror"] = othermirror
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
75
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
76 # create the pbuilderrcfile
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
77 print "creating pbuilderrc:", repr(pbuilderrc)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
78 writefile(pbuilderrc, pbuilderrc_template % replacements)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
79
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
80 # turn the extra-pkg directory into a property deb archive
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
81 print "turning the extra-pkg dir into a debian archive"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
82 extra_pkgdir = replacements["extra-pkgdir"]
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
83 call(["apt-ftparchive", "packages", "."],
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
84 stdout=open(os.path.join(extra_pkgdir, "Packages"), "w"),
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
85 cwd=extra_pkgdir)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
86
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
87 # create the base.tgz chroot
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
88 print "running pbuilder create"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
89 call(root_cmd + ["pbuilder", "create", "--configfile", pbuilderrc])
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
90
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
91
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
92 def parse_commandline():
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
93 parser = create_parser()
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
94 parser.set_defaults(distribution="etch")
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
95 parser.add_option("--mirrorsite",
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
96 help=("The debian mirror site"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
97 " (pbuilder MIRRORSITE setting). Required."))
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
98 parser.add_option("--othermirror",
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
99 help=("Extra contents of the OTHERMIRROR setting."
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
100 " See the pbuilder documentation for the format."))
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
101 parser.add_option("--distribution",
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
102 help=("The debian distribution for the pbuilder chroot."
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
103 " Default is etch."))
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
104 return parser.parse_args()
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
105
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
106
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
107 def main():
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
108 options, args = parse_commandline()
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
109
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
110 if options.mirrorsite is None:
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
111 print >>sys.stderr, "Missing required option --mirrorsite"
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
112 sys.exit(1)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
113
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
114 treepkg_opts, packager_opts = read_config(options.config_file)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
115 group = PackagerGroup([create_package_track(**opts)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
116 for opts in packager_opts],
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
117 **treepkg_opts)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
118 track = group.get_package_tracks()[0]
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
119 init_pbuilder(track.pbuilderrc,
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
120 distribution=options.distribution,
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
121 mirrorsite=options.mirrorsite,
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
122 extramirrors=options.othermirror,
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
123 root_cmd=track.root_cmd)
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
124
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
125 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)