Mercurial > treepkg
annotate bin/initpbuilder.py @ 112:cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Use this class in treepkg.packager.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 20 Mar 2008 20:21:34 +0000 |
parents | b4226070371f |
children | bfcb2bbf9a52 |
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 |
102 | 2 # Copyright (C) 2007, 2008 by Intevation GmbH |
78
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 |
105
b4226070371f
Use cmdexpand in bin/initpbuilder.py
Bernhard Herzog <bh@intevation.de>
parents:
102
diff
changeset
|
26 from treepkg.cmdexpand import cmdexpand |
78
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 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
29 pbuilderrc_template = '''\ |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
30 # This file was automatically generated by initpbuilder.py. |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
31 # for the possible settings see "man pbuilderrc" |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
32 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
33 BASETGZ=%(basedir)s/base.tgz |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
34 BUILDPLACE=%(builddir)s |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
35 USEPROC=yes |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
36 USEDEVPTS=yes |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
37 BUILDRESULT=%(resultdir)s |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
38 DISTRIBUTION=%(distribution)s |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
39 APTCACHE=%(basedir)s/aptcache |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
40 APTCACHEHARDLINK=yes |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
41 REMOVEPACKAGES=lilo |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
42 MIRRORSITE="%(mirrorsite)s" |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
43 OTHERMIRROR="%(othermirror)s" |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
44 BINDMOUNTS="%(extra-pkgdir)s" |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
45 PKGNAME_LOGFILE=yes |
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 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
49 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
|
50 if not os.path.isabs(pbuilderrc): |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
51 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
|
52 sys.exit(1) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
53 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
54 if os.path.exists(pbuilderrc): |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
55 print >>sys.stderr, "pbuilderrc %r already exists." % pbuilderrc |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
56 sys.exit(1) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
57 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
58 basedir = os.path.dirname(pbuilderrc) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
59 replacements = dict(basedir=basedir, |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
60 distribution=distribution, |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
61 mirrorsite=mirrorsite) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
62 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
63 # 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
|
64 # creating its subdirectories. |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
65 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
|
66 directory = os.path.join(basedir, subdir) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
67 replacements[subdir + "dir"] = directory |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
68 print "creating directory:", repr(directory) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
69 ensure_directory(directory) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
70 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
71 # 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
|
72 othermirror = "deb file://%(extra-pkgdir)s ./" % replacements |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
73 if extramirrors: |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
74 othermirror += " | " + extramirrors |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
75 replacements["othermirror"] = othermirror |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
76 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
77 # create the pbuilderrcfile |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
78 print "creating pbuilderrc:", repr(pbuilderrc) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
79 writefile(pbuilderrc, pbuilderrc_template % replacements) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
80 |
102 | 81 # turn the extra-pkg directory into a proper deb archive |
78
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
82 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
|
83 extra_pkgdir = replacements["extra-pkgdir"] |
105
b4226070371f
Use cmdexpand in bin/initpbuilder.py
Bernhard Herzog <bh@intevation.de>
parents:
102
diff
changeset
|
84 call(cmdexpand("apt-ftparchive packages ."), |
78
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
85 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
|
86 cwd=extra_pkgdir) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
87 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
88 # create the base.tgz chroot |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
89 print "running pbuilder create" |
105
b4226070371f
Use cmdexpand in bin/initpbuilder.py
Bernhard Herzog <bh@intevation.de>
parents:
102
diff
changeset
|
90 call(cmdexpand("@root_cmd pbuilder create --configfile $pbuilderrc", |
b4226070371f
Use cmdexpand in bin/initpbuilder.py
Bernhard Herzog <bh@intevation.de>
parents:
102
diff
changeset
|
91 **locals())) |
78
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
92 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
93 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
94 def parse_commandline(): |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
95 parser = create_parser() |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
96 parser.set_defaults(distribution="etch") |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
97 parser.add_option("--mirrorsite", |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
98 help=("The debian mirror site" |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
99 " (pbuilder MIRRORSITE setting). Required.")) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
100 parser.add_option("--othermirror", |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
101 help=("Extra contents of the OTHERMIRROR setting." |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
102 " See the pbuilder documentation for the format.")) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
103 parser.add_option("--distribution", |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
104 help=("The debian distribution for the pbuilder chroot." |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
105 " Default is etch.")) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
106 return parser.parse_args() |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
107 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
108 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
109 def main(): |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
110 options, args = parse_commandline() |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
111 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
112 if options.mirrorsite is None: |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
113 print >>sys.stderr, "Missing required option --mirrorsite" |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
114 sys.exit(1) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
115 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
116 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
|
117 group = PackagerGroup([create_package_track(**opts) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
118 for opts in packager_opts], |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
119 **treepkg_opts) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
120 track = group.get_package_tracks()[0] |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
121 init_pbuilder(track.pbuilderrc, |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
122 distribution=options.distribution, |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
123 mirrorsite=options.mirrorsite, |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
124 extramirrors=options.othermirror, |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
125 root_cmd=track.root_cmd) |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
126 |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
127 main() |