comparison treepkg/subversion.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 97fd2584df5f
children f58f9adb7dc3
comparison
equal deleted inserted replaced
272:026dd7286431 273:4b700b39c32f
7 7
8 """Collection of subversion utility code""" 8 """Collection of subversion utility code"""
9 9
10 import os 10 import os
11 import shutil 11 import shutil
12 import re
12 13
13 import run 14 import run
14 from cmdexpand import cmdexpand 15 from cmdexpand import cmdexpand
15 from util import extract_value_for_key 16 from util import extract_value_for_key
16 17
161 shutil.copytree(self.directory, destdir) 162 shutil.copytree(self.directory, destdir)
162 163
163 def last_changed_revision(self): 164 def last_changed_revision(self):
164 """Always returns 0""" 165 """Always returns 0"""
165 return 0 166 return 0
167
168
169 class TagDetector(object):
170
171 """Class to automatically find SVN tags and help package them
172
173 The tags are found using three parameters:
174 url -- The base url of the SVN tags directory to use
175 pattern -- A regular expression matching the subdirectories to
176 consider in the tag directory specified by the url
177 subdir -- A subdirectory of the directory matched by pattern to
178 export and use to determine revision number
179
180 The subdir parameter is there to cope with the kdepim enterprise
181 tags. The URL for a tag is of the form
182 .../tags/kdepim/enterprise4.0.<date>.<rev> . Each such tag has
183 subdirectories for kdepim, kdelibs, etc. The url and pattern are
184 used to match the URL for the tag, and the subdir is used to select
185 which part of the tag is meant.
186
187 The subdir also determines which SVN directory's revision number is
188 used. Normally, just appending the subdir to the tag URL would be
189 enough for this, but the situation is more complex for
190 kdebase_workspace and kdebase_runtime, whose code comes from
191 different subdirectories of the kdebase-4.X-branch subdirectory (for
192 enterprise4 tags). Here the revision number must be taken from
193 kdebase-4.X-branch, but the URL to use when exporting the sources,
194 must refer to e.g. kdebase-4.1-branch/kdebase_workspace. To achieve
195 that, subdir may contain slashes to indicate subdirectories of
196 subdirectories, but only the first part of subdir (up to the first
197 slash) is used when determining the revision number.
198 """
199
200 def __init__(self, url, pattern, subdir):
201 self.url = url
202 self.pattern = re.compile(pattern)
203 self.subdir = subdir
204
205 def list_tags(self):
206 matches = []
207 if self.url:
208 for tag in list_url(self.url):
209 if self.pattern.match(tag.rstrip("/")):
210 matches.append(tag)
211 return sorted(matches)
212
213 def newest_tag_revision(self):
214 """Determines the newest tag revision and returns (tagurl, revno)
215 If no tag can be found, the method returns the tuple (None, None).
216 """
217 candidates = self.list_tags()
218 urlrev = (None, None)
219 if candidates:
220 newest = candidates[-1]
221 urlrev = self.determine_revision(self.url + "/" + newest,
222 self.subdir)
223 return urlrev
224
225 def determine_revision(self, baseurl, subdir):
226 urlrev = (None, None)
227 revision_url = baseurl + "/" + subdir.split("/")[0]
228 try:
229 revision = last_changed_revision(revision_url)
230 urlrev = (baseurl + "/" + subdir, revision)
231 except SubversionError:
232 pass
233 return urlrev
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)