Mercurial > treepkg > treepkg
annotate treepkg/sbuilder.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 | 5fa4b938a939 |
children |
rev | line source |
---|---|
344
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
1 # Copyright (C) 2010 by Intevation GmbH |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
2 # Authors: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
3 # Bjoern Ricks <bjoern.ricks@intevation.de> |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
4 # |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
5 # This program is free software under the GPL (>=v2) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
6 # Read the file COPYING coming with the software for details. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
7 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
8 """Build binary packages from source packages""" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
9 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
10 import sys |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
11 import os |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
12 import shutil |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
13 import logging |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
14 import tempfile |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
15 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
16 import util |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
17 import run |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
18 import builder |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
19 from cmdexpand import cmdexpand |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
20 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
21 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
22 class SbdmockBuilder(builder.Builder): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
23 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
24 """Represents a way to run and manage a specific sbdmock instance |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
25 to build binary for Maemo within scratchbox environment""" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
26 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
27 basetgz_dir = util.filenameproperty("base") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
28 build_dir = util.filenameproperty("build") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
29 result_dir = util.filenameproperty("result") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
30 aptcache_dir = util.filenameproperty("aptcache") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
31 extra_pkg_dir = util.filenameproperty("extra-pkg") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
32 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
33 def __init__(self, builderconfig, root_cmd, release_signing_keyid=None): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
34 """Initialize the Builder instance with the configuration file. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
35 The root_cmd parameter should be a list with a command that can |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
36 be used to get root permissions. It may be an |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
37 empty list if no command is needed. It's a list so that |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
38 commands with several shell-words can be used without having to |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
39 worry about quoting. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
40 """ |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
41 if not os.path.exists(builderconfig): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
42 raise RuntimeError("Config file %s for sbdmock does not exist.", |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
43 builderconfig) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
44 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
45 if not os.path.isabs(builderconfig): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
46 raise RuntimeError("Config file %s must be an absolute filename.", |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
47 builderconfig) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
48 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
49 self.builderconfig = builderconfig |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
50 self.root_cmd = root_cmd |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
51 self.release_signing_keyid = release_signing_keyid |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
52 self.base_dir = os.path.dirname(self.builderconfig) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
53 self.mounted_dirs = [] |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
54 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
55 def init_builder(self, distribution, mirrorsite, extramirrors): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
56 """Initializes the builder instance""" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
57 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
58 basedir = os.path.dirname(self.builderconfig) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
59 replacements = dict(basedir=basedir, |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
60 distribution=distribution, |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
61 mirrorsite=mirrorsite) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
62 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
63 # create the builder directories. basedir is created implicitly by |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
64 # creating its subdirectories. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
65 for attr in ["build_dir", "result_dir", "aptcache_dir", |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
66 "extra_pkg_dir"]: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
67 directory = getattr(self, attr) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
68 replacements[attr] = directory |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
69 print "creating directory:", repr(directory) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
70 util.ensure_directory(directory) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
71 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
72 # build OTHERMIRROR value. We always include the extra-pkg dir. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
73 # othermirror = "deb file://%(extra_pkg_dir)s ./" % replacements |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
74 # if extramirrors: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
75 # othermirror += " | " + extramirrors |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
76 # replacements["othermirror"] = othermirror |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
77 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
78 # turn the extra-pkg directory into a proper deb archive |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
79 print "turning the extra-pkg dir into a debian archive" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
80 self.update_extra_pkg_dir() |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
81 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
82 def update(self, suppress_output=True, log_info=True): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
83 """Runs nothing""" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
84 if log_info: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
85 logging.info("Update of apt cache is done on every start. skipping ...") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
86 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
87 def build(self, dsc_file, binary_dir=None, logfile=None, bindmounts=(), |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
88 extra_packages=(), extra_env=None): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
89 """Build a binary packager from a source package |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
90 Parameters: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
91 dsc_file -- name of the debian .dsc file of the source package |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
92 binary_dir -- name of the directory to receive the binary packages |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
93 logfile -- name of the logfile of the build |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
94 bindmounts -- Sequence of directory names that should be |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
95 bind-mounted in the builder chroot |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
96 environment |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
97 extra_packages -- Extra packages to install |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
98 extra_env -- mapping with extra environment variables to set |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
99 when runing the builder process. If builder |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
100 is started via sudo, make sure that sudo does |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
101 not remove these variables when it starts |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
102 builder |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
103 """ |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
104 args = [] |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
105 if logfile is not None: |
360 | 106 logdir = os.path.dirname(logfile) |
471
5fa4b938a939
set sbdmock rootlog to scratchlog.txt
Bjoern Ricks <bricks@intevation.de>
parents:
462
diff
changeset
|
107 args.extend(["--rootlog=scratchlog.txt"]) |
344
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
108 args.extend(["--buildlog=%s" % logfile]) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
109 args.extend(["--logdir=%s" % logdir]) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
110 if binary_dir is not None: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
111 args.extend(["--resultdir=%s" % binary_dir]) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
112 util.ensure_directory(binary_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
113 if bindmounts: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
114 self.mount(bindmounts) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
115 # for pkg in extra_packages: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
116 # args.extend(["--extrapackages", pkg]) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
117 |
360 | 118 logging.info("Mointing extra-pkg apt repository") |
344
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
119 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
120 self.mount([self.extra_pkg_dir]) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
121 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
122 logging.info("Starting build process with sbdmock ...") |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
123 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
124 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
125 cmd = cmdexpand("/usr/bin/sbdmock --cleanbuilddir" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
126 " --config=$builderconfig" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
127 # " --dbo=" # aren't build options setable in treepkg.cfg? |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
128 " -u -b $dsc @args", |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
129 builderconfig=self.builderconfig, |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
130 dsc=dsc_file, args=args) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
131 logging.debug("sbdmock cmd: %s" % cmd) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
132 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
133 try: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
134 run.call(cmd, suppress_output=True, extra_env=extra_env) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
135 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
136 # remove the source package files put into the binary directory |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
137 # by pbuilder (BR: not sure if this is necessary for sbdmock) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
138 if binary_dir is not None: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
139 for filename in os.listdir(binary_dir): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
140 if os.path.splitext(filename)[1] not in (".deb", ".changes"): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
141 os.remove(os.path.join(binary_dir, filename)) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
142 finally: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
143 # remove all mounted directories |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
144 self.umount_all() |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
145 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
146 def run_script(self, script, logfile, bindmounts=(), save_after_exec=False): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
147 """Execute a script in builder's chroot environment |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
148 Parameters: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
149 script -- A list of strings with the command line to invoke the |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
150 script |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
151 logfile -- name of the logfile of the build |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
152 bindmounts -- Sequence of directory names that should be |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
153 bind-mounted in the builder chroot |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
154 environment (optional) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
155 save_after_exec -- Boolean indicating whether the chroot |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
156 environment should be copied back so that |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
157 modifications are available in subsequent |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
158 uses of the builder instance. |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
159 """ |
361
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
160 |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
161 if not script[0]: |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
162 raise RuntimeError("No script to execute was passed") |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
163 |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
164 args = [] |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
165 if logfile is not None: |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
166 logdir = os.path.dirname(logfile) |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
167 args.extend(["--rootlog=%s" % logfile]) |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
168 args.extend(["--logdir=%s" % logdir]) |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
169 if bindmounts: |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
170 self.mount(bindmounts) |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
171 |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
172 self.mount([self.extra_pkg_dir]) |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
173 |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
174 cmd = cmdexpand("/usr/bin/sbdmock exec $script --cleanbuilddir" |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
175 " --config=$builderconfig" |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
176 # " --dbo=" # aren't build options setable in treepkg.cfg? |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
177 " -u @args", |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
178 builderconfig=self.builderconfig, |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
179 script=script[0], |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
180 args=args) |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
181 logging.debug("sbdmock cmd: %s" % cmd) |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
182 |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
183 try: |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
184 run.call(cmd, suppress_output=False) |
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
185 finally: |
461
454967511f5c
commit compress all logs patch from Sascha Teichmann
Bjoern Ricks <bricks@intevation.de>
parents:
366
diff
changeset
|
186 if logfile is not None: |
454967511f5c
commit compress all logs patch from Sascha Teichmann
Bjoern Ricks <bricks@intevation.de>
parents:
366
diff
changeset
|
187 logdir = os.path.dirname(logfile) |
361
72b39fcb6a24
sbdmock is now able to run scripts
Bjoern Ricks <bricks@intevation.de>
parents:
360
diff
changeset
|
188 self.umount_all() |
344
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
189 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
190 def login(self, bindmounts=(), save_after_login=False): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
191 """Start an interactive shell in the builder environment""" |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
192 args = [] |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
193 for mount in bindmounts: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
194 args.extend(["--bindmounts", mount]) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
195 if save_after_login: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
196 args.extend(["--save-after-login"]) |
348
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
197 |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
198 logging.info("Mointing extra-pkg apt repository") |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
199 |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
200 self.mount([self.extra_pkg_dir]) |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
201 |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
202 logging.info("Login into scratchbox...") |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
203 |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
204 |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
205 |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
206 cmd = cmdexpand("/usr/bin/sbdmock login --cleanbuilddir" |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
207 " --config=$builderconfig" |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
208 # " --dbo=" # aren't build options setable in treepkg.cfg? |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
209 " -u @args", |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
210 builderconfig=self.builderconfig, |
366
fee68f1a35e8
removed dsc file statement from login target of sbuilder
Bjoern Ricks <bricks@intevation.de>
parents:
361
diff
changeset
|
211 args=args) |
348
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
212 logging.debug("sbdmock cmd: %s" % cmd) |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
213 |
bcd01f68662c
added login feature for sbdmock
Bjoern Ricks <bricks@intevation.de>
parents:
344
diff
changeset
|
214 run.call(cmd, suppress_output=False) |
344
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
215 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
216 def mount(self, bindmounts): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
217 for mount in bindmounts: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
218 mount_dir = "/scratchbox/users/%s/%s" % (util.getuser(), mount) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
219 util.ensure_directory(mount_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
220 logging.info("Mounting %s to %s" % (mount, mount_dir)) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
221 run.call(cmdexpand("@rootcmd mount --bind $mount $mountdir", rootcmd=self.root_cmd, mount=mount, mountdir=mount_dir)) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
222 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
223 #add mountpoint to a variable to for unmounting later |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
224 self.mounted_dirs.append(mount_dir) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
225 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
226 def umount(self, mounts): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
227 for mount in mounts: |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
228 logging.info("Unmounting %s" % mount) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
229 run.call(cmdexpand("@rootcmd umount $dir", rootcmd=self.root_cmd, dir=mount)) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
230 self.mounted_dirs.remove(mount) |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
231 |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
232 def umount_all(self): |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
233 mounts = self.mounted_dirs[:] |
f06f707d9fda
merged branches/scratchbox into trunk
Bjoern Ricks <bricks@intevation.de>
parents:
diff
changeset
|
234 self.umount(mounts) |