comparison recipes/kde_enterprise_4/base.py @ 265:9c0131d2e0e1

Add automatic detection and builds of svn tags for the kdepim enterprise4 packages. Doesn't work for kde-l10n yet.
author Bernhard Herzog <bh@intevation.de>
date Wed, 29 Apr 2009 16:53:00 +0000
parents 89ca9ba349e5
children fdee17d71778
comparison
equal deleted inserted replaced
264:ea3abd1aa652 265:9c0131d2e0e1
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 15
14 import treepkg.packager 16 import treepkg.packager
17 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
32 def __init__(self, url, pattern, subdir):
33 self.url = url
34 self.pattern = re.compile(pattern)
35 self.subdir = subdir
36
37 def list_tags(self):
38 matches = []
39 if self.url:
40 for tag in treepkg.subversion.list_url(self.url):
41 if self.pattern.match(tag.rstrip("/")):
42 matches.append(tag)
43 return sorted(matches)
44
45 def newest_tag_revision(self):
46 """Determines the newest tag revision and returns (tagurl, revno)
47 If no tag can be found, the method returns the tuple (None, None).
48 """
49 candidates = self.list_tags()
50 if candidates:
51 newest = candidates[-1]
52 subdir = self.subdir
53 if not subdir.endswith("/"):
54 subdir += "/"
55 tag_url = self.url + "/" + newest
56 tag_subdirs = treepkg.subversion.list_url(tag_url)
57 if subdir in tag_subdirs:
58 subdir_url = tag_url + "/" + subdir
59 revision = treepkg.subversion.last_changed_revision(subdir_url)
60 return subdir_url, revision
61 return None, None
62
15 63
16 64
17 class BaseSourcePackager(treepkg.packager.SourcePackager): 65 class BaseSourcePackager(treepkg.packager.SourcePackager):
18 66
19 def __init__(self, *args, **kw): 67 def __init__(self, *args, **kw):
44 self.move_source_package(pkgbasename) 92 self.move_source_package(pkgbasename)
45 93
46 94
47 class BasePackageTrack(treepkg.packager.PackageTrack): 95 class BasePackageTrack(treepkg.packager.PackageTrack):
48 96
49 extra_config_desc = ["version_template"] 97 extra_config_desc = ["version_template",
98 ("tags_url", str, ""),
99 ("tags_pattern", str, ""),
100 ("tags_subdir", str, "")]
50 101
51 def __init__(self, *args, **kw): 102 def __init__(self, *args, **kw):
52 self.version_template = kw.pop("version_template") 103 self.version_template = kw.pop("version_template")
104 tags_url = kw.pop("tags_url")
105 tags_pattern = kw.pop("tags_pattern")
106 tags_subdir = kw.pop("tags_subdir")
53 super(BasePackageTrack, self).__init__(*args, **kw) 107 super(BasePackageTrack, self).__init__(*args, **kw)
108 self.tag_detector = TagDetector(tags_url, tags_pattern, tags_subdir)
109
110 def packager_for_new_revision(self):
111 logging.info("Checking tags")
112 self.tag_url = None
113 tag_url, tag_revision = self.tag_detector.newest_tag_revision()
114 logging.info("Found: %s: %s", tag_url, tag_revision)
115 if tag_url is not None:
116 revision = (tag_revision,
117 self.rules_working_copy.last_changed_revision())
118 logging.info("New revision is %s", revision)
119 if revision not in self.get_revision_numbers():
120 logging.info("Revision %s has not been packaged yet",
121 revision)
122 self.tag_url = tag_url
123 return self.revision_packager_cls(self, tag=tag_url, *revision)
124 else:
125 logging.info("Revision %s has already been packaged.",
126 revision)
127
128 return super(BasePackageTrack, self).packager_for_new_revision()
129
130 def export_sources(self, to_dir):
131 if self.tag_url is not None:
132 logging.info("Exporting sources from %s to %r",
133 self.tag_url, to_dir)
134 treepkg.subversion.export(self.tag_url, to_dir)
135 else:
136 super(BasePackageTrack, self).export_sources(to_dir)
54 137
55 138
56 def define_kdepim_packager(basename=None, external_subdirs=None): 139 def define_kdepim_packager(basename=None, external_subdirs=None):
57 140
58 caller_globals = inspect.currentframe().f_back.f_globals 141 caller_globals = inspect.currentframe().f_back.f_globals
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)