annotate treepkg/packager.py @ 140:0da76aee8035

Add RevisionPackager method list_log_files which returns a description of the log files available for that revision
author Bernhard Herzog <bh@intevation.de>
date Mon, 02 Jun 2008 15:46:41 +0000
parents a7fa22320c3f
children 1dcddaacf12e
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
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
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
113
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
16 import new
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
17
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
18 import util
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
19 import subversion
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
20 import run
16
7c55f3879c4d Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents: 14
diff changeset
21 import status
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
22 import debian
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 41
diff changeset
23 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
24 from builder import PBuilder
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
25
139
a7fa22320c3f Extend _filenameproperty so that the filename can be interpreted
Bernhard Herzog <bh@intevation.de>
parents: 136
diff changeset
26 def _filenameproperty(filename, dir_attr="base_dir"):
a7fa22320c3f Extend _filenameproperty so that the filename can be interpreted
Bernhard Herzog <bh@intevation.de>
parents: 136
diff changeset
27 """Create a property for a directory or filename.
a7fa22320c3f Extend _filenameproperty so that the filename can be interpreted
Bernhard Herzog <bh@intevation.de>
parents: 136
diff changeset
28 If the filename is relative it is interpreted as relative to the
a7fa22320c3f Extend _filenameproperty so that the filename can be interpreted
Bernhard Herzog <bh@intevation.de>
parents: 136
diff changeset
29 value of the attribute of self named by dir_attr which defaults to
a7fa22320c3f Extend _filenameproperty so that the filename can be interpreted
Bernhard Herzog <bh@intevation.de>
parents: 136
diff changeset
30 'base_dir'.
a7fa22320c3f Extend _filenameproperty so that the filename can be interpreted
Bernhard Herzog <bh@intevation.de>
parents: 136
diff changeset
31 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
32 def get(self):
139
a7fa22320c3f Extend _filenameproperty so that the filename can be interpreted
Bernhard Herzog <bh@intevation.de>
parents: 136
diff changeset
33 return os.path.join(getattr(self, dir_attr), filename)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
34 return property(get)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
35
135
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
36 def _fromparent(attr):
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
37 """Creates a property that delegates its value to self.parent.<attr>"""
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
38 def get(self):
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
39 return getattr(self.parent, attr)
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
40 return property(get)
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
41
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
42
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
43 class SourcePackager(object):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
44
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
45 # Derived classes must supply the package basename
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
46 pkg_basename = None
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
47
135
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
48 track = _fromparent("track")
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
49 revision = _fromparent("revision")
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
50 status = _fromparent("status")
136
5598014b2a1d Add a log/ subdir for each revision. The filename is available as the
Bernhard Herzog <bh@intevation.de>
parents: 135
diff changeset
51 log_dir = _fromparent("log_dir")
135
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
52 work_dir = _fromparent("work_dir")
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
53 src_dir = _fromparent("src_dir")
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
54
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
55 def __init__(self, parent):
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
56 self.parent = parent
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
57 assert(self.pkg_basename)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
58
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
59 def determine_package_version(self, directory):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
60 """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
61
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
62 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
63 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
64 export_sources method.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
65
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
66 The default implementation simply returns the revision converted
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
67 to a string.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
68 """
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
69 return str(self.revision)
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 def export_sources(self):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
72 """Export the sources from the subversion working directory
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
73
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
74 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
75 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
76
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
77 <pkg_basename>-<version>
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
78
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
79 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
80 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
81 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
82 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
83 self.track.export_sources(temp_dir)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
84
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
85 pkgbaseversion = self.determine_package_version(temp_dir)
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
86 pkgbasedir = os.path.join(self.work_dir,
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
87 self.pkg_basename + "-" + pkgbaseversion)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
88
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
89 os.rename(temp_dir, pkgbasedir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
90 return pkgbaseversion, pkgbasedir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
91
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
92
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
93 def update_version_numbers(self, pkgbasedir):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
94 """Updates the version numbers in the code in pkgbasedir.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
95
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
96 The default implementation does nothing. Derived classes should
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
97 override this method if necessary.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
98 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
99
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
100 def create_tarball(self, tarballname, workdir, basedir):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
101 """Creates a new tarball.
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 Parameters:
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 tarballname -- the filename of the new tarball
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
106 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
107 (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
108 basedir -- The basedirectory of the files that are packaged
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
109 into the tarfile. This should be a relative
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
110 filename directly in workdir.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
111 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
112 logging.info("Creating tarball %r", tarballname)
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 41
diff changeset
113 run.call(cmdexpand("tar czf $tarballname -C $workdir $basedir",
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 41
diff changeset
114 **locals()))
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 def copy_debian_directory(self, pkgbasedir, pkgbaseversion, changemsg):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
117 """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
118
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
119 Parameter:
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
120 pkgbasedir -- The directory holding the unpacked source package
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
121 pkgbaseversion -- The version to update the changelog to
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
122 changemsg -- The message for the changelog
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
123
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
124 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
125 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
126 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
127 prefix is prepended to the pkgbaseversion parameter. Debian
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
128 uses such prefixes for the kde packages.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
129 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
130 debian_dir = os.path.join(pkgbasedir, "debian")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
131 changelog = os.path.join(debian_dir, "changelog")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
132
53
74cd21b6400b rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
133 self.track.copy_debian_directory(debian_dir)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
134
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
135 logging.info("Updating %r", changelog)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
136 oldversion = util.debian_changelog_version(changelog)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
137 if ":" in oldversion:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
138 oldversionprefix = oldversion.split(":")[0] + ":"
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
139 else:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
140 oldversionprefix = ""
93
73c67372c7f7 Make the prefix used in the debian revision number configurable.
Bernhard Herzog <bh@intevation.de>
parents: 91
diff changeset
141 debrev = self.track.debrevision_prefix + "1"
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 41
diff changeset
142 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
143 " -v ${oldversionprefix}${pkgbaseversion}-${debrev}"
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 41
diff changeset
144 " $changemsg", **locals()),
53
74cd21b6400b rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
145 env=self.track.debian_environment())
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
146
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
147
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
148 def create_source_package(self, pkgbasedir, origtargz):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
149 """Creates a new source package from pkgbasedir and origtargz"""
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
150 logging.info("Creating new source package")
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 41
diff changeset
151 run.call(cmdexpand("dpkg-source -b $directory $tarball",
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 41
diff changeset
152 directory=os.path.basename(pkgbasedir),
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 41
diff changeset
153 tarball=os.path.basename(origtargz)),
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
154 cwd=os.path.dirname(pkgbasedir),
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
155 suppress_output=True,
53
74cd21b6400b rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
156 env=self.track.debian_environment())
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
157
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
158 def move_source_package(self, pkgbasename):
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
159 """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
160 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
161 util.ensure_directory(self.src_dir)
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
162 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
163 if filename.startswith(pkgbasename)]:
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
164 os.rename(os.path.join(self.work_dir, filename),
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
165 os.path.join(self.src_dir, filename))
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
166
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
167 def package(self):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
168 """Creates a source package from a subversion checkout.
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 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
171 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
172 work directory is removed.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
173 """
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
174 util.ensure_directory(self.work_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
175 try:
41
f7ec40638a06 use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
176 self.status.creating_source_package()
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
177 self.do_package()
41
f7ec40638a06 use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
178 self.status.source_package_created()
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
179 finally:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
180 logging.info("Removing workdir %r", self.work_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
181 shutil.rmtree(self.work_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
182
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
183 def do_package(self):
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
184 """Does the work of creating a source package
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
185 This method must be overriden by derived classes.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
186
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
187 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
188 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
189 self.src_dir.
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
190 """
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
191 raise NotImplementedError
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
192
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
193
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
194 class BinaryPackager(object):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
195
135
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
196 track = _fromparent("track")
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
197 status = _fromparent("status")
136
5598014b2a1d Add a log/ subdir for each revision. The filename is available as the
Bernhard Herzog <bh@intevation.de>
parents: 135
diff changeset
198 log_dir = _fromparent("log_dir")
135
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
199 binary_dir = _fromparent("binary_dir")
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
200
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
201 def __init__(self, parent, dsc_file, logfile):
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
202 self.parent = parent
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
203 self.dsc_file = dsc_file
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
204 self.logfile = logfile
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
205
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
206 def package(self):
41
f7ec40638a06 use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
207 self.status.creating_binary_package()
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
208 util.ensure_directory(self.binary_dir)
54
b0014b8f6029 fix typo in log message
Bernhard Herzog <bh@intevation.de>
parents: 53
diff changeset
209 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
210 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
211 self.status.binary_package_created()
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
212
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
213
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
214 class RevisionPackager(object):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
215
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
216 source_packager_cls = SourcePackager
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
217 binary_packager_cls = BinaryPackager
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
218
53
74cd21b6400b rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
219 def __init__(self, track, revision):
74cd21b6400b rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
220 self.track = track
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
221 self.revision = revision
53
74cd21b6400b rename some variables from pkg_track to track
Bernhard Herzog <bh@intevation.de>
parents: 52
diff changeset
222 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
223 self.status = status.RevisionStatus(os.path.join(self.base_dir,
086c68ca51d2 rename Status to RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 26
diff changeset
224 "status"))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
225
136
5598014b2a1d Add a log/ subdir for each revision. The filename is available as the
Bernhard Herzog <bh@intevation.de>
parents: 135
diff changeset
226 log_dir = _filenameproperty("log")
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
227 work_dir = _filenameproperty("work")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
228 binary_dir = _filenameproperty("binary")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
229 src_dir = _filenameproperty("src")
18
d5c24cfce05e Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents: 16
diff changeset
230 build_log = _filenameproperty("build.log")
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
231
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
232 def find_dsc_file(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
233 for filename in os.listdir(self.src_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
234 if filename.endswith(".dsc"):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
235 return os.path.join(self.src_dir, filename)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
236 return None
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
237
18
d5c24cfce05e Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents: 16
diff changeset
238 def has_build_log(self):
d5c24cfce05e Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents: 16
diff changeset
239 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
240
140
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
241 def list_log_files(self):
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
242 """Returns a list describing the logfiles available for the revision.
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
243 Each list item is a tuple of the form (TITLE, FILENAME) where
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
244 TITLE is a string with a title usable in e. g. a web-page, and
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
245 FILENAME is the absolute filename of the log file.
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
246 """
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
247 files = []
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
248 if self.has_build_log():
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
249 files.append(("build log", self.build_log))
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
250 return files
0da76aee8035 Add RevisionPackager method list_log_files which returns a description
Bernhard Herzog <bh@intevation.de>
parents: 139
diff changeset
251
88
3ae54f99db26 Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents: 85
diff changeset
252 def list_source_files(self):
3ae54f99db26 Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents: 85
diff changeset
253 """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
254 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
255 to the source package.
3ae54f99db26 Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents: 85
diff changeset
256 """
3ae54f99db26 Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents: 85
diff changeset
257 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
258
3ae54f99db26 Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents: 85
diff changeset
259 def list_binary_files(self):
3ae54f99db26 Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents: 85
diff changeset
260 """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
261 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
262 to the binary packages.
3ae54f99db26 Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents: 85
diff changeset
263 """
3ae54f99db26 Add methods RevisionPackager.list_source_files and
Bernhard Herzog <bh@intevation.de>
parents: 85
diff changeset
264 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
265
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
266 def package(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
267 try:
16
7c55f3879c4d Use the new status class and report start/stop time too
Bernhard Herzog <bh@intevation.de>
parents: 14
diff changeset
268 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
269 self.status.start = datetime.datetime.utcnow()
135
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
270 src_packager = self.source_packager_cls(self)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
271 src_packager.package()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
272
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
273 dsc_file = self.find_dsc_file()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
274 if dsc_file is None:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
275 raise RuntimeError("Cannot find dsc File in %r" % self.src_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
276
135
e5b4dea52297 Make more of RevisionPackager available to SourcePackager and
Bernhard Herzog <bh@intevation.de>
parents: 131
diff changeset
277 bin_packager = self.binary_packager_cls(self, dsc_file,
18
d5c24cfce05e Improve access to a RevisionPackager's build_log
Bernhard Herzog <bh@intevation.de>
parents: 16
diff changeset
278 self.build_log)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
279 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
280 self.status.stop = datetime.datetime.utcnow()
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
281 except:
41
f7ec40638a06 use the enums for the status field of RevisionStatus
Bernhard Herzog <bh@intevation.de>
parents: 36
diff changeset
282 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
283 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
284 # 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
285 # 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
286 # 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
287 # 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
288 # "notification_sent")
7888fe374e11 Add support for notification mails in case of build errors
Bernhard Herzog <bh@intevation.de>
parents: 98
diff changeset
289 self.status.notification_pending()
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
290 raise
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 remove_package_dir(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
293 logging.info("Removing pkgdir %r", self.base_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
294 shutil.rmtree(self.base_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
295
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
296
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
297 class PackageTrack(object):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
298
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
299 revision_packager_cls = RevisionPackager
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
300
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
301 svn_external_subdirs = []
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
302
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
303 extra_config_desc = []
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
304
47
2802be410156 add config options pbuilderrc and use it when calling pbuilder
Bernhard Herzog <bh@intevation.de>
parents: 16
diff changeset
305 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
306 deb_fullname, packager_class="treepkg.packager",
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
307 debrevision_prefix="treepkg", handle_dependencies=False):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
308 self.name = name
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
309 self.base_dir = base_dir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
310 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
311 self.builder = PBuilder(pbuilderrc, root_cmd)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
312 self.deb_email = deb_email
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
313 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
314 self.debrevision_prefix = debrevision_prefix
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
315 self.handle_dependencies = handle_dependencies
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
316 self.dependencies = None
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
317 self.pkg_dir_template = "%(revision)d-%(increment)d"
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
318 self.pkg_dir_regex \
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
319 = re.compile(r"(?P<revision>[0-9]+)-(?P<increment>[0-9]+)$")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
320
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
321 checkout_dir = _filenameproperty("checkout")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
322 debian_dir = _filenameproperty("debian")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
323 pkg_dir = _filenameproperty("pkg")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
324
106
66cbfc772f84 Add bin/inittreepkg.py, a script to automate some of the installation
Bernhard Herzog <bh@intevation.de>
parents: 99
diff changeset
325 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
326 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
327 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
328 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
329 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
330 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
331 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
332 % (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
333
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
334 def determine_dependencies(self):
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
335 if self.dependencies is not None:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
336 return
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
337
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
338 requires = ()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
339 provides = ()
131
bea9f1cc0bef Try to determine dependencies only when treepkg is fully configured.
Bernhard Herzog <bh@intevation.de>
parents: 128
diff changeset
340 # only try to parse the control file if the debian directory
bea9f1cc0bef Try to determine dependencies only when treepkg is fully configured.
Bernhard Herzog <bh@intevation.de>
parents: 128
diff changeset
341 # exists. If the debian directory doesn't exist yet, the tree
bea9f1cc0bef Try to determine dependencies only when treepkg is fully configured.
Bernhard Herzog <bh@intevation.de>
parents: 128
diff changeset
342 # packager is likely still being configured and this code may be
bea9f1cc0bef Try to determine dependencies only when treepkg is fully configured.
Bernhard Herzog <bh@intevation.de>
parents: 128
diff changeset
343 # run indirectly from e. g. bin/inittreepkg.py in which case the
bea9f1cc0bef Try to determine dependencies only when treepkg is fully configured.
Bernhard Herzog <bh@intevation.de>
parents: 128
diff changeset
344 # init_treepkg method will report the missing debian
bea9f1cc0bef Try to determine dependencies only when treepkg is fully configured.
Bernhard Herzog <bh@intevation.de>
parents: 128
diff changeset
345 if self.handle_dependencies and os.path.exists(self.debian_dir):
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
346 control = debian.DebianControlFile(os.path.join(self.debian_dir,
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
347 "control"))
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
348 requires = control.build_depends
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
349 provides = (pkg[0] for pkg in control.packages)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
350 self.dependencies = (set(requires), set(provides))
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
351 logging.debug("Track %s: build depends: %s", self.name,
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
352 " ".join(self.dependencies[0]))
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
353 logging.debug("Track %s: provides: %s", self.name,
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
354 " ".join(self.dependencies[1]))
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
355
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
356 def dependencies_required(self):
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
357 """Returns a list of required packages"""
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
358 self.determine_dependencies()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
359 return self.dependencies[0]
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
360
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
361 def dependencies_provided(self):
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
362 """Returns a list of provided packages"""
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
363 self.determine_dependencies()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
364 return self.dependencies[1]
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
365
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
366 def pkg_dir_for_revision(self, revision, increment):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
367 return os.path.join(self.pkg_dir,
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
368 self.pkg_dir_template % locals())
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
369
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
370 def last_changed_revision(self):
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
371 revisions = []
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
372 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
373 directory = os.path.join(self.checkout_dir, directory)
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
374 revisions.append(subversion.last_changed_revision(directory))
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
375 return max(revisions)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
376
11
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
377 def get_revision_numbers(self):
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
378 """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
379 revisions = []
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
380 if os.path.exists(self.pkg_dir):
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
381 for filename in os.listdir(self.pkg_dir):
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
382 match = self.pkg_dir_regex.match(filename)
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
383 if match:
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
384 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
385 revisions.sort()
11
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
386 return revisions
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
387
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
388 def last_packaged_revision(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
389 """Returns the revision number of the highest packaged revision.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
390
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
391 If the revision cannot be determined because no already packaged
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
392 revisions can be found, the function returns -1.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
393 """
11
6efe0bd3d8c1 Add method RevisionPackager.get_revision_numbers
Bernhard Herzog <bh@intevation.de>
parents: 10
diff changeset
394 return max([-1] + self.get_revision_numbers())
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
395
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
396 def debian_source(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
397 return util.extract_value_for_key(open(os.path.join(self.debian_dir,
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
398 "control")),
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
399 "Source:")
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
400
80
0af2fa3790e0 Add revision parameter to PackagerGroup.__init__ and some other methods
Bernhard Herzog <bh@intevation.de>
parents: 78
diff changeset
401 def update_checkout(self, revision=None):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
402 """Updates the working copy of self.svn_url in self.checkout_dir.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
403
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
404 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
405 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
406 passed through to subversion.update.
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
407 """
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
408 localdir = self.checkout_dir
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
409 if os.path.exists(localdir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
410 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
411 subversion.update(localdir, revision=revision)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
412 else:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
413 logging.info("The working copy in %r doesn't exist yet."
26
06fba656dde8 fix typo
Bernhard Herzog <bh@intevation.de>
parents: 18
diff changeset
414 " Checking out from %r", localdir,
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
415 self.svn_url)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
416 subversion.checkout(self.svn_url, localdir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
417
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
418 def export_sources(self, to_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
419 logging.info("Exporting sources for tarball to %r", to_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
420 subversion.export(self.checkout_dir, to_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
421 # some versions of svn (notably version 1.4.2 shipped with etch)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
422 # do export externals such as the admin subdirectory. We may
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
423 # have to do that in an extra step.
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
424 for subdir in self.svn_external_subdirs:
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
425 absdir = os.path.join(to_dir, subdir)
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
426 if not os.path.isdir(absdir):
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
427 subversion.export(os.path.join(self.checkout_dir, subdir),
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
428 absdir)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
429
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
430 def copy_debian_directory(self, to_dir):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
431 logging.info("Copying debian directory to %r", to_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
432 shutil.copytree(self.debian_dir, to_dir)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
433
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
434 def debian_environment(self):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
435 """Returns the environment variables for the debian commands"""
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
436 env = os.environ.copy()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
437 env["DEBFULLNAME"] = self.deb_fullname
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
438 env["DEBEMAIL"] = self.deb_email
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
439 return env
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
440
80
0af2fa3790e0 Add revision parameter to PackagerGroup.__init__ and some other methods
Bernhard Herzog <bh@intevation.de>
parents: 78
diff changeset
441 def package_if_updated(self, revision=None):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
442 """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
443 self.update_checkout(revision=revision)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
444 current_revision = self.last_changed_revision()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
445 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
446 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
447 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
448 current_revision)
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
449 return self.revision_packager_cls(self, current_revision)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
450 else:
98
f7b9c7113c46 Make packaging a specific revision work even if newer revisions have already
Bernhard Herzog <bh@intevation.de>
parents: 93
diff changeset
451 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
452 current_revision)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
453
14
dfd89f81e66c Add simple status report tool. Still using the old status files
Bernhard Herzog <bh@intevation.de>
parents: 11
diff changeset
454 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
455 """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
456 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
457 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
458
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
459
113
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
460 def import_packager_module(packager_class):
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
461 """Import the packager module named by packager_class.
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
462
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
463 The packager_class must be the full absolute module name for the
125
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
464 packager. The function tries to find or create a suitable
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
465 PackageTrack class from this module using the following rules:
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
466
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
467 - If the module contains a class called PackageTrack, use that.
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
468
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
469 - Otherwise create one using the module's RevisionPackager class,
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
470 creating RevisionPackager if necessary.
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
471
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
472 - If RevisionPackager needs to be created, it uses the module's
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
473 SourcePackager as source_packager_cls and if present also the
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
474 module's BinaryPackager as binary_packager_cls. If the module
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
475 does not have a BinaryPackager, the default BinaryPackager is
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
476 used.
113
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
477 """
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
478 module = util.import_dotted_name(packager_class)
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
479 if not hasattr(module, "PackageTrack"):
125
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
480 if not hasattr(module, "RevisionPackager"):
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
481 binary_packager = getattr(module, "BinaryPackager", BinaryPackager)
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
482 module.RevisionPackager \
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
483 = new.classobj("RevisionPackager", (RevisionPackager,),
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
484 dict(source_packager_cls=module.SourcePackager,
34e08d52956e Make the import_packager_module function more flexible. The modules may
Bernhard Herzog <bh@intevation.de>
parents: 113
diff changeset
485 binary_packager_cls=binary_packager))
113
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
486 module.PackageTrack \
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
487 = new.classobj("PackageTrack", (PackageTrack,),
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
488 dict(revision_packager_cls=module.RevisionPackager))
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
489 return module
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
490
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
491 def create_package_track(packager_class, **kw):
113
312949e7628d Add a smarter way to load the packager modules: Add the function
Bernhard Herzog <bh@intevation.de>
parents: 112
diff changeset
492 module = import_packager_module(packager_class)
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
493 return module.PackageTrack(**kw)
4
fee641fec94e Separate the kolab specific parts.
Bernhard Herzog <bh@intevation.de>
parents: 2
diff changeset
494
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
495
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
496 class CyclicDependencyError(Exception):
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
497
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
498 """Exception thrown when a cycle is detected in the track dependencies"""
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
499
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
500 def __init__(self, tracks):
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
501 Exception.__init__(self,
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
502 "Cyclic dependencies between" " tracks (%s)"
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
503 % ", ".join([track.name for track in tracks]))
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
504
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
505
7
96f4f58c62b5 Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents: 4
diff changeset
506 class PackagerGroup(object):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
507
91
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
508 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
509 instructions_file=None):
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
510 self.package_tracks = package_tracks
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
511 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
512 self.revision = revision
91
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
513 self.instructions_file = instructions_file
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
514 self.instructions_file_removed = False
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
515 self.sort_tracks()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
516
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
517 def sort_tracks(self):
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
518 """Sorts tracks for dependency handling"""
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
519 todo = self.package_tracks[:]
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
520 sorted = []
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
521 seen = set()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
522
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
523 # dependencies that can be solved by one of the tracks
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
524 known = set()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
525 for track in todo:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
526 known |= track.dependencies_provided()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
527
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
528 while todo:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
529 todo_again = []
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
530 for track in todo:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
531 if not track.handle_dependencies:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
532 sorted.append(track)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
533 continue
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
534
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
535 unmet = (track.dependencies_required() & known) - seen
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
536 if unmet:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
537 todo_again.append(track)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
538 else:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
539 sorted.append(track)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
540 seen |= track.dependencies_provided()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
541 if todo_again == todo:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
542 raise CyclicDependencyError(todo)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
543 todo = todo_again
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
544
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
545 self.package_tracks = sorted
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
546 self.needed_binaries = set()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
547 for track in self.package_tracks:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
548 self.needed_binaries |= track.dependencies_required()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
549 self.needed_binaries &= known
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
550
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
551 logging.info("sorted track order: %s",
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
552 " ".join(track.name for track in sorted))
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
553 logging.info("binary packages needed as build dependencies: %s",
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
554 " ".join(self.needed_binaries))
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
555
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
556
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
557 def run(self):
7
96f4f58c62b5 Rename the Packager class to PackagerGroup
Bernhard Herzog <bh@intevation.de>
parents: 4
diff changeset
558 """Runs the packager group indefinitely"""
78
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents: 55
diff changeset
559 logging.info("Starting in periodic check mode."
9a602d8eaa60 initial revision of the subversion repository
Thomas Arendsen Hein <thomas@intevation.de>
parents: 55
diff changeset
560 " Will check every %d seconds", self.check_interval)
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
561 last_check = -1
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
562 while 1:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
563 now = time.time()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
564 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
565 if self.check_package_tracks():
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
566 break
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
567 last_check = now
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
568 next_check = now + self.check_interval
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
569 to_sleep = next_check - time.time()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
570 if to_sleep > 0:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
571 logging.info("Next check at %s",
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
572 time.strftime("%Y-%m-%d %H:%M:%S",
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
573 time.localtime(next_check)))
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
574 time.sleep(to_sleep)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
575 else:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
576 logging.info("Next check now")
91
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
577 if self.should_stop():
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
578 logging.info("Received stop instruction. Stopping.")
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
579 return
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
580
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
581 def check_package_tracks(self):
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
582 logging.info("Checking package tracks")
91
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
583 self.clear_instruction()
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
584 repeat = True
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
585 while repeat:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
586 repeat = False
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
587 for track in self.package_tracks:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
588 try:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
589 packager = track.package_if_updated(revision=self.revision)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
590 if packager:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
591 packager.package()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
592 repeat = self.install_dependencies(track, packager)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
593 if self.should_stop():
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
594 logging.info("Received stop instruction. Stopping.")
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
595 return True
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
596 except:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
597 logging.exception("An error occurred while"
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
598 " checking packager track %r", track.name)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
599 if repeat:
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
600 logging.info("Built binaries needed by other tracks."
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
601 " Starting over to ensure all dependencies"
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
602 " are met")
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
603 break
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
604
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
605 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
606
128
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
607
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
608 def install_dependencies(self, track, packager):
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
609 """Add the binaries built by packager to the builder, if necessary.
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
610 It is necessary if any track depends on the packages. The
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
611 method simply installs all binary files built by the packger
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
612 instead of only those which are immediately required by a track.
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
613 This is done because tracks usually depend directly only on the
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
614 -dev packages which usually require another binary package built
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
615 at the same time.
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
616 """
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
617 if (track.handle_dependencies
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
618 and track.dependencies_provided() & self.needed_binaries):
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
619 # FIXME: this basically assumes that all tracks use the same
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
620 # builder. This is true for now, but it is possible to
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
621 # configure treepkg with different builders for different
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
622 # tracks and we really should be installing the newly built
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
623 # binaries into the builder of the tracks which depends on
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
624 # them
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
625 binaries = packager.list_binary_files()
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
626 track.builder.add_binaries_to_extra_pkg(binaries)
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
627 return True
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
628 return False
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
629
5155b4f9443d Add basic dependency handling to PackageTrack and PackagerGroup.
Bernhard Herzog <bh@intevation.de>
parents: 125
diff changeset
630
52
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
631 def get_package_tracks(self):
78cf5f6778ec Rename 'packagel ine' -> 'package track'
Bernhard Herzog <bh@intevation.de>
parents: 49
diff changeset
632 return self.package_tracks
91
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
633
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
634 def read_instruction(self):
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
635 if not self.instructions_file:
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
636 return ""
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
637 try:
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
638 f = open(self.instructions_file)
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
639 except (IOError, OSError):
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
640 return ""
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
641 try:
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
642 return f.read().strip()
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
643 finally:
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
644 f.close()
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
645 self.clear_instruction()
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
646
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
647 def clear_instruction(self, force=False):
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
648 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
649 or force):
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
650 util.writefile(self.instructions_file, "")
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
651 self.instructions_file_removed = True
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
652
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
653 def should_stop(self):
3ed079a7174a Implement a way to stop a running treepackager.
Bernhard Herzog <bh@intevation.de>
parents: 90
diff changeset
654 return self.read_instruction() == "stop"
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)