comparison bin/initpbuilder.py @ 78:9a602d8eaa60

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