annotate treepkg/builder.py @ 170:bfcb2bbf9a52

Move the pbuilder initialization code from bin/initpbuilder.py to treepkg/builder.py to make it work again and add some tests.
author Bernhard Herzog <bh@intevation.de>
date Mon, 23 Jun 2008 13:21:08 +0000
parents 1bcdc8934b27
children c0ea6cbb0fd2
rev   line source
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2007, 2008 by Intevation GmbH
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
2 # Authors:
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
3 # Bernhard Herzog <bh@intevation.de>
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
4 #
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
7
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
8 """Build binary packages from source packages"""
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
9
170
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
10 import sys
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
11 import os
121
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
12 import shutil
119
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
13 import logging
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
14
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
15 import util
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
16 import run
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
17 from cmdexpand import cmdexpand
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
18
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
19
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
20 class PBuilder(object):
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
21
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
22 """Represents a way to run and manage a specific pbuilder instance"""
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
23
170
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
24 pbuilderrc_template = '''\
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
25 # This file was automatically generated by initpbuilder.py.
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
26 # for the possible settings see "man pbuilderrc"
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
27
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
28 BASETGZ=%(basedir)s/base.tgz
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
29 BUILDPLACE=%(builddir)s
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
30 USEPROC=yes
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
31 USEDEVPTS=yes
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
32 BUILDRESULT=%(resultdir)s
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
33 DISTRIBUTION=%(distribution)s
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
34 APTCACHE=%(basedir)s/aptcache
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
35 APTCACHEHARDLINK=yes
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
36 REMOVEPACKAGES=lilo
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
37 MIRRORSITE="%(mirrorsite)s"
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
38 OTHERMIRROR="%(othermirror)s"
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
39 BINDMOUNTS="%(extra-pkgdir)s"
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
40 PKGNAME_LOGFILE=yes
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
41 '''
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
42
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
43
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
44 def __init__(self, pbuilderrc, root_cmd):
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
45 """Initialize the PBuilder instance with the configuration file.
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
46 The root_cmd parameter should be a list with a command that can
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
47 be used to get root permissions to run pbuilder. It may be an
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
48 empty list if no command is needed. It's a list so that
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
49 commands with several shell-words can be used without having to
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
50 worry about quoting.
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
51 """
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
52 self.pbuilderrc = pbuilderrc
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
53 self.root_cmd = root_cmd
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
54
170
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
55 def init_pbuilder(self, distribution, mirrorsite, extramirrors):
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
56 """Initializes the pbuilder instance"""
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
57 if not os.path.isabs(self.pbuilderrc):
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
58 print >>sys.stderr, "pbuilderrc must be an absolute filename"
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
59 sys.exit(1)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
60
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
61 if os.path.exists(self.pbuilderrc):
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
62 print >>sys.stderr, ("pbuilderrc %r already exists."
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
63 % self.pbuilderrc)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
64 sys.exit(1)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
65
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
66 basedir = os.path.dirname(self.pbuilderrc)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
67 replacements = dict(basedir=basedir,
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
68 distribution=distribution,
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
69 mirrorsite=mirrorsite)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
70
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
71 # create the pbuilder directories. basedir is created implicitly by
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
72 # creating its subdirectories.
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
73 for subdir in ["base", "build", "result", "aptcache", "extra-pkg"]:
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
74 directory = os.path.join(basedir, subdir)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
75 replacements[subdir + "dir"] = directory
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
76 print "creating directory:", repr(directory)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
77 util.ensure_directory(directory)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
78
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
79 # build OTHERMIRROR value. We always include the extra-pkg dir.
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
80 othermirror = "deb file://%(extra-pkgdir)s ./" % replacements
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
81 if extramirrors:
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
82 othermirror += " | " + extramirrors
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
83 replacements["othermirror"] = othermirror
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
84
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
85 # create the pbuilderrcfile
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
86 print "creating pbuilderrc:", repr(self.pbuilderrc)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
87 util.writefile(self.pbuilderrc, self.pbuilderrc_template % replacements)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
88
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
89 # turn the extra-pkg directory into a proper deb archive
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
90 print "turning the extra-pkg dir into a debian archive"
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
91 extra_pkgdir = replacements["extra-pkgdir"]
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
92 run.call(cmdexpand("apt-ftparchive packages ."),
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
93 stdout=open(os.path.join(extra_pkgdir, "Packages"), "w"),
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
94 cwd=extra_pkgdir)
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
95
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
96 # create the base.tgz chroot
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
97 print "running pbuilder create"
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
98 run.call(cmdexpand("@root_cmd pbuilder create --configfile $pbuilderrc",
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
99 root_cmd=self.root_cmd, pbuilderrc=self.pbuilderrc))
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
100
bfcb2bbf9a52 Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents: 138
diff changeset
101
122
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
102 def build(self, dsc_file, binary_dir, logfile, bindmounts=(),
126
68d829cac3ff New parameter for PBuilder.build: extra_env, a mapping with extra
Bernhard Herzog <bh@intevation.de>
parents: 122
diff changeset
103 extra_packages=(), extra_env=None):
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
104 """Build a binary packager from a source package
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
105 Parameters:
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
106 dsc_file -- name of the debian .dsc file of the source package
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
107 binary_dir -- name of the directory to receive the binary packages
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
108 logfile -- name of the logfile of the build
122
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
109 bindmounts -- Sequence of directory names that should be
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
110 bind-mounted in the pbuilder chroot
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
111 environment
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
112 extra_packages -- Extra packages to install
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
113 extra_env -- mapping with extra environment variables to set
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
114 when runing the pbuilder process. If pbuilder
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
115 is started via sudo, make sure that sudo does
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
116 not remove these variables when it starts
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
117 pbuilder
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
118 """
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
119 util.ensure_directory(binary_dir)
122
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
120 args = []
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
121 for mount in bindmounts:
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
122 args.extend(["--bindmounts", mount])
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
123 for pkg in extra_packages:
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
124 args.extend(["--extrapackages", pkg])
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
125 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build"
122
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
126 " --configfile $pbuilderrc @args"
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
127 " --logfile $logfile --buildresult $bindir $dsc",
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
128 rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
122
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
129 logfile=logfile, bindir=binary_dir, dsc=dsc_file,
6e34fc4ebe39 New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents: 121
diff changeset
130 args=args),
126
68d829cac3ff New parameter for PBuilder.build: extra_env, a mapping with extra
Bernhard Herzog <bh@intevation.de>
parents: 122
diff changeset
131 suppress_output=True,
68d829cac3ff New parameter for PBuilder.build: extra_env, a mapping with extra
Bernhard Herzog <bh@intevation.de>
parents: 122
diff changeset
132 extra_env=extra_env)
112
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
133 # remove the source package files put into the binary directory
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
134 # by pbuilder
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
135 for filename in os.listdir(binary_dir):
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
136 if os.path.splitext(filename)[1] not in (".deb", ".changes"):
cea98d4e4a6a Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
137 os.remove(os.path.join(binary_dir, filename))
119
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
138
121
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
139 def add_binaries_to_extra_pkg(self, filenames):
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
140 """Adds binary packages to the extra-pkg directory.
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
141 The filenames parameter should be sequence of absolute
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
142 filenames. The files named will be copied to the extra-pkg
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
143 directory which is assumed to reside in the same directory as
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
144 the pbuilderrc. Afterwards, the method generates a Packages
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
145 file in the directory and runs pbuilder update. All of this
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
146 assumes that pbuilder was set up the way bin/initpbuilder.py
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
147 does.
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
148 """
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
149 extrapkg_dir = os.path.join(os.path.dirname(self.pbuilderrc),
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
150 "extra-pkg")
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
151 for filename in filenames:
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
152 logging.info("Copying %s into %s", filename, extrapkg_dir)
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
153 shutil.copy(filename, extrapkg_dir)
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
154 logging.info("Running apt-ftparchive in %s", extrapkg_dir)
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
155 run.call(cmdexpand("apt-ftparchive packages ."),
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
156 stdout=open(os.path.join(extrapkg_dir, "Packages"), "w"),
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
157 cwd=extrapkg_dir)
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
158 logging.info("Running pbuilder update for %s", self.pbuilderrc)
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
159 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder update"
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
160 " --configfile $pbuilderrc",
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
161 rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc),
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
162 suppress_output=True)
890bb70920d6 Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents: 119
diff changeset
163
119
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
164 def run_script(self, script, logfile, bindmounts=()):
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
165 """Execute a script in pbuilder's chroot environment
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
166 Parameters:
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
167 script -- The filename of the script
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
168 logfile -- name of the logfile of the build
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
169 bindmounts -- Sequence of directory names that should be
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
170 bind-mounted in the pbuilder chroot
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
171 environment (optional)
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
172 """
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
173 logging.info("Running pbuilder execute on %s", script)
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
174 args = []
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
175 if logfile:
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
176 args.extend(["--logfile", logfile])
138
1bcdc8934b27 In PBuilder.run_script create the log file before starting pbuilder to
Bernhard Herzog <bh@intevation.de>
parents: 126
diff changeset
177 # create the logfile. This makes sure that it is owned by
1bcdc8934b27 In PBuilder.run_script create the log file before starting pbuilder to
Bernhard Herzog <bh@intevation.de>
parents: 126
diff changeset
178 # the user the tree packager is running as and not root, as
1bcdc8934b27 In PBuilder.run_script create the log file before starting pbuilder to
Bernhard Herzog <bh@intevation.de>
parents: 126
diff changeset
179 # would be the case when it is created indirectly by
1bcdc8934b27 In PBuilder.run_script create the log file before starting pbuilder to
Bernhard Herzog <bh@intevation.de>
parents: 126
diff changeset
180 # pbuilder
1bcdc8934b27 In PBuilder.run_script create the log file before starting pbuilder to
Bernhard Herzog <bh@intevation.de>
parents: 126
diff changeset
181 open(logfile, "w").close()
119
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
182 for mount in bindmounts:
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
183 args.extend(["--bindmounts", mount])
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
184
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
185 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder execute"
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
186 " --configfile $pbuilderrc @args $script",
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
187 rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc,
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
188 args=args, script=script),
92116333ef77 Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
189 suppress_output=False)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)