Mercurial > treepkg > treepkg
annotate treepkg/packager.py @ 16:7c55f3879c4d
Use the new status class and report start/stop time too
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Fri, 09 Mar 2007 19:39:13 +0100 |
parents | dfd89f81e66c |
children | d5c24cfce05e 2802be410156 |
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 |
0 | 22 |
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 |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
35 def __init__(self, pkg_line, status, work_dir, src_dir, revision): |
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
36 self.pkg_line = pkg_line |
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") |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
67 self.pkg_line.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) |
97 run.call(["tar", "czf", tarballname, "-C", workdir, basedir]) | |
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 | |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
116 self.pkg_line.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 = "" | |
124 run.call(["debchange", "-c", changelog, | |
125 "-v", oldversionprefix + pkgbaseversion + "-kk1", | |
126 changemsg], | |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
127 env=self.pkg_line.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") |
133 run.call(["dpkg-source", "-b", os.path.basename(pkgbasedir), | |
134 os.path.basename(origtargz)], | |
135 cwd=os.path.dirname(pkgbasedir), | |
136 suppress_output=True, | |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
137 env=self.pkg_line.debian_environment()) |
0 | 138 |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
139 def move_source_package(self, pkgbasename): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
140 """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
|
141 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
|
142 util.ensure_directory(self.src_dir) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
143 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
|
144 if filename.startswith(pkgbasename)]: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
145 os.rename(os.path.join(self.work_dir, filename), |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
146 os.path.join(self.src_dir, filename)) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
147 |
0 | 148 def package(self): |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
149 """Creates a source package from a subversion checkout. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
150 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
151 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
|
152 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
|
153 work directory is removed. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
154 """ |
0 | 155 util.ensure_directory(self.work_dir) |
156 try: | |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
157 self.status.status = "creating_source_package" |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
158 self.do_package() |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
159 self.status.status = "source_package_created" |
0 | 160 finally: |
161 logging.info("Removing workdir %r", self.work_dir) | |
162 shutil.rmtree(self.work_dir) | |
163 | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
164 def do_package(self): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
165 """Does the work of creating a source package |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
166 This method must be overriden by derived classes. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
167 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
168 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
|
169 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
|
170 self.src_dir. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
171 """ |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
172 raise NotImplementedError |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
173 |
0 | 174 |
175 class BinaryPackager(object): | |
176 | |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
177 def __init__(self, pkg_line, status, binary_dir, dsc_file, logfile): |
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
178 self.pkg_line = pkg_line |
0 | 179 self.status = status |
180 self.binary_dir = binary_dir | |
181 self.dsc_file = dsc_file | |
182 self.logfile = logfile | |
183 | |
184 def package(self): | |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
185 self.status.status = "creating_binary_package" |
0 | 186 util.ensure_directory(self.binary_dir) |
187 logging.info("Building binary package; loging to %r", self.logfile) | |
2
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
188 cmd = ["/usr/sbin/pbuilder", "build", "--logfile", self.logfile, |
e6a9f4037f68
readconfig.py is smarter now about conversions and supports shlex
Bernhard Herzog <bh@intevation.de>
parents:
0
diff
changeset
|
189 "--buildresult", self.binary_dir, self.dsc_file] |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
190 run.call(self.pkg_line.root_cmd + cmd, suppress_output=True) |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
191 self.status.status = "binary_package_created" |
0 | 192 |
193 | |
194 class RevisionPackager(object): | |
195 | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
196 source_packager_cls = SourcePackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
197 binary_packager_cls = BinaryPackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
198 |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
199 def __init__(self, pkg_line, revision): |
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
200 self.pkg_line = pkg_line |
0 | 201 self.revision = revision |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
202 self.base_dir = self.pkg_line.pkg_dir_for_revision(self.revision, 1) |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
203 self.status = status.Status(os.path.join(self.base_dir, "status")) |
0 | 204 |
205 work_dir = _filenameproperty("work") | |
206 binary_dir = _filenameproperty("binary") | |
207 src_dir = _filenameproperty("src") | |
208 | |
209 def find_dsc_file(self): | |
210 for filename in os.listdir(self.src_dir): | |
211 if filename.endswith(".dsc"): | |
212 return os.path.join(self.src_dir, filename) | |
213 return None | |
214 | |
215 def package(self): | |
216 try: | |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
217 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
|
218 self.status.start = datetime.datetime.utcnow() |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
219 src_packager = self.source_packager_cls(self.pkg_line, self.status, |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
220 self.work_dir, self.src_dir, |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
221 self.revision) |
0 | 222 src_packager.package() |
223 | |
224 dsc_file = self.find_dsc_file() | |
225 if dsc_file is None: | |
226 raise RuntimeError("Cannot find dsc File in %r" % self.src_dir) | |
227 | |
9
16689c948bbc
Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents:
8
diff
changeset
|
228 bin_packager = self.binary_packager_cls(self.pkg_line, self.status, |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
229 self.binary_dir, dsc_file, |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
230 os.path.join(self.base_dir, |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
231 "build.log")) |
0 | 232 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
|
233 self.status.stop = datetime.datetime.utcnow() |
0 | 234 except: |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
235 self.status.status = "error" |
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
236 self.status.stop = datetime.datetime.utcnow() |
0 | 237 raise |
238 | |
239 def remove_package_dir(self): | |
240 logging.info("Removing pkgdir %r", self.base_dir) | |
241 shutil.rmtree(self.base_dir) | |
242 | |
243 | |
8
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
244 class PackageLine(object): |
0 | 245 |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
246 revision_packager_cls = RevisionPackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
247 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
248 svn_external_subdirs = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
249 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
250 extra_config_desc = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
251 |
0 | 252 def __init__(self, name, base_dir, svn_url, root_cmd, deb_email, |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
253 deb_fullname, packager_class="treepkg.packager"): |
0 | 254 self.name = name |
255 self.base_dir = base_dir | |
256 self.svn_url = svn_url | |
257 self.root_cmd = root_cmd | |
258 self.deb_email = deb_email | |
259 self.deb_fullname = deb_fullname | |
260 self.pkg_dir_template = "%(revision)d-%(increment)d" | |
261 self.pkg_dir_regex \ | |
262 = re.compile(r"(?P<revision>[0-9]+)-(?P<increment>[0-9]+)$") | |
263 | |
264 checkout_dir = _filenameproperty("checkout") | |
265 debian_dir = _filenameproperty("debian") | |
266 pkg_dir = _filenameproperty("pkg") | |
267 | |
268 def pkg_dir_for_revision(self, revision, increment): | |
269 return os.path.join(self.pkg_dir, | |
270 self.pkg_dir_template % locals()) | |
271 | |
272 def last_changed_revision(self): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
273 revisions = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
274 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
|
275 directory = os.path.join(self.checkout_dir, directory) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
276 revisions.append(subversion.last_changed_revision(directory)) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
277 return max(revisions) |
0 | 278 |
11
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
279 def get_revision_numbers(self): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
280 """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
|
281 revisions = [] |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
282 if os.path.exists(self.pkg_dir): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
283 for filename in os.listdir(self.pkg_dir): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
284 match = self.pkg_dir_regex.match(filename) |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
285 if match: |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
286 revisions.append(int(match.group("revision"))) |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
287 return revisions |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
288 |
0 | 289 def last_packaged_revision(self): |
290 """Returns the revision number of the highest packaged revision. | |
291 | |
292 If the revision cannot be determined because no already packaged | |
293 revisions can be found, the function returns -1. | |
294 """ | |
11
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
295 return max([-1] + self.get_revision_numbers()) |
0 | 296 |
297 def debian_source(self): | |
298 return util.extract_value_for_key(open(os.path.join(self.debian_dir, | |
299 "control")), | |
300 "Source:") | |
301 | |
302 def update_checkout(self): | |
303 """Updates the working copy of self.svn_url in self.checkout_dir. | |
304 | |
305 If self.checkout_dir doesn't exist yet, self.svn_url is checked | |
306 out into that directory. | |
307 """ | |
308 localdir = self.checkout_dir | |
309 if os.path.exists(localdir): | |
310 logging.info("Updating the working copy in %r", localdir) | |
311 subversion.update(localdir) | |
312 else: | |
313 logging.info("The working copy in %r doesn't exist yet." | |
314 " Checking out fromo %r", localdir, | |
315 self.svn_url) | |
316 subversion.checkout(self.svn_url, localdir) | |
317 | |
318 def export_sources(self, to_dir): | |
319 logging.info("Exporting sources for tarball to %r", to_dir) | |
320 subversion.export(self.checkout_dir, to_dir) | |
321 # some versions of svn (notably version 1.4.2 shipped with etch) | |
322 # do export externals such as the admin subdirectory. We may | |
323 # have to do that in an extra step. | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
324 for subdir in self.svn_external_subdirs: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
325 absdir = os.path.join(to_dir, subdir) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
326 if not os.path.isdir(absdir): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
327 subversion.export(os.path.join(self.checkout_dir, subdir), |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
328 absdir) |
0 | 329 |
330 def copy_debian_directory(self, to_dir): | |
331 logging.info("Copying debian directory to %r", to_dir) | |
332 shutil.copytree(self.debian_dir, to_dir) | |
333 | |
334 def debian_environment(self): | |
335 """Returns the environment variables for the debian commands""" | |
336 env = os.environ.copy() | |
337 env["DEBFULLNAME"] = self.deb_fullname | |
338 env["DEBEMAIL"] = self.deb_email | |
339 return env | |
340 | |
341 def package_if_updated(self): | |
342 """Checks if the checkout changed and returns a new packager if so""" | |
343 self.update_checkout() | |
344 current_revision = self.last_changed_revision() | |
345 logging.info("New revision is %d", current_revision) | |
346 previous_revision = self.last_packaged_revision() | |
347 logging.info("Previously packaged revision was %d", previous_revision) | |
348 if current_revision > previous_revision: | |
349 logging.info("New revision is not packaged yet") | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
350 return self.revision_packager_cls(self, current_revision) |
0 | 351 else: |
352 logging.info("New revision already packaged.") | |
353 | |
14
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
354 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
|
355 """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
|
356 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
|
357 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
|
358 |
0 | 359 |
8
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
360 def create_package_line(packager_class, **kw): |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
361 module = util.import_dotted_name(packager_class) |
8
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
362 return module.PackageLine(**kw) |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
363 |
0 | 364 |
7
96f4f58c62b5
Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents:
4
diff
changeset
|
365 class PackagerGroup(object): |
0 | 366 |
8
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
367 def __init__(self, package_lines, check_interval): |
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
368 self.package_lines = package_lines |
0 | 369 self.check_interval = check_interval |
370 | |
371 def run(self): | |
7
96f4f58c62b5
Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents:
4
diff
changeset
|
372 """Runs the packager group indefinitely""" |
96f4f58c62b5
Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents:
4
diff
changeset
|
373 logging.info("Tree packager starts. Will check every %d seconds", |
0 | 374 self.check_interval) |
375 last_check = -1 | |
376 while 1: | |
377 now = time.time() | |
378 if now > last_check + self.check_interval: | |
8
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
379 self.check_package_lines() |
0 | 380 last_check = now |
381 next_check = now + self.check_interval | |
382 to_sleep = next_check - time.time() | |
383 if to_sleep > 0: | |
384 logging.info("Next check at %s", | |
385 time.strftime("%Y-%m-%d %H:%M:%S", | |
386 time.localtime(next_check))) | |
387 time.sleep(to_sleep) | |
388 else: | |
389 logging.info("Next check now") | |
390 | |
8
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
391 def check_package_lines(self): |
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
392 logging.info("Checking package lines") |
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
393 for line in self.package_lines: |
0 | 394 try: |
395 packager = line.package_if_updated() | |
396 if packager: | |
397 packager.package() | |
398 except: | |
399 logging.exception("An error occurred while" | |
8
574506a022f6
Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents:
7
diff
changeset
|
400 " checking packager line %r", line.name) |
10
59d6055493f5
Fix typo in logging message
Bernhard Herzog <bh@intevation.de>
parents:
9
diff
changeset
|
401 logging.info("Checked all package lines") |
14
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
402 |
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
403 def get_package_lines(self): |
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
404 return self.package_lines |