Mercurial > treepkg > treepkg
annotate treepkg/packager.py @ 55:6b5f7f7575f6
merge
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 10 Apr 2007 12:07:39 +0200 |
parents | e1028211d34b b0014b8f6029 |
children | 9a602d8eaa60 |
rev | line source |
---|---|
0 | 1 # Copyright (C) 2007 by Intevation GmbH |
2 # Authors: | |
3 # Bernhard Herzog <bh@intevation.de> | |
4 # | |
5 # This program is free software under the GPL (>=v2) | |
6 # Read the file COPYING coming with the software for details. | |
7 | |
8 """Classes to automatically build debian packages from subversion checkouts""" | |
9 | |
10 import os | |
11 import time | |
12 import re | |
13 import logging | |
14 import shutil | |
15 import traceback | |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
16 import datetime |
0 | 17 |
18 import util | |
19 import subversion | |
20 import run | |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
21 import status |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
22 from cmdexpand import cmdexpand |
0 | 23 |
24 def _filenameproperty(relative_dir): | |
25 def get(self): | |
26 return os.path.join(self.base_dir, relative_dir) | |
27 return property(get) | |
28 | |
29 | |
30 class SourcePackager(object): | |
31 | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
32 # Derived classes must supply the package basename |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
33 pkg_basename = None |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
34 |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
35 def __init__(self, track, status, work_dir, src_dir, revision): |
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
36 self.track = track |
0 | 37 self.status = status |
38 self.work_dir = work_dir | |
39 self.src_dir = src_dir | |
40 self.revision = revision | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
41 assert(self.pkg_basename) |
0 | 42 |
43 def determine_package_version(self, directory): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
44 """Returns the version number of the new package as a string |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
45 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
46 The directory parameter is the name of the directory containing |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
47 the newly exported sources. The sources were exported with the |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
48 export_sources method. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
49 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
50 The default implementation simply returns the revision converted |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
51 to a string. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
52 """ |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
53 return str(self.revision) |
0 | 54 |
55 def export_sources(self): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
56 """Export the sources from the subversion working directory |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
57 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
58 This method first exports the sources to a temporary directory |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
59 and then renames the directory. The new name is of the form |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
60 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
61 <pkg_basename>-<version> |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
62 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
63 Where pkg_basename is the value of self.pkg_basename and version |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
64 is the return value of the determine_package_version() method. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
65 """ |
0 | 66 temp_dir = os.path.join(self.work_dir, "temp") |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
67 self.track.export_sources(temp_dir) |
0 | 68 |
69 pkgbaseversion = self.determine_package_version(temp_dir) | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
70 pkgbasedir = os.path.join(self.work_dir, |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
71 self.pkg_basename + "-" + pkgbaseversion) |
0 | 72 |
73 os.rename(temp_dir, pkgbasedir) | |
74 return pkgbaseversion, pkgbasedir | |
75 | |
76 | |
77 def update_version_numbers(self, pkgbasedir): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
78 """Updates the version numbers in the code in pkgbasedir. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
79 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
80 The default implementation does nothing. Derived classes should |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
81 override this method if necessary. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
82 """ |
0 | 83 |
84 def create_tarball(self, tarballname, workdir, basedir): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
85 """Creates a new tarball. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
86 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
87 Parameters: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
88 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
89 tarballname -- the filename of the new tarball |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
90 workdir -- The directory into which to change before running tar. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
91 (actually this is done with GNUI tar's -C option) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
92 basedir -- The basedirectory of the files that are packaged |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
93 into the tarfile. This should be a relative |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
94 filename directly in workdir. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
95 """ |
0 | 96 logging.info("Creating tarball %r", tarballname) |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
97 run.call(cmdexpand("tar czf $tarballname -C $workdir $basedir", |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
98 **locals())) |
0 | 99 |
100 def copy_debian_directory(self, pkgbasedir, pkgbaseversion, changemsg): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
101 """Copies the debian directory and updates the copy's changelog |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
102 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
103 Parameter: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
104 pkgbasedir -- The directory holding the unpacked source package |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
105 pkgbaseversion -- The version to update the changelog to |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
106 changemsg -- The message for the changelog |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
107 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
108 When determining the actual version for the new package, this |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
109 function looks at the previous version in the changelog. If it |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
110 has a prefix separated from the version number by a colon this |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
111 prefix is prepended to the pkgbaseversion parameter. Debian |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
112 uses such prefixes for the kde packages. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
113 """ |
0 | 114 debian_dir = os.path.join(pkgbasedir, "debian") |
115 changelog = os.path.join(debian_dir, "changelog") | |
116 | |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
117 self.track.copy_debian_directory(debian_dir) |
0 | 118 |
119 logging.info("Updating %r", changelog) | |
120 oldversion = util.debian_changelog_version(changelog) | |
121 if ":" in oldversion: | |
122 oldversionprefix = oldversion.split(":")[0] + ":" | |
123 else: | |
124 oldversionprefix = "" | |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
125 run.call(cmdexpand("debchange -c $changelog" |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
126 " -v ${oldversionprefix}${pkgbaseversion}-kk1" |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
127 " $changemsg", **locals()), |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
128 env=self.track.debian_environment()) |
0 | 129 |
130 | |
131 def create_source_package(self, pkgbasedir, origtargz): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
132 """Creates a new source package from pkgbasedir and origtargz""" |
0 | 133 logging.info("Creating new source package") |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
134 run.call(cmdexpand("dpkg-source -b $directory $tarball", |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
135 directory=os.path.basename(pkgbasedir), |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
136 tarball=os.path.basename(origtargz)), |
0 | 137 cwd=os.path.dirname(pkgbasedir), |
138 suppress_output=True, | |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
139 env=self.track.debian_environment()) |
0 | 140 |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
141 def move_source_package(self, pkgbasename): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
142 """Moves the new source package from the work_dir to the src_dir""" |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
143 logging.info("Moving source package to %r", self.src_dir) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
144 util.ensure_directory(self.src_dir) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
145 for filename in [filename for filename in os.listdir(self.work_dir) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
146 if filename.startswith(pkgbasename)]: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
147 os.rename(os.path.join(self.work_dir, filename), |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
148 os.path.join(self.src_dir, filename)) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
149 |
0 | 150 def package(self): |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
151 """Creates a source package from a subversion checkout. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
152 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
153 After setting up the working directory, this method calls the |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
154 do_package method to do the actual packaging. Afterwards the |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
155 work directory is removed. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
156 """ |
0 | 157 util.ensure_directory(self.work_dir) |
158 try: | |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
159 self.status.creating_source_package() |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
160 self.do_package() |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
161 self.status.source_package_created() |
0 | 162 finally: |
163 logging.info("Removing workdir %r", self.work_dir) | |
164 shutil.rmtree(self.work_dir) | |
165 | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
166 def do_package(self): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
167 """Does the work of creating a source package |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
168 This method must be overriden by derived classes. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
169 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
170 The method should do the work in self.work_dir. When the |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
171 package is done, the source package files should be in |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
172 self.src_dir. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
173 """ |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
174 raise NotImplementedError |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
175 |
0 | 176 |
177 class BinaryPackager(object): | |
178 | |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
179 def __init__(self, track, status, binary_dir, dsc_file, logfile): |
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
180 self.track = track |
0 | 181 self.status = status |
182 self.binary_dir = binary_dir | |
183 self.dsc_file = dsc_file | |
184 self.logfile = logfile | |
185 | |
186 def package(self): | |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
187 self.status.creating_binary_package() |
0 | 188 util.ensure_directory(self.binary_dir) |
54 | 189 logging.info("Building binary package; logging to %r", self.logfile) |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
190 run.call(cmdexpand("@rootcmd /usr/sbin/pbuilder build" |
51 | 191 " --configfile $pbuilderrc" |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
192 " --logfile $logfile --buildresult $bindir $dsc", |
55 | 193 rootcmd=self.track.root_cmd, |
194 pbuilderrc=self.track.pbuilderrc, | |
51 | 195 logfile=self.logfile, bindir=self.binary_dir, |
196 dsc=self.dsc_file), | |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
197 suppress_output=True) |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
198 self.status.binary_package_created() |
0 | 199 |
200 | |
201 class RevisionPackager(object): | |
202 | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
203 source_packager_cls = SourcePackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
204 binary_packager_cls = BinaryPackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
205 |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
206 def __init__(self, track, revision): |
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
207 self.track = track |
0 | 208 self.revision = revision |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
209 self.base_dir = self.track.pkg_dir_for_revision(self.revision, 1) |
36
086c68ca51d2
rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
26
diff
changeset
|
210 self.status = status.RevisionStatus(os.path.join(self.base_dir, |
086c68ca51d2
rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
26
diff
changeset
|
211 "status")) |
0 | 212 |
213 work_dir = _filenameproperty("work") | |
214 binary_dir = _filenameproperty("binary") | |
215 src_dir = _filenameproperty("src") | |
18
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
216 build_log = _filenameproperty("build.log") |
0 | 217 |
218 def find_dsc_file(self): | |
219 for filename in os.listdir(self.src_dir): | |
220 if filename.endswith(".dsc"): | |
221 return os.path.join(self.src_dir, filename) | |
222 return None | |
223 | |
18
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
224 def has_build_log(self): |
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
225 return os.path.exists(self.build_log) |
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
226 |
0 | 227 def package(self): |
228 try: | |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
229 util.ensure_directory(self.work_dir) |
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
230 self.status.start = datetime.datetime.utcnow() |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
231 src_packager = self.source_packager_cls(self.track, self.status, |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
232 self.work_dir, self.src_dir, |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
233 self.revision) |
0 | 234 src_packager.package() |
235 | |
236 dsc_file = self.find_dsc_file() | |
237 if dsc_file is None: | |
238 raise RuntimeError("Cannot find dsc File in %r" % self.src_dir) | |
239 | |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
240 bin_packager = self.binary_packager_cls(self.track, self.status, |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
241 self.binary_dir, dsc_file, |
18
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
242 self.build_log) |
0 | 243 bin_packager.package() |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
244 self.status.stop = datetime.datetime.utcnow() |
0 | 245 except: |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
246 self.status.error() |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
247 self.status.stop = datetime.datetime.utcnow() |
0 | 248 raise |
249 | |
250 def remove_package_dir(self): | |
251 logging.info("Removing pkgdir %r", self.base_dir) | |
252 shutil.rmtree(self.base_dir) | |
253 | |
254 | |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
255 class PackageTrack(object): |
0 | 256 |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
257 revision_packager_cls = RevisionPackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
258 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
259 svn_external_subdirs = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
260 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
261 extra_config_desc = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
262 |
47
2802be410156
add config options pbuilderrc and use it when calling pbuilder
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
263 def __init__(self, name, base_dir, svn_url, root_cmd, pbuilderrc, deb_email, |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
264 deb_fullname, packager_class="treepkg.packager"): |
0 | 265 self.name = name |
266 self.base_dir = base_dir | |
267 self.svn_url = svn_url | |
268 self.root_cmd = root_cmd | |
47
2802be410156
add config options pbuilderrc and use it when calling pbuilder
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
269 self.pbuilderrc = pbuilderrc |
0 | 270 self.deb_email = deb_email |
271 self.deb_fullname = deb_fullname | |
272 self.pkg_dir_template = "%(revision)d-%(increment)d" | |
273 self.pkg_dir_regex \ | |
274 = re.compile(r"(?P<revision>[0-9]+)-(?P<increment>[0-9]+)$") | |
275 | |
276 checkout_dir = _filenameproperty("checkout") | |
277 debian_dir = _filenameproperty("debian") | |
278 pkg_dir = _filenameproperty("pkg") | |
279 | |
280 def pkg_dir_for_revision(self, revision, increment): | |
281 return os.path.join(self.pkg_dir, | |
282 self.pkg_dir_template % locals()) | |
283 | |
284 def last_changed_revision(self): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
285 revisions = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
286 for directory in [self.checkout_dir] + self.svn_external_subdirs: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
287 directory = os.path.join(self.checkout_dir, directory) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
288 revisions.append(subversion.last_changed_revision(directory)) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
289 return max(revisions) |
0 | 290 |
11
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
291 def get_revision_numbers(self): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
292 """Returns a list of the numbers of the packaged revisions""" |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
293 revisions = [] |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
294 if os.path.exists(self.pkg_dir): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
295 for filename in os.listdir(self.pkg_dir): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
296 match = self.pkg_dir_regex.match(filename) |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
297 if match: |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
298 revisions.append(int(match.group("revision"))) |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
299 return revisions |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
300 |
0 | 301 def last_packaged_revision(self): |
302 """Returns the revision number of the highest packaged revision. | |
303 | |
304 If the revision cannot be determined because no already packaged | |
305 revisions can be found, the function returns -1. | |
306 """ | |
11
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
307 return max([-1] + self.get_revision_numbers()) |
0 | 308 |
309 def debian_source(self): | |
310 return util.extract_value_for_key(open(os.path.join(self.debian_dir, | |
311 "control")), | |
312 "Source:") | |
313 | |
314 def update_checkout(self): | |
315 """Updates the working copy of self.svn_url in self.checkout_dir. | |
316 | |
317 If self.checkout_dir doesn't exist yet, self.svn_url is checked | |
318 out into that directory. | |
319 """ | |
320 localdir = self.checkout_dir | |
321 if os.path.exists(localdir): | |
322 logging.info("Updating the working copy in %r", localdir) | |
323 subversion.update(localdir) | |
324 else: | |
325 logging.info("The working copy in %r doesn't exist yet." | |
26 | 326 " Checking out from %r", localdir, |
0 | 327 self.svn_url) |
328 subversion.checkout(self.svn_url, localdir) | |
329 | |
330 def export_sources(self, to_dir): | |
331 logging.info("Exporting sources for tarball to %r", to_dir) | |
332 subversion.export(self.checkout_dir, to_dir) | |
333 # some versions of svn (notably version 1.4.2 shipped with etch) | |
334 # do export externals such as the admin subdirectory. We may | |
335 # have to do that in an extra step. | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
336 for subdir in self.svn_external_subdirs: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
337 absdir = os.path.join(to_dir, subdir) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
338 if not os.path.isdir(absdir): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
339 subversion.export(os.path.join(self.checkout_dir, subdir), |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
340 absdir) |
0 | 341 |
342 def copy_debian_directory(self, to_dir): | |
343 logging.info("Copying debian directory to %r", to_dir) | |
344 shutil.copytree(self.debian_dir, to_dir) | |
345 | |
346 def debian_environment(self): | |
347 """Returns the environment variables for the debian commands""" | |
348 env = os.environ.copy() | |
349 env["DEBFULLNAME"] = self.deb_fullname | |
350 env["DEBEMAIL"] = self.deb_email | |
351 return env | |
352 | |
353 def package_if_updated(self): | |
354 """Checks if the checkout changed and returns a new packager if so""" | |
355 self.update_checkout() | |
356 current_revision = self.last_changed_revision() | |
357 logging.info("New revision is %d", current_revision) | |
358 previous_revision = self.last_packaged_revision() | |
359 logging.info("Previously packaged revision was %d", previous_revision) | |
360 if current_revision > previous_revision: | |
361 logging.info("New revision is not packaged yet") | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
362 return self.revision_packager_cls(self, current_revision) |
0 | 363 else: |
364 logging.info("New revision already packaged.") | |
365 | |
14
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
366 def get_revisions(self): |
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
367 """Returns RevisionPackager objects for each packaged revision""" |
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
368 return [self.revision_packager_cls(self, revision) |
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
369 for revision in self.get_revision_numbers()] |
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
370 |
0 | 371 |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
372 def create_package_track(packager_class, **kw): |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
373 module = util.import_dotted_name(packager_class) |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
374 return module.PackageTrack(**kw) |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
375 |
0 | 376 |
7
96f4f58c62b5
Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents:
4
diff
changeset
|
377 class PackagerGroup(object): |
0 | 378 |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
379 def __init__(self, package_tracks, check_interval): |
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
380 self.package_tracks = package_tracks |
0 | 381 self.check_interval = check_interval |
382 | |
383 def run(self): | |
7
96f4f58c62b5
Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents:
4
diff
changeset
|
384 """Runs the packager group indefinitely""" |
96f4f58c62b5
Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents:
4
diff
changeset
|
385 logging.info("Tree packager starts. Will check every %d seconds", |
0 | 386 self.check_interval) |
387 last_check = -1 | |
388 while 1: | |
389 now = time.time() | |
390 if now > last_check + self.check_interval: | |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
391 self.check_package_tracks() |
0 | 392 last_check = now |
393 next_check = now + self.check_interval | |
394 to_sleep = next_check - time.time() | |
395 if to_sleep > 0: | |
396 logging.info("Next check at %s", | |
397 time.strftime("%Y-%m-%d %H:%M:%S", | |
398 time.localtime(next_check))) | |
399 time.sleep(to_sleep) | |
400 else: | |
401 logging.info("Next check now") | |
402 | |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
403 def check_package_tracks(self): |
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
404 logging.info("Checking package tracks") |
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
405 for track in self.package_tracks: |
0 | 406 try: |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
407 packager = track.package_if_updated() |
0 | 408 if packager: |
409 packager.package() | |
410 except: | |
411 logging.exception("An error occurred while" | |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
412 " checking packager track %r", track.name) |
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
413 logging.info("Checked all package tracks") |
14
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
414 |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
415 def get_package_tracks(self): |
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
416 return self.package_tracks |