comparison initpbuilder.py @ 48:aed3869ac04a

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