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