annotate initpbuilder.py @ 59:9cb94b9ac6a6

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