comparison recipes/kde_enterprise_3_5/base.py @ 271:12facd1b5f19

Implement tag detection for the KDEPIM enterprise 3.5 packages. This is a simple port of the implementation for the enterprise 4 branch. This change leads to a lot of duplicated code that needs to be refactored.
author Bernhard Herzog <bh@intevation.de>
date Thu, 07 May 2009 13:51:21 +0000
parents
children 4b700b39c32f
comparison
equal deleted inserted replaced
270:e5e23c3acaea 271:12facd1b5f19
1 # Copyright (C) 2007, 2008, 2009 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <bh@intevation.de>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8 """Base classes for all kdepim packagers"""
9
10 import os
11 import time
12 import inspect
13 import re
14 import logging
15
16 import treepkg.packager
17 import treepkg.subversion
18
19 class TagDetector(object):
20
21 """Class to automatically find SVN tags and help package them
22
23 The tags are found using three parameters:
24 url -- The base url of the SVN tags directory to use
25 pattern -- A regular expression matching the subdirectories to
26 consider in the tag directory specified by the url
27 subdir -- A subdirectory of the directory matched by pattern to
28 export and use to determine revision number
29
30 The subdir parameter is there to cope with the kdepim enterprise
31 tags. The URL for a tag is of the form
32 .../tags/kdepim/enterprise4.0.<date>.<rev> . Each such tag has
33 subdirectories for kdepim, kdelibs, etc. The url and pattern are
34 used to match the URL for the tag, and the subdir is used to select
35 which part of the tag is meant.
36
37 The subdir also determines which SVN directory's revision number is
38 used. Normally, just appending the subdir to the tag URL would be
39 enough for this, but the situation is more complex for
40 kdebase_workspace and kdebase_runtime, whose code comes from
41 different subdirectories of the kdebase-4.X-branch subdirectory (for
42 enterprise4 tags). Here the revision number must be taken from
43 kdebase-4.X-branch, but the URL to use when exporting the sources,
44 must refer to e.g. kdebase-4.1-branch/kdebase_workspace. To achieve
45 that, subdir may contain slashes to indicate subdirectories of
46 subdirectories, but only the first part of subdir (up to the first
47 slash) is used when determining the revision number.
48 """
49
50 def __init__(self, url, pattern, subdir):
51 self.url = url
52 self.pattern = re.compile(pattern)
53 self.subdir = subdir
54
55 def list_tags(self):
56 matches = []
57 if self.url:
58 for tag in treepkg.subversion.list_url(self.url):
59 if self.pattern.match(tag.rstrip("/")):
60 matches.append(tag)
61 return sorted(matches)
62
63 def newest_tag_revision(self):
64 """Determines the newest tag revision and returns (tagurl, revno)
65 If no tag can be found, the method returns the tuple (None, None).
66 """
67 candidates = self.list_tags()
68 urlrev = (None, None)
69 if candidates:
70 newest = candidates[-1]
71 urlrev = self.determine_revision(self.url + "/" + newest,
72 self.subdir)
73 return urlrev
74
75 def determine_revision(self, baseurl, subdir):
76 urlrev = (None, None)
77 revision_url = baseurl + "/" + subdir.split("/")[0]
78 try:
79 revision = treepkg.subversion.last_changed_revision(revision_url)
80 urlrev = (baseurl + "/" + subdir, revision)
81 except treepkg.subversion.SubversionError:
82 pass
83 return urlrev
84
85
86 class BaseSourcePackager(treepkg.packager.SourcePackager):
87
88 changemsg_template = None
89
90 def __init__(self, *args, **kw):
91 super(BaseSourcePackager, self).__init__(*args, **kw)
92 self.enterprise_version = (time.strftime("%Y%m%d", time.localtime()) \
93 + "." + str(self.revision))
94
95 def determine_package_version(self, directory):
96 enterprise_version = self.enterprise_version
97 return self.track.version_template % locals()
98
99 def do_package(self):
100 pkgbaseversion, pkgbasedir = self.export_sources()
101 self.update_version_numbers(pkgbasedir)
102
103 pkgbasename = self.pkg_basename + "_" + pkgbaseversion
104 origtargz = os.path.join(self.work_dir,
105 pkgbasename + ".orig.tar.gz")
106 self.create_tarball(origtargz, self.work_dir,
107 os.path.basename(pkgbasedir))
108
109 changemsg = self.changemsg_template % dict(revision=self.revision)
110 self.copy_debian_directory(pkgbasedir, pkgbaseversion,
111 changemsg)
112
113 self.create_source_package(pkgbasedir, origtargz)
114 self.move_source_package(pkgbasename)
115
116
117 class BasePackageTrack(treepkg.packager.PackageTrack):
118
119 extra_config_desc = [("version_template", str, "%(enterprise_version)s"),
120 ("tags_url", str, ""),
121 ("tags_pattern", str, ""),
122 ("tags_subdir", str, "")]
123
124 def __init__(self, *args, **kw):
125 self.version_template = kw.pop("version_template")
126 tags_url = kw.pop("tags_url")
127 tags_pattern = kw.pop("tags_pattern")
128 tags_subdir = kw.pop("tags_subdir")
129 super(BasePackageTrack, self).__init__(*args, **kw)
130 self.tag_detector = TagDetector(tags_url, tags_pattern, tags_subdir)
131
132 def packager_for_new_revision(self):
133 logging.info("Checking tags")
134 self.tag_url = None
135 tag_url, tag_revision = self.tag_detector.newest_tag_revision()
136 logging.info("Found: %s: %s", tag_url, tag_revision)
137 if tag_url is not None:
138 revision = (tag_revision,
139 self.rules_working_copy.last_changed_revision())
140 logging.info("New revision is %s", revision)
141 if revision not in self.get_revision_numbers():
142 logging.info("Revision %s has not been packaged yet",
143 revision)
144 self.tag_url = tag_url
145 return self.revision_packager_cls(self, tag=tag_url, *revision)
146 else:
147 logging.info("Revision %s has already been packaged.",
148 revision)
149
150 return super(BasePackageTrack, self).packager_for_new_revision()
151
152 def export_sources(self, to_dir):
153 if self.tag_url is not None:
154 self.export_tag(self.tag_url, to_dir)
155 else:
156 super(BasePackageTrack, self).export_sources(to_dir)
157
158 def export_tag(self, tag_url, to_dir):
159 logging.info("Exporting sources from %s to %r",
160 tag_url, to_dir)
161 treepkg.subversion.export(tag_url, to_dir)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)