annotate treepkg/packager.py @ 10:59d6055493f5

Fix typo in logging message
author Bernhard Herzog <bh@intevation.de>
date Fri, 09 Mar 2007 15:03:20 +0100
parents 16689c948bbc
children 6efe0bd3d8c1
rev   line source
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2007 by Intevation GmbH
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
2 # Authors:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
3 # Bernhard Herzog <bh@intevation.de>
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
4 #
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
7
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
8 """Classes to automatically build debian packages from subversion checkouts"""
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
9
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
10 import os
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
11 import time
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
12 import re
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
13 import logging
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
14 import shutil
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
15 import traceback
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
16
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
17 import util
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
18 import subversion
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
19 import run
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
20
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
21
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
22 def _filenameproperty(relative_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
23 def get(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
24 return os.path.join(self.base_dir, relative_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
25 return property(get)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
26
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
27
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
28 class SourcePackager(object):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
29
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
30 # Derived classes must supply the package basename
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
31 pkg_basename = None
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
32
9
16689c948bbc Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
33 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
34 self.pkg_line = pkg_line
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
35 self.status = status
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
36 self.work_dir = work_dir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
37 self.src_dir = src_dir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
38 self.revision = revision
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
39 assert(self.pkg_basename)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
40
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
41 def determine_package_version(self, directory):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
42 """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
43
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
44 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
45 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
46 export_sources method.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
47
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
48 The default implementation simply returns the revision converted
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
49 to a string.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
50 """
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
51 return str(self.revision)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
52
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
53 def export_sources(self):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
54 """Export the sources from the subversion working directory
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
55
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
56 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
57 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
58
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
59 <pkg_basename>-<version>
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 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
62 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
63 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
64 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
65 self.pkg_line.export_sources(temp_dir)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
66
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
67 pkgbaseversion = self.determine_package_version(temp_dir)
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
68 pkgbasedir = os.path.join(self.work_dir,
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
69 self.pkg_basename + "-" + pkgbaseversion)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
70
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
71 os.rename(temp_dir, pkgbasedir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
72 return pkgbaseversion, pkgbasedir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
73
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
74
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
75 def update_version_numbers(self, pkgbasedir):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
76 """Updates the version numbers in the code in pkgbasedir.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
77
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
78 The default implementation does nothing. Derived classes should
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
79 override this method if necessary.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
80 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
81
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
82 def create_tarball(self, tarballname, workdir, basedir):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
83 """Creates a new tarball.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
84
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
85 Parameters:
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 tarballname -- the filename of the new tarball
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
88 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
89 (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
90 basedir -- The basedirectory of the files that are packaged
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
91 into the tarfile. This should be a relative
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
92 filename directly in workdir.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
93 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
94 logging.info("Creating tarball %r", tarballname)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
95 run.call(["tar", "czf", tarballname, "-C", workdir, basedir])
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
96
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
97 def copy_debian_directory(self, pkgbasedir, pkgbaseversion, changemsg):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
98 """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
99
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
100 Parameter:
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
101 pkgbasedir -- The directory holding the unpacked source package
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
102 pkgbaseversion -- The version to update the changelog to
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
103 changemsg -- The message for the changelog
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
104
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
105 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
106 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
107 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
108 prefix is prepended to the pkgbaseversion parameter. Debian
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
109 uses such prefixes for the kde packages.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
110 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
111 debian_dir = os.path.join(pkgbasedir, "debian")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
112 changelog = os.path.join(debian_dir, "changelog")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
113
9
16689c948bbc Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
114 self.pkg_line.copy_debian_directory(debian_dir)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
115
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
116 logging.info("Updating %r", changelog)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
117 oldversion = util.debian_changelog_version(changelog)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
118 if ":" in oldversion:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
119 oldversionprefix = oldversion.split(":")[0] + ":"
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
120 else:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
121 oldversionprefix = ""
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
122 run.call(["debchange", "-c", changelog,
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
123 "-v", oldversionprefix + pkgbaseversion + "-kk1",
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
124 changemsg],
9
16689c948bbc Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
125 env=self.pkg_line.debian_environment())
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
126
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
127
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
128 def create_source_package(self, pkgbasedir, origtargz):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
129 """Creates a new source package from pkgbasedir and origtargz"""
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
130 logging.info("Creating new source package")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
131 run.call(["dpkg-source", "-b", os.path.basename(pkgbasedir),
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
132 os.path.basename(origtargz)],
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
133 cwd=os.path.dirname(pkgbasedir),
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
134 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
135 env=self.pkg_line.debian_environment())
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
136
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
137 def move_source_package(self, pkgbasename):
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
138 """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
139 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
140 util.ensure_directory(self.src_dir)
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
141 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
142 if filename.startswith(pkgbasename)]:
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
143 os.rename(os.path.join(self.work_dir, filename),
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
144 os.path.join(self.src_dir, filename))
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
145
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
146 def package(self):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
147 """Creates a source package from a subversion checkout.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
148
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
149 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
150 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
151 work directory is removed.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
152 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
153 util.ensure_directory(self.work_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
154 try:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
155 self.status.set("creating_source_package")
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
156 self.do_package()
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
157 self.status.set("source_package_created")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
158 finally:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
159 logging.info("Removing workdir %r", self.work_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
160 shutil.rmtree(self.work_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
161
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
162 def do_package(self):
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
163 """Does the work of creating a source package
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
164 This method must be overriden by derived classes.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
165
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
166 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
167 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
168 self.src_dir.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
169 """
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
170 raise NotImplementedError
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
171
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
172
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
173 class BinaryPackager(object):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
174
9
16689c948bbc Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
175 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
176 self.pkg_line = pkg_line
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
177 self.status = status
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
178 self.binary_dir = binary_dir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
179 self.dsc_file = dsc_file
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
180 self.logfile = logfile
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
181
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
182 def package(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
183 self.status.set("creating_binary_package")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
184 util.ensure_directory(self.binary_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
185 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
186 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
187 "--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
188 run.call(self.pkg_line.root_cmd + cmd, suppress_output=True)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
189 self.status.set("binary_package_created")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
190
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
191
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
192 class RevisionPackager(object):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
193
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
194 source_packager_cls = SourcePackager
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
195 binary_packager_cls = BinaryPackager
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
196
9
16689c948bbc Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
197 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
198 self.pkg_line = pkg_line
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
199 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
200 self.base_dir = self.pkg_line.pkg_dir_for_revision(self.revision, 1)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
201 self.status = util.StatusFile(os.path.join(self.base_dir, "status"))
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
202
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
203 work_dir = _filenameproperty("work")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
204 binary_dir = _filenameproperty("binary")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
205 src_dir = _filenameproperty("src")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
206
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
207 def find_dsc_file(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
208 for filename in os.listdir(self.src_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
209 if filename.endswith(".dsc"):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
210 return os.path.join(self.src_dir, filename)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
211 return None
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
212
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
213 def package(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
214 try:
9
16689c948bbc Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
215 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
216 self.work_dir, self.src_dir,
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
217 self.revision)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
218 src_packager.package()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
219
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
220 dsc_file = self.find_dsc_file()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
221 if dsc_file is None:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
222 raise RuntimeError("Cannot find dsc File in %r" % self.src_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
223
9
16689c948bbc Rename the instance variable plant to pkg_line in some classes
Bernhard Herzog <bh@intevation.de>
parents: 8
diff changeset
224 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
225 self.binary_dir, dsc_file,
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
226 os.path.join(self.base_dir,
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
227 "build.log"))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
228 bin_packager.package()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
229 except:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
230 self.status.set("failed", traceback.format_exc())
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
231 raise
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
232
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
233 def remove_package_dir(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
234 logging.info("Removing pkgdir %r", self.base_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
235 shutil.rmtree(self.base_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
236
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
237
8
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
238 class PackageLine(object):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
239
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
240 revision_packager_cls = RevisionPackager
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
241
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
242 svn_external_subdirs = []
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
243
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
244 extra_config_desc = []
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
245
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
246 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
247 deb_fullname, packager_class="treepkg.packager"):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
248 self.name = name
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
249 self.base_dir = base_dir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
250 self.svn_url = svn_url
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
251 self.root_cmd = root_cmd
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
252 self.deb_email = deb_email
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
253 self.deb_fullname = deb_fullname
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
254 self.pkg_dir_template = "%(revision)d-%(increment)d"
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
255 self.pkg_dir_regex \
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
256 = re.compile(r"(?P<revision>[0-9]+)-(?P<increment>[0-9]+)$")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
257
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
258 checkout_dir = _filenameproperty("checkout")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
259 debian_dir = _filenameproperty("debian")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
260 pkg_dir = _filenameproperty("pkg")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
261
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
262 def pkg_dir_for_revision(self, revision, increment):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
263 return os.path.join(self.pkg_dir,
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
264 self.pkg_dir_template % locals())
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
265
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
266 def last_changed_revision(self):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
267 revisions = []
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
268 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
269 directory = os.path.join(self.checkout_dir, directory)
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
270 revisions.append(subversion.last_changed_revision(directory))
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
271 return max(revisions)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
272
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
273 def last_packaged_revision(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
274 """Returns the revision number of the highest packaged revision.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
275
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
276 If the revision cannot be determined because no already packaged
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
277 revisions can be found, the function returns -1.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
278 """
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
279 revisions = [-1]
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
280 if os.path.exists(self.pkg_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
281 for filename in os.listdir(self.pkg_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
282 match = self.pkg_dir_regex.match(filename)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
283 if match:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
284 revisions.append(int(match.group("revision")))
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
285 return max(revisions)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
286
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
287 def debian_source(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
288 return util.extract_value_for_key(open(os.path.join(self.debian_dir,
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
289 "control")),
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
290 "Source:")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
291
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
292 def update_checkout(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
293 """Updates the working copy of self.svn_url in self.checkout_dir.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
294
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
295 If self.checkout_dir doesn't exist yet, self.svn_url is checked
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
296 out into that directory.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
297 """
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
298 localdir = self.checkout_dir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
299 if os.path.exists(localdir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
300 logging.info("Updating the working copy in %r", localdir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
301 subversion.update(localdir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
302 else:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
303 logging.info("The working copy in %r doesn't exist yet."
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
304 " Checking out fromo %r", localdir,
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
305 self.svn_url)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
306 subversion.checkout(self.svn_url, localdir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
307
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
308 def export_sources(self, to_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
309 logging.info("Exporting sources for tarball to %r", to_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
310 subversion.export(self.checkout_dir, to_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
311 # some versions of svn (notably version 1.4.2 shipped with etch)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
312 # do export externals such as the admin subdirectory. We may
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
313 # have to do that in an extra step.
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
314 for subdir in self.svn_external_subdirs:
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
315 absdir = os.path.join(to_dir, subdir)
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
316 if not os.path.isdir(absdir):
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
317 subversion.export(os.path.join(self.checkout_dir, subdir),
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
318 absdir)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
319
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
320 def copy_debian_directory(self, to_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
321 logging.info("Copying debian directory to %r", to_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
322 shutil.copytree(self.debian_dir, to_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
323
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
324 def debian_environment(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
325 """Returns the environment variables for the debian commands"""
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
326 env = os.environ.copy()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
327 env["DEBFULLNAME"] = self.deb_fullname
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
328 env["DEBEMAIL"] = self.deb_email
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
329 return env
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
330
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
331 def package_if_updated(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
332 """Checks if the checkout changed and returns a new packager if so"""
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
333 self.update_checkout()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
334 current_revision = self.last_changed_revision()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
335 logging.info("New revision is %d", current_revision)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
336 previous_revision = self.last_packaged_revision()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
337 logging.info("Previously packaged revision was %d", previous_revision)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
338 if current_revision > previous_revision:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
339 logging.info("New revision is not packaged yet")
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
340 return self.revision_packager_cls(self, current_revision)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
341 else:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
342 logging.info("New revision already packaged.")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
343
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
344
8
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
345 def create_package_line(packager_class, **kw):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
346 module = util.import_dotted_name(packager_class)
8
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
347 return module.PackageLine(**kw)
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
348
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
349
7
96f4f58c62b5 Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents: 4
diff changeset
350 class PackagerGroup(object):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
351
8
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
352 def __init__(self, package_lines, check_interval):
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
353 self.package_lines = package_lines
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
354 self.check_interval = check_interval
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
355
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
356 def run(self):
7
96f4f58c62b5 Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents: 4
diff changeset
357 """Runs the packager group indefinitely"""
96f4f58c62b5 Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents: 4
diff changeset
358 logging.info("Tree packager starts. Will check every %d seconds",
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
359 self.check_interval)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
360 last_check = -1
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
361 while 1:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
362 now = time.time()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
363 if now > last_check + self.check_interval:
8
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
364 self.check_package_lines()
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
365 last_check = now
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
366 next_check = now + self.check_interval
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
367 to_sleep = next_check - time.time()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
368 if to_sleep > 0:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
369 logging.info("Next check at %s",
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
370 time.strftime("%Y-%m-%d %H:%M:%S",
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
371 time.localtime(next_check)))
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
372 time.sleep(to_sleep)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
373 else:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
374 logging.info("Next check now")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
375
8
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
376 def check_package_lines(self):
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
377 logging.info("Checking package lines")
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
378 for line in self.package_lines:
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
379 try:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
380 packager = line.package_if_updated()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
381 if packager:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
382 packager.package()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
383 except:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
384 logging.exception("An error occurred while"
8
574506a022f6 Rename AssemblyLine to PackageLine
Bernhard Herzog <bh@intevation.de>
parents: 7
diff changeset
385 " checking packager line %r", line.name)
10
59d6055493f5 Fix typo in logging message
Bernhard Herzog <bh@intevation.de>
parents: 9
diff changeset
386 logging.info("Checked all package lines")
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)