Mercurial > treepkg > treepkg
annotate treepkg/packager.py @ 112:cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Use this class in treepkg.packager.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 20 Mar 2008 20:21:34 +0000 |
parents | 66cbfc772f84 |
children | 312949e7628d |
rev | line source |
---|---|
99
7888fe374e11
Add support for notification mails in case of build errors
Bernhard Herzog <bh@intevation.de>
parents:
98
diff
changeset
|
1 # Copyright (C) 2007, 2008 by Intevation GmbH |
0 | 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 |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
106
diff
changeset
|
22 from builder import PBuilder |
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 = "" | |
93
73c67372c7f7
Make the prefix used in the debian revision number configurable.
Bernhard Herzog <bh@intevation.de>
parents:
91
diff
changeset
|
125 debrev = self.track.debrevision_prefix + "1" |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
126 run.call(cmdexpand("debchange -c $changelog" |
93
73c67372c7f7
Make the prefix used in the debian revision number configurable.
Bernhard Herzog <bh@intevation.de>
parents:
91
diff
changeset
|
127 " -v ${oldversionprefix}${pkgbaseversion}-${debrev}" |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
128 " $changemsg", **locals()), |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
129 env=self.track.debian_environment()) |
0 | 130 |
131 | |
132 def create_source_package(self, pkgbasedir, origtargz): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
133 """Creates a new source package from pkgbasedir and origtargz""" |
0 | 134 logging.info("Creating new source package") |
45
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
135 run.call(cmdexpand("dpkg-source -b $directory $tarball", |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
136 directory=os.path.basename(pkgbasedir), |
3e610233ccfe
use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents:
41
diff
changeset
|
137 tarball=os.path.basename(origtargz)), |
0 | 138 cwd=os.path.dirname(pkgbasedir), |
139 suppress_output=True, | |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
140 env=self.track.debian_environment()) |
0 | 141 |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
142 def move_source_package(self, pkgbasename): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
143 """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
|
144 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
|
145 util.ensure_directory(self.src_dir) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
146 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
|
147 if filename.startswith(pkgbasename)]: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
148 os.rename(os.path.join(self.work_dir, filename), |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
149 os.path.join(self.src_dir, filename)) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
150 |
0 | 151 def package(self): |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
152 """Creates a source package from a subversion checkout. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
153 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
154 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
|
155 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
|
156 work directory is removed. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
157 """ |
0 | 158 util.ensure_directory(self.work_dir) |
159 try: | |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
160 self.status.creating_source_package() |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
161 self.do_package() |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
162 self.status.source_package_created() |
0 | 163 finally: |
164 logging.info("Removing workdir %r", self.work_dir) | |
165 shutil.rmtree(self.work_dir) | |
166 | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
167 def do_package(self): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
168 """Does the work of creating a source package |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
169 This method must be overriden by derived classes. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
170 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
171 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
|
172 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
|
173 self.src_dir. |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
174 """ |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
175 raise NotImplementedError |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
176 |
0 | 177 |
178 class BinaryPackager(object): | |
179 | |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
180 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
|
181 self.track = track |
0 | 182 self.status = status |
183 self.binary_dir = binary_dir | |
184 self.dsc_file = dsc_file | |
185 self.logfile = logfile | |
186 | |
187 def package(self): | |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
188 self.status.creating_binary_package() |
0 | 189 util.ensure_directory(self.binary_dir) |
54 | 190 logging.info("Building binary package; logging to %r", self.logfile) |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
106
diff
changeset
|
191 self.track.builder.build(self.dsc_file, self.binary_dir, self.logfile) |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
192 self.status.binary_package_created() |
0 | 193 |
194 | |
195 class RevisionPackager(object): | |
196 | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
197 source_packager_cls = SourcePackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
198 binary_packager_cls = BinaryPackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
199 |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
200 def __init__(self, track, revision): |
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
201 self.track = track |
0 | 202 self.revision = revision |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
203 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
|
204 self.status = status.RevisionStatus(os.path.join(self.base_dir, |
086c68ca51d2
rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
26
diff
changeset
|
205 "status")) |
0 | 206 |
207 work_dir = _filenameproperty("work") | |
208 binary_dir = _filenameproperty("binary") | |
209 src_dir = _filenameproperty("src") | |
18
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
210 build_log = _filenameproperty("build.log") |
0 | 211 |
212 def find_dsc_file(self): | |
213 for filename in os.listdir(self.src_dir): | |
214 if filename.endswith(".dsc"): | |
215 return os.path.join(self.src_dir, filename) | |
216 return None | |
217 | |
18
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
218 def has_build_log(self): |
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
219 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
|
220 |
88
3ae54f99db26
Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents:
85
diff
changeset
|
221 def list_source_files(self): |
3ae54f99db26
Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents:
85
diff
changeset
|
222 """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
|
223 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
|
224 to the source package. |
3ae54f99db26
Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents:
85
diff
changeset
|
225 """ |
3ae54f99db26
Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents:
85
diff
changeset
|
226 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
|
227 |
3ae54f99db26
Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents:
85
diff
changeset
|
228 def list_binary_files(self): |
3ae54f99db26
Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents:
85
diff
changeset
|
229 """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
|
230 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
|
231 to the binary packages. |
3ae54f99db26
Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents:
85
diff
changeset
|
232 """ |
3ae54f99db26
Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents:
85
diff
changeset
|
233 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
|
234 |
0 | 235 def package(self): |
236 try: | |
16
7c55f3879c4d
Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents:
14
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 self.work_dir, self.src_dir, |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
241 self.revision) |
0 | 242 src_packager.package() |
243 | |
244 dsc_file = self.find_dsc_file() | |
245 if dsc_file is None: | |
246 raise RuntimeError("Cannot find dsc File in %r" % self.src_dir) | |
247 | |
53
74cd21b6400b
rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents:
52
diff
changeset
|
248 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
|
249 self.binary_dir, dsc_file, |
18
d5c24cfce05e
Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
250 self.build_log) |
0 | 251 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
|
252 self.status.stop = datetime.datetime.utcnow() |
0 | 253 except: |
41
f7ec40638a06
use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents:
36
diff
changeset
|
254 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
|
255 self.status.stop = datetime.datetime.utcnow() |
99
7888fe374e11
Add support for notification mails in case of build errors
Bernhard Herzog <bh@intevation.de>
parents:
98
diff
changeset
|
256 # set the notification status last to avoid race conditions. |
7888fe374e11
Add support for notification mails in case of build errors
Bernhard Herzog <bh@intevation.de>
parents:
98
diff
changeset
|
257 # The pending notification is for now the only situation |
7888fe374e11
Add support for notification mails in case of build errors
Bernhard Herzog <bh@intevation.de>
parents:
98
diff
changeset
|
258 # where another process might modify the status file (the |
7888fe374e11
Add support for notification mails in case of build errors
Bernhard Herzog <bh@intevation.de>
parents:
98
diff
changeset
|
259 # listpendingnotifications program will set it to |
7888fe374e11
Add support for notification mails in case of build errors
Bernhard Herzog <bh@intevation.de>
parents:
98
diff
changeset
|
260 # "notification_sent") |
7888fe374e11
Add support for notification mails in case of build errors
Bernhard Herzog <bh@intevation.de>
parents:
98
diff
changeset
|
261 self.status.notification_pending() |
0 | 262 raise |
263 | |
264 def remove_package_dir(self): | |
265 logging.info("Removing pkgdir %r", self.base_dir) | |
266 shutil.rmtree(self.base_dir) | |
267 | |
268 | |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
269 class PackageTrack(object): |
0 | 270 |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
271 revision_packager_cls = RevisionPackager |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
272 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
273 svn_external_subdirs = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
274 |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
275 extra_config_desc = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
276 |
47
2802be410156
add config options pbuilderrc and use it when calling pbuilder
Bernhard Herzog <bh@intevation.de>
parents:
16
diff
changeset
|
277 def __init__(self, name, base_dir, svn_url, root_cmd, pbuilderrc, deb_email, |
93
73c67372c7f7
Make the prefix used in the debian revision number configurable.
Bernhard Herzog <bh@intevation.de>
parents:
91
diff
changeset
|
278 deb_fullname, packager_class="treepkg.packager", |
73c67372c7f7
Make the prefix used in the debian revision number configurable.
Bernhard Herzog <bh@intevation.de>
parents:
91
diff
changeset
|
279 debrevision_prefix="treepkg"): |
0 | 280 self.name = name |
281 self.base_dir = base_dir | |
282 self.svn_url = svn_url | |
112
cea98d4e4a6a
Abstract the pbuilder calls into the new class treepkg.builder.PBuilder.
Bernhard Herzog <bh@intevation.de>
parents:
106
diff
changeset
|
283 self.builder = PBuilder(pbuilderrc, root_cmd) |
0 | 284 self.deb_email = deb_email |
285 self.deb_fullname = deb_fullname | |
93
73c67372c7f7
Make the prefix used in the debian revision number configurable.
Bernhard Herzog <bh@intevation.de>
parents:
91
diff
changeset
|
286 self.debrevision_prefix = debrevision_prefix |
0 | 287 self.pkg_dir_template = "%(revision)d-%(increment)d" |
288 self.pkg_dir_regex \ | |
289 = re.compile(r"(?P<revision>[0-9]+)-(?P<increment>[0-9]+)$") | |
290 | |
291 checkout_dir = _filenameproperty("checkout") | |
292 debian_dir = _filenameproperty("debian") | |
293 pkg_dir = _filenameproperty("pkg") | |
294 | |
106
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
295 def init_treepkg(self): |
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
296 print "Initializing", self.name |
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
297 if not os.path.exists(self.base_dir): |
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
298 print "creating %s" % (self.base_dir,) |
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
299 util.ensure_directory(self.base_dir) |
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
300 if not os.path.exists(self.debian_dir): |
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
301 print ("TODO: the debian directory %s still has to be created" |
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
302 % (self.debian_dir,)) |
66cbfc772f84
Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents:
99
diff
changeset
|
303 |
0 | 304 def pkg_dir_for_revision(self, revision, increment): |
305 return os.path.join(self.pkg_dir, | |
306 self.pkg_dir_template % locals()) | |
307 | |
308 def last_changed_revision(self): | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
309 revisions = [] |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
310 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
|
311 directory = os.path.join(self.checkout_dir, directory) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
312 revisions.append(subversion.last_changed_revision(directory)) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
313 return max(revisions) |
0 | 314 |
11
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
315 def get_revision_numbers(self): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
316 """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
|
317 revisions = [] |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
318 if os.path.exists(self.pkg_dir): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
319 for filename in os.listdir(self.pkg_dir): |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
320 match = self.pkg_dir_regex.match(filename) |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
321 if match: |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
322 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
|
323 revisions.sort() |
11
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
324 return revisions |
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
325 |
0 | 326 def last_packaged_revision(self): |
327 """Returns the revision number of the highest packaged revision. | |
328 | |
329 If the revision cannot be determined because no already packaged | |
330 revisions can be found, the function returns -1. | |
331 """ | |
11
6efe0bd3d8c1
Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents:
10
diff
changeset
|
332 return max([-1] + self.get_revision_numbers()) |
0 | 333 |
334 def debian_source(self): | |
335 return util.extract_value_for_key(open(os.path.join(self.debian_dir, | |
336 "control")), | |
337 "Source:") | |
338 | |
80
0af2fa3790e0
Add revision parameter to PackagerGroup.__init__ and some other methods
Bernhard Herzog <bh@intevation.de>
parents:
78
diff
changeset
|
339 def update_checkout(self, revision=None): |
0 | 340 """Updates the working copy of self.svn_url in self.checkout_dir. |
341 | |
342 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
|
343 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
|
344 passed through to subversion.update. |
0 | 345 """ |
346 localdir = self.checkout_dir | |
347 if os.path.exists(localdir): | |
348 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
|
349 subversion.update(localdir, revision=revision) |
0 | 350 else: |
351 logging.info("The working copy in %r doesn't exist yet." | |
26 | 352 " Checking out from %r", localdir, |
0 | 353 self.svn_url) |
354 subversion.checkout(self.svn_url, localdir) | |
355 | |
356 def export_sources(self, to_dir): | |
357 logging.info("Exporting sources for tarball to %r", to_dir) | |
358 subversion.export(self.checkout_dir, to_dir) | |
359 # some versions of svn (notably version 1.4.2 shipped with etch) | |
360 # do export externals such as the admin subdirectory. We may | |
361 # have to do that in an extra step. | |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
362 for subdir in self.svn_external_subdirs: |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
363 absdir = os.path.join(to_dir, subdir) |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
364 if not os.path.isdir(absdir): |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
365 subversion.export(os.path.join(self.checkout_dir, subdir), |
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
366 absdir) |
0 | 367 |
368 def copy_debian_directory(self, to_dir): | |
369 logging.info("Copying debian directory to %r", to_dir) | |
370 shutil.copytree(self.debian_dir, to_dir) | |
371 | |
372 def debian_environment(self): | |
373 """Returns the environment variables for the debian commands""" | |
374 env = os.environ.copy() | |
375 env["DEBFULLNAME"] = self.deb_fullname | |
376 env["DEBEMAIL"] = self.deb_email | |
377 return env | |
378 | |
80
0af2fa3790e0
Add revision parameter to PackagerGroup.__init__ and some other methods
Bernhard Herzog <bh@intevation.de>
parents:
78
diff
changeset
|
379 def package_if_updated(self, revision=None): |
0 | 380 """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
|
381 self.update_checkout(revision=revision) |
0 | 382 current_revision = self.last_changed_revision() |
383 logging.info("New revision is %d", current_revision) | |
98
f7b9c7113c46
Make packaging a specific revision work even if newer revisions have already
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
384 if current_revision not in self.get_revision_numbers(): |
f7b9c7113c46
Make packaging a specific revision work even if newer revisions have already
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
385 logging.info("Revision %d has not been packaged yet", |
f7b9c7113c46
Make packaging a specific revision work even if newer revisions have already
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
386 current_revision) |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
387 return self.revision_packager_cls(self, current_revision) |
0 | 388 else: |
98
f7b9c7113c46
Make packaging a specific revision work even if newer revisions have already
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
389 logging.info("Revision %d has already been packaged.", |
f7b9c7113c46
Make packaging a specific revision work even if newer revisions have already
Bernhard Herzog <bh@intevation.de>
parents:
93
diff
changeset
|
390 current_revision) |
0 | 391 |
14
dfd89f81e66c
Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents:
11
diff
changeset
|
392 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
|
393 """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
|
394 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
|
395 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
|
396 |
0 | 397 |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
398 def create_package_track(packager_class, **kw): |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
399 module = util.import_dotted_name(packager_class) |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
400 return module.PackageTrack(**kw) |
4
fee641fec94e
Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents:
2
diff
changeset
|
401 |
0 | 402 |
7
96f4f58c62b5
Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents:
4
diff
changeset
|
403 class PackagerGroup(object): |
0 | 404 |
91
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
405 def __init__(self, package_tracks, check_interval, revision=None, |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
406 instructions_file=None): |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
407 self.package_tracks = package_tracks |
0 | 408 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
|
409 self.revision = revision |
91
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
410 self.instructions_file = instructions_file |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
411 self.instructions_file_removed = False |
0 | 412 |
413 def run(self): | |
7
96f4f58c62b5
Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents:
4
diff
changeset
|
414 """Runs the packager group indefinitely""" |
78
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
55
diff
changeset
|
415 logging.info("Starting in periodic check mode." |
9a602d8eaa60
initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents:
55
diff
changeset
|
416 " Will check every %d seconds", self.check_interval) |
0 | 417 last_check = -1 |
418 while 1: | |
419 now = time.time() | |
420 if now > last_check + self.check_interval: | |
91
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
421 if self.check_package_tracks(): |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
422 break |
0 | 423 last_check = now |
424 next_check = now + self.check_interval | |
425 to_sleep = next_check - time.time() | |
426 if to_sleep > 0: | |
427 logging.info("Next check at %s", | |
428 time.strftime("%Y-%m-%d %H:%M:%S", | |
429 time.localtime(next_check))) | |
430 time.sleep(to_sleep) | |
431 else: | |
432 logging.info("Next check now") | |
91
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
433 if self.should_stop(): |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
434 logging.info("Received stop instruction. Stopping.") |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
435 return |
0 | 436 |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
437 def check_package_tracks(self): |
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
438 logging.info("Checking package tracks") |
91
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
439 self.clear_instruction() |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
440 for track in self.package_tracks: |
0 | 441 try: |
80
0af2fa3790e0
Add revision parameter to PackagerGroup.__init__ and some other methods
Bernhard Herzog <bh@intevation.de>
parents:
78
diff
changeset
|
442 packager = track.package_if_updated(revision=self.revision) |
0 | 443 if packager: |
444 packager.package() | |
91
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
445 if self.should_stop(): |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
446 logging.info("Received stop instruction. Stopping.") |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
447 return True |
0 | 448 except: |
449 logging.exception("An error occurred while" | |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
450 " checking packager track %r", track.name) |
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
451 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
|
452 |
52
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
453 def get_package_tracks(self): |
78cf5f6778ec
Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents:
49
diff
changeset
|
454 return self.package_tracks |
91
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
455 |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
456 def read_instruction(self): |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
457 if not self.instructions_file: |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
458 return "" |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
459 try: |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
460 f = open(self.instructions_file) |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
461 except (IOError, OSError): |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
462 return "" |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
463 try: |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
464 return f.read().strip() |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
465 finally: |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
466 f.close() |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
467 self.clear_instruction() |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
468 |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
469 def clear_instruction(self, force=False): |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
470 if self.instructions_file and (not self.instructions_file_removed |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
471 or force): |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
472 util.writefile(self.instructions_file, "") |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
473 self.instructions_file_removed = True |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
474 |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
475 def should_stop(self): |
3ed079a7174a
Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents:
90
diff
changeset
|
476 return self.read_instruction() == "stop" |