comparison recipes/kde_enterprise_4/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 bba100869221
children 2676abfc0e1d
comparison
equal deleted inserted replaced
272:026dd7286431 273:4b700b39c32f
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 12 import inspect
13 import re
14 import logging 13 import logging
15 14
16 import treepkg.packager 15 import treepkg.packager
17 import treepkg.subversion 16 import treepkg.subversion
18
19
20 class TagDetector(object):
21
22 """Class to automatically find SVN tags and help package them
23
24 The tags are found using three parameters:
25 url -- The base url of the SVN tags directory to use
26 pattern -- A regular expression matching the subdirectories to
27 consider in the tag directory specified by the url
28 subdir -- A subdirectory of the directory matched by pattern to
29 export and use to determine revision number
30
31 The subdir parameter is there to cope with the kdepim enterprise
32 tags. The URL for a tag is of the form
33 .../tags/kdepim/enterprise4.0.<date>.<rev> . Each such tag has
34 subdirectories for kdepim, kdelibs, etc. The url and pattern are
35 used to match the URL for the tag, and the subdir is used to select
36 which part of the tag is meant.
37
38 The subdir also determines which SVN directory's revision number is
39 used. Normally, just appending the subdir to the tag URL would be
40 enough for this, but the situation is more complex for
41 kdebase_workspace and kdebase_runtime, whose code comes from
42 different subdirectories of the kdebase-4.X-branch subdirectory (for
43 enterprise4 tags). Here the revision number must be taken from
44 kdebase-4.X-branch, but the URL to use when exporting the sources,
45 must refer to e.g. kdebase-4.1-branch/kdebase_workspace. To achieve
46 that, subdir may contain slashes to indicate subdirectories of
47 subdirectories, but only the first part of subdir (up to the first
48 slash) is used when determining the revision number.
49 """
50
51 def __init__(self, url, pattern, subdir):
52 self.url = url
53 self.pattern = re.compile(pattern)
54 self.subdir = subdir
55
56 def list_tags(self):
57 matches = []
58 if self.url:
59 for tag in treepkg.subversion.list_url(self.url):
60 if self.pattern.match(tag.rstrip("/")):
61 matches.append(tag)
62 return sorted(matches)
63
64 def newest_tag_revision(self):
65 """Determines the newest tag revision and returns (tagurl, revno)
66 If no tag can be found, the method returns the tuple (None, None).
67 """
68 candidates = self.list_tags()
69 urlrev = (None, None)
70 if candidates:
71 newest = candidates[-1]
72 urlrev = self.determine_revision(self.url + "/" + newest,
73 self.subdir)
74 return urlrev
75
76 def determine_revision(self, baseurl, subdir):
77 urlrev = (None, None)
78 revision_url = baseurl + "/" + subdir.split("/")[0]
79 try:
80 revision = treepkg.subversion.last_changed_revision(revision_url)
81 urlrev = (baseurl + "/" + subdir, revision)
82 except treepkg.subversion.SubversionError:
83 pass
84 return urlrev
85 17
86 18
87 class BaseSourcePackager(treepkg.packager.SourcePackager): 19 class BaseSourcePackager(treepkg.packager.SourcePackager):
88 20
89 def __init__(self, *args, **kw): 21 def __init__(self, *args, **kw):
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()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)