Mercurial > treepkg
comparison recipes/kde_enterprise_3_5/base.py @ 273:4b700b39c32f
Refactoring: Move the TagDetector class into the treepkg.subversion module
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 07 May 2009 14:25:10 +0000 |
parents | 12facd1b5f19 |
children | 2676abfc0e1d |
comparison
equal
deleted
inserted
replaced
272:026dd7286431 | 273:4b700b39c32f |
---|---|
7 | 7 |
8 """Base classes for all kdepim packagers""" | 8 """Base classes for all kdepim packagers""" |
9 | 9 |
10 import os | 10 import os |
11 import time | 11 import time |
12 import inspect | |
13 import re | |
14 import logging | 12 import logging |
15 | 13 |
16 import treepkg.packager | 14 import treepkg.packager |
17 import treepkg.subversion | 15 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 | 16 |
85 | 17 |
86 class BaseSourcePackager(treepkg.packager.SourcePackager): | 18 class BaseSourcePackager(treepkg.packager.SourcePackager): |
87 | 19 |
88 changemsg_template = None | 20 changemsg_template = None |
125 self.version_template = kw.pop("version_template") | 57 self.version_template = kw.pop("version_template") |
126 tags_url = kw.pop("tags_url") | 58 tags_url = kw.pop("tags_url") |
127 tags_pattern = kw.pop("tags_pattern") | 59 tags_pattern = kw.pop("tags_pattern") |
128 tags_subdir = kw.pop("tags_subdir") | 60 tags_subdir = kw.pop("tags_subdir") |
129 super(BasePackageTrack, self).__init__(*args, **kw) | 61 super(BasePackageTrack, self).__init__(*args, **kw) |
130 self.tag_detector = TagDetector(tags_url, tags_pattern, tags_subdir) | 62 self.tag_detector = treepkg.subversion.TagDetector(tags_url, |
63 tags_pattern, | |
64 tags_subdir) | |
131 | 65 |
132 def packager_for_new_revision(self): | 66 def packager_for_new_revision(self): |
133 logging.info("Checking tags") | 67 logging.info("Checking tags") |
134 self.tag_url = None | 68 self.tag_url = None |
135 tag_url, tag_revision = self.tag_detector.newest_tag_revision() | 69 tag_url, tag_revision = self.tag_detector.newest_tag_revision() |