Mercurial > treepkg > treepkg
annotate treepkg/builder.py @ 579:97a5e09c84dc tip
Fix: pass url to command expand to be able to checkout a new git repository
author | Bjoern Ricks <bricks@intevation.de> |
---|---|
date | Sat, 03 Sep 2011 12:32:32 +0000 |
parents | 058856954e2d |
children |
rev | line source |
---|---|
245
21da92cea416
Add --save-after-login option to bin/treepkgbuilder.py and corresponding
Bernhard Herzog <bh@intevation.de>
parents:
213
diff
changeset
|
1 # Copyright (C) 2007, 2008, 2009 by Intevation GmbH |
112
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 |
184
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
14 import tempfile |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
15 |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
16 import util |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
17 import run |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
18 from cmdexpand import cmdexpand |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
19 |
344
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
20 class Builder: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
21 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
22 basetgz_dir = util.filenameproperty("base") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
23 build_dir = util.filenameproperty("build") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
24 result_dir = util.filenameproperty("result") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
25 aptcache_dir = util.filenameproperty("aptcache") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
26 extra_pkg_dir = util.filenameproperty("extra-pkg") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
27 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
28 """ Parent class for all Builders """ |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
29 def __init__(self): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
30 pass |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
31 |
344
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
32 def update_extra_pkg_dir(self): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
33 run.call(cmdexpand("apt-ftparchive packages ."), |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
34 stdout=open(os.path.join(self.extra_pkg_dir, "Packages"), "w"), |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
35 cwd=self.extra_pkg_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
36 release_filename = os.path.join(self.extra_pkg_dir, "Release") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
37 run.call(cmdexpand("apt-ftparchive release ."), |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
38 stdout=open(release_filename, "w"), cwd=self.extra_pkg_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
39 # handle signatures. remove any existing signature because it |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
40 # will be invalid now. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
41 signature = release_filename + ".gpg" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
42 try: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
43 os.remove(signature) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
44 except OSError: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
45 pass |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
46 if self.release_signing_keyid: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
47 run.call(cmdexpand("gpg --detach-sign --armor --local-user=$keyid" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
48 " -o $sig $release", |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
49 keyid=self.release_signing_keyid, |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
50 sig=release_filename + ".gpg", |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
51 release=release_filename)) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
52 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
53 def add_binaries_to_extra_pkg(self, filenames, subdirectory="auto"): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
54 """Adds binary packages to the extra-pkg directory. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
55 The filenames parameter should be sequence of absolute |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
56 filenames. The files named will be copied to a subdirectory of |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
57 the extra-pkg directory which is assumed to reside in the same |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
58 directory as the pbuilderrc. The subdirectory is specified with |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
59 the subdirectory parameter and defaults to 'auto'. Afterwards, |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
60 the method generates a Packages file in the directory and runs |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
61 pbuilder update. All of this assumes that pbuilder was set up |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
62 the way bin/initpbuilder.py does. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
63 """ |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
64 target_dir = os.path.join(self.extra_pkg_dir, subdirectory) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
65 util.ensure_directory(target_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
66 for filename in filenames: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
67 logging.info("Copying %s into %s", filename, target_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
68 shutil.copy(filename, target_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
69 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
70 logging.info("Running apt-ftparchive in %s", self.extra_pkg_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
71 self.update_extra_pkg_dir() |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
72 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
73 self.update(suppress_output=True, log_info=True) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
74 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
75 class PBuilder(Builder): |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
76 |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
77 """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
|
78 |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
79 pbuilderrc_template = '''\ |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
80 # 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
|
81 # 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
|
82 |
173
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
83 BASETGZ=%(basetgz_dir)s/base.tgz |
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
84 BUILDPLACE=%(build_dir)s |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
85 USEPROC=yes |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
86 USEDEVPTS=yes |
173
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
87 BUILDRESULT=%(result_dir)s |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
88 DISTRIBUTION=%(distribution)s |
173
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
89 APTCACHE=%(aptcache_dir)s |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
90 APTCACHEHARDLINK=yes |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
91 REMOVEPACKAGES=lilo |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
92 MIRRORSITE="%(mirrorsite)s" |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
93 OTHERMIRROR="%(othermirror)s" |
173
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
94 BINDMOUNTS="%(extra_pkg_dir)s" |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
95 PKGNAME_LOGFILE=yes |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
96 ''' |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
97 |
176
7bde59aa611e
Make PBuilder.update_extra_pkg_dir create Release and Release.gpg files
Bernhard Herzog <bh@intevation.de>
parents:
174
diff
changeset
|
98 def __init__(self, pbuilderrc, root_cmd, release_signing_keyid=None): |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
99 """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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 worry about quoting. |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
105 """ |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
106 self.pbuilderrc = pbuilderrc |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
107 self.root_cmd = root_cmd |
176
7bde59aa611e
Make PBuilder.update_extra_pkg_dir create Release and Release.gpg files
Bernhard Herzog <bh@intevation.de>
parents:
174
diff
changeset
|
108 self.release_signing_keyid = release_signing_keyid |
173
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
109 self.base_dir = os.path.dirname(self.pbuilderrc) |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
110 |
344
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
339
diff
changeset
|
111 def init_builder(self, distribution, mirrorsite, extramirrors): |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
112 """Initializes the pbuilder instance""" |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
113 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
|
114 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
|
115 sys.exit(1) |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
116 |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
117 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
|
118 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
|
119 % self.pbuilderrc) |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
120 sys.exit(1) |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
121 |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
122 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
|
123 replacements = dict(basedir=basedir, |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
124 distribution=distribution, |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
125 mirrorsite=mirrorsite) |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
126 |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
127 # 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
|
128 # creating its subdirectories. |
173
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
129 for attr in ["basetgz_dir", "build_dir", "result_dir", "aptcache_dir", |
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
130 "extra_pkg_dir"]: |
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
131 directory = getattr(self, attr) |
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
132 replacements[attr] = directory |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
133 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
|
134 util.ensure_directory(directory) |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
135 |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
136 # build OTHERMIRROR value. We always include the extra-pkg dir. |
173
97435e92411a
Introduce filenameproperties for the various directories in the PBuilder class
Bernhard Herzog <bh@intevation.de>
parents:
171
diff
changeset
|
137 othermirror = "deb file://%(extra_pkg_dir)s ./" % replacements |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
138 if extramirrors: |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
139 othermirror += " | " + extramirrors |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
140 replacements["othermirror"] = othermirror |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
141 |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
142 # create the pbuilderrcfile |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
143 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
|
144 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
|
145 |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
146 # 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
|
147 print "turning the extra-pkg dir into a debian archive" |
174
2d7415b84e32
treepkg.builder.PBuilder: refactor the actual apt-ftparchive call into a
Bernhard Herzog <bh@intevation.de>
parents:
173
diff
changeset
|
148 self.update_extra_pkg_dir() |
170
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
149 |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
150 # 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
|
151 print "running pbuilder create" |
bfcb2bbf9a52
Move the pbuilder initialization code from bin/initpbuilder.py to
Bernhard Herzog <bh@intevation.de>
parents:
138
diff
changeset
|
152 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
|
153 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
|
154 |
178
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
155 def update(self, suppress_output=True, log_info=True): |
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
156 """Runs pbuilder update on this pbuilder instance""" |
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
157 if log_info: |
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
158 logging.info("Running pbuilder update for %s", self.pbuilderrc) |
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
159 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder update" |
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
160 " --configfile $pbuilderrc", |
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
161 rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc), |
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
162 suppress_output=suppress_output) |
b2fa3b0926d0
PBuilder: refactor the "pbuilder update" call into a separate method
Bernhard Herzog <bh@intevation.de>
parents:
176
diff
changeset
|
163 |
184
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
164 def add_apt_key(self, keyid): |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
165 """Runs apt-key add in the chroot""" |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
166 # Creates a temporary file in extra_pkg_dir (because that's |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
167 # bind-mounted by default) with a script that adds the desired |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
168 # key. The exported key is included in the script file so that |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
169 # only one file has to be created |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
170 script = tempfile.NamedTemporaryFile(dir=self.extra_pkg_dir) |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
171 try: |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
172 script.write("#! /bin/sh\n") |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
173 script.write("apt-key add $0\n") |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
174 script.write("exit\n\n") |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
175 script.flush() |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
176 run.call(cmdexpand("gpg --export --armor $keyid", **locals()), |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
177 stdout=script.fileno()) |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
178 self.run_script([script.name], logfile=None, save_after_exec=True) |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
179 finally: |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
180 script.close() |
83c77307ffb1
Add the addkey command to bin/treepkgbuilder.py and a corresponding
Bernhard Herzog <bh@intevation.de>
parents:
182
diff
changeset
|
181 |
209
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
182 def build(self, dsc_file, binary_dir=None, logfile=None, bindmounts=(), |
126
68d829cac3ff
New parameter for PBuilder.build: extra_env, a mapping with extra
Bernhard Herzog <bh@intevation.de>
parents:
122
diff
changeset
|
183 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
|
184 """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
|
185 Parameters: |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 bind-mounted in the pbuilder chroot |
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
191 environment |
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
192 extra_packages -- Extra packages to install |
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
193 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
|
194 when runing the pbuilder process. If pbuilder |
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
195 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
|
196 not remove these variables when it starts |
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
197 pbuilder |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
198 """ |
122
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
199 args = [] |
209
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
200 if logfile is not None: |
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
201 args.extend(["--logfile", logfile]) |
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
202 if binary_dir is not None: |
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
203 args.extend(["--buildresult", binary_dir]) |
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
204 util.ensure_directory(binary_dir) |
122
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
205 for mount in bindmounts: |
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
206 args.extend(["--bindmounts", mount]) |
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
207 for pkg in extra_packages: |
6e34fc4ebe39
New arguments for the PBuilder.build method:
Bernhard Herzog <bh@intevation.de>
parents:
121
diff
changeset
|
208 args.extend(["--extrapackages", pkg]) |
462
058856954e2d
Make the compress_all_logs call builder independent and also compress
Andre Heinecke <aheinecke@intevation.de>
parents:
461
diff
changeset
|
209 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build" |
058856954e2d
Make the compress_all_logs call builder independent and also compress
Andre Heinecke <aheinecke@intevation.de>
parents:
461
diff
changeset
|
210 " --configfile $pbuilderrc @args" |
058856954e2d
Make the compress_all_logs call builder independent and also compress
Andre Heinecke <aheinecke@intevation.de>
parents:
461
diff
changeset
|
211 " --debbuildopts -b $dsc", |
058856954e2d
Make the compress_all_logs call builder independent and also compress
Andre Heinecke <aheinecke@intevation.de>
parents:
461
diff
changeset
|
212 rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc, |
058856954e2d
Make the compress_all_logs call builder independent and also compress
Andre Heinecke <aheinecke@intevation.de>
parents:
461
diff
changeset
|
213 dsc=dsc_file, args=args), |
058856954e2d
Make the compress_all_logs call builder independent and also compress
Andre Heinecke <aheinecke@intevation.de>
parents:
461
diff
changeset
|
214 suppress_output=True, |
058856954e2d
Make the compress_all_logs call builder independent and also compress
Andre Heinecke <aheinecke@intevation.de>
parents:
461
diff
changeset
|
215 extra_env=extra_env) |
461
454967511f5c
commit compress all logs patch from Sascha Teichmann
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
216 |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
217 # 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
|
218 # by pbuilder |
209
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
219 if binary_dir is not None: |
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
220 for filename in os.listdir(binary_dir): |
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
221 if os.path.splitext(filename)[1] not in (".deb", ".changes"): |
cbcd8f549ff7
Make logfile and binary_dir parameters of PBuilder.build optional.
Bernhard Herzog <bh@intevation.de>
parents:
201
diff
changeset
|
222 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
|
223 |
121
890bb70920d6
Add the PBuilder.add_binaries_to_extra_pkg method. It allows automatic
Bernhard Herzog <bh@intevation.de>
parents:
119
diff
changeset
|
224 |
182
88c8f255b5a0
Add the save_after_exec argument to the PBuilder.run_script method. If
Bernhard Herzog <bh@intevation.de>
parents:
181
diff
changeset
|
225 def run_script(self, script, logfile, bindmounts=(), save_after_exec=False): |
119
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
226 """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
|
227 Parameters: |
181
81585486281b
Extend the PBuilder.run_script method so that the script can be called
Bernhard Herzog <bh@intevation.de>
parents:
178
diff
changeset
|
228 script -- A list of strings with the command line to invoke the |
81585486281b
Extend the PBuilder.run_script method so that the script can be called
Bernhard Herzog <bh@intevation.de>
parents:
178
diff
changeset
|
229 script |
119
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 environment (optional) |
182
88c8f255b5a0
Add the save_after_exec argument to the PBuilder.run_script method. If
Bernhard Herzog <bh@intevation.de>
parents:
181
diff
changeset
|
234 save_after_exec -- Boolean indicating whether the chroot |
88c8f255b5a0
Add the save_after_exec argument to the PBuilder.run_script method. If
Bernhard Herzog <bh@intevation.de>
parents:
181
diff
changeset
|
235 environment should be copied back so that |
88c8f255b5a0
Add the save_after_exec argument to the PBuilder.run_script method. If
Bernhard Herzog <bh@intevation.de>
parents:
181
diff
changeset
|
236 modifications are available in subsequent |
88c8f255b5a0
Add the save_after_exec argument to the PBuilder.run_script method. If
Bernhard Herzog <bh@intevation.de>
parents:
181
diff
changeset
|
237 uses of the pbuilder instance. |
119
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
238 """ |
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
239 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
|
240 args = [] |
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
241 if logfile: |
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
242 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
|
243 # 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
|
244 # 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
|
245 # 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
|
246 # pbuilder |
1bcdc8934b27
In PBuilder.run_script create the log file before starting pbuilder to
Bernhard Herzog <bh@intevation.de>
parents:
126
diff
changeset
|
247 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
|
248 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
|
249 args.extend(["--bindmounts", mount]) |
182
88c8f255b5a0
Add the save_after_exec argument to the PBuilder.run_script method. If
Bernhard Herzog <bh@intevation.de>
parents:
181
diff
changeset
|
250 if save_after_exec: |
88c8f255b5a0
Add the save_after_exec argument to the PBuilder.run_script method. If
Bernhard Herzog <bh@intevation.de>
parents:
181
diff
changeset
|
251 args.append("--save-after-exec") |
119
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
252 |
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
253 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder execute" |
182
88c8f255b5a0
Add the save_after_exec argument to the PBuilder.run_script method. If
Bernhard Herzog <bh@intevation.de>
parents:
181
diff
changeset
|
254 " --configfile $pbuilderrc @args -- @script", |
119
92116333ef77
Add PBuilder.run_script method and associated tests. The run_script
Bernhard Herzog <bh@intevation.de>
parents:
112
diff
changeset
|
255 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
|
256 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
|
257 suppress_output=False) |
201
6624e731e218
Add login command to bin/treepkgbuilder.py and corresponding method in
Bernhard Herzog <bh@intevation.de>
parents:
189
diff
changeset
|
258 |
245
21da92cea416
Add --save-after-login option to bin/treepkgbuilder.py and corresponding
Bernhard Herzog <bh@intevation.de>
parents:
213
diff
changeset
|
259 def login(self, bindmounts=(), save_after_login=False): |
201
6624e731e218
Add login command to bin/treepkgbuilder.py and corresponding method in
Bernhard Herzog <bh@intevation.de>
parents:
189
diff
changeset
|
260 """Start an interactive shell in the pbuilder environment""" |
213
98c5aab790bb
Add --bind-mount option to bin/treepkgbuilder.py's login command and a
Bernhard Herzog <bh@intevation.de>
parents:
209
diff
changeset
|
261 args = [] |
98c5aab790bb
Add --bind-mount option to bin/treepkgbuilder.py's login command and a
Bernhard Herzog <bh@intevation.de>
parents:
209
diff
changeset
|
262 for mount in bindmounts: |
98c5aab790bb
Add --bind-mount option to bin/treepkgbuilder.py's login command and a
Bernhard Herzog <bh@intevation.de>
parents:
209
diff
changeset
|
263 args.extend(["--bindmounts", mount]) |
245
21da92cea416
Add --save-after-login option to bin/treepkgbuilder.py and corresponding
Bernhard Herzog <bh@intevation.de>
parents:
213
diff
changeset
|
264 if save_after_login: |
21da92cea416
Add --save-after-login option to bin/treepkgbuilder.py and corresponding
Bernhard Herzog <bh@intevation.de>
parents:
213
diff
changeset
|
265 args.extend(["--save-after-login"]) |
201
6624e731e218
Add login command to bin/treepkgbuilder.py and corresponding method in
Bernhard Herzog <bh@intevation.de>
parents:
189
diff
changeset
|
266 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder login" |
213
98c5aab790bb
Add --bind-mount option to bin/treepkgbuilder.py's login command and a
Bernhard Herzog <bh@intevation.de>
parents:
209
diff
changeset
|
267 " --configfile $pbuilderrc @args", |
98c5aab790bb
Add --bind-mount option to bin/treepkgbuilder.py's login command and a
Bernhard Herzog <bh@intevation.de>
parents:
209
diff
changeset
|
268 rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc, |
98c5aab790bb
Add --bind-mount option to bin/treepkgbuilder.py's login command and a
Bernhard Herzog <bh@intevation.de>
parents:
209
diff
changeset
|
269 args=args), |
201
6624e731e218
Add login command to bin/treepkgbuilder.py and corresponding method in
Bernhard Herzog <bh@intevation.de>
parents:
189
diff
changeset
|
270 suppress_output=False) |