Mercurial > treepkg > treepkg
annotate treepkg/builder.py @ 112:cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Use this class in treepkg.packager.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 20 Mar 2008 20:21:34 +0000 |
parents | |
children | 92116333ef77 |
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 |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
10 import os |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
11 |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
12 import util |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
13 import run |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
14 from cmdexpand import cmdexpand |
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 |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
17 class PBuilder(object): |
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 """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
|
20 |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
21 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
|
22 """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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 worry about quoting. |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
28 """ |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
29 self.pbuilderrc = pbuilderrc |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
30 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
|
31 |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
32 def build(self, dsc_file, binary_dir, logfile): |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
33 """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
|
34 Parameters: |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
35 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
|
36 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
|
37 logfile -- name of the logfile of the build |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
38 """ |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
39 util.ensure_directory(binary_dir) |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
40 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build" |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
41 " --configfile $pbuilderrc" |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
42 " --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
|
43 rootcmd=self.root_cmd, pbuilderrc=self.pbuilderrc, |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
44 logfile=logfile, bindir=binary_dir, dsc=dsc_file), |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
45 suppress_output=True) |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
46 # 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
|
47 # by pbuilder |
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
48 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
|
49 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
|
50 os.remove(os.path.join(binary_dir, filename)) |