annotate 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
rev   line source
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
1 # Copyright (C) 2007, 2008, 2009 by Intevation GmbH
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
2 # Authors:
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
3 # Bernhard Herzog <bh@intevation.de>
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
4 #
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
7
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
8 """Collection of subversion utility code"""
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
9
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
10 import os
230
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
11 import shutil
273
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
12 import re
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
13
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
14 import run
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
15 from cmdexpand import cmdexpand
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
16 from util import extract_value_for_key
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
17
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
18
269
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
19 class SubversionError(Exception):
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
20 pass
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
21
262
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
22 def list_url(url):
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
23 """Runs svn list with the given url and returns files listed as a list"""
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
24 output = run.capture_output(cmdexpand("svn list $url", **locals()))
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
25 return output.splitlines()
81ba86662cbd Add treepkg/subversion.list_url function, a wrapper for "svn list"
Bernhard Herzog <bh@intevation.de>
parents: 230
diff changeset
26
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
27 def checkout(url, localdir, revision=None, recurse=True):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
28 """Runs svn to checkout the repository at url into the localdir"""
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
29 args = []
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
30 if revision:
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
31 args.extend(["--revision", revision])
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
32 if not recurse:
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
33 args.append("-N")
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
34 run.call(cmdexpand("svn checkout -q @args $url $localdir", **locals()))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
35
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
36 def update(localdir, revision=None, recurse=True):
79
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
37 """Runs svn update on the localdir.
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
38 The parameter revision, if given, is passed to svn as the value of
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
39 the --revision option.
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
40 """
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
41 args = []
79
570ac81865be Add revision parameter to update so that a checkout can be updated to a
Bernhard Herzog <bh@intevation.de>
parents: 45
diff changeset
42 if revision:
208
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
43 args.extend(["--revision", revision])
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
44 if not recurse:
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
45 args.append("-N")
1527c37bd7aa Allow checkouts of specific revision and to prohibit recursion during
Bernhard Herzog <bh@intevation.de>
parents: 79
diff changeset
46 run.call(cmdexpand("svn update -q @args $localdir", **locals()))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
47
266
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
48 def export(src, dest, revision=None, recurse=True):
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
49 """Runs svn export src dest"""
266
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
50 args = []
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
51 if revision:
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
52 args.extend(["--revision", revision])
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
53 if not recurse:
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
54 args.append("-N")
e201ea1f6d0e Add revision and recurse parameters to treepkg.subversion.export
Bernhard Herzog <bh@intevation.de>
parents: 262
diff changeset
55 run.call(cmdexpand("svn export -q @args $src $dest", **locals()))
0
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
56
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
57 def last_changed_revision(svn_working_copy):
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
58 """return the last changed revision of an SVN working copy as an int"""
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
59 # Make sure we run svn under the C locale to avoid localized
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
60 # messages
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
61 env = os.environ.copy()
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
62 env["LANG"] = "C"
f78a02e79c84 initial checkin
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
63
45
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
64 output = run.capture_output(cmdexpand("svn info $svn_working_copy",
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
65 **locals()),
3e610233ccfe use cmdexpand when calling subprocesses
Bernhard Herzog <bh@intevation.de>
parents: 0
diff changeset
66 env=env)
269
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
67 str_rev = extract_value_for_key(output.splitlines(), "Last Changed Rev:")
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
68 if str_rev is None:
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
69 raise SubversionError("Cannot determine last changed revision for %r"
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
70 % svn_working_copy)
97fd2584df5f Make treepkg.subversion.last_changed_revision raise SubversionError if
Bernhard Herzog <bh@intevation.de>
parents: 266
diff changeset
71 return int(str_rev)
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
72
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
73
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
74 class SvnRepository(object):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
75
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
76 """Describes a subversion repository"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
77
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
78 def __init__(self, url, external_subdirs=()):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
79 """Initialize the subversion repository description
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
80 Parameters:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
81 url -- The url of the repository
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
82 external_subdirs -- A list of subdirectories which are managed
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
83 by svn externals definitions
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
84 """
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
85 self.url = url
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
86 self.external_subdirs = external_subdirs
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
87
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
88 def checkout(self, localdir, revision=None):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
89 """Checks out the repository into localdir. The revision
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
90 parameter should be an and indicates the revision to check out.
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
91 """
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
92 checkout(self.url, localdir, revision=revision)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
93
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
94 def export(self, localdir, destdir):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
95 """Exports the working copy in localdir to destdir"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
96 export(localdir, destdir)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
97 for subdir in self.external_subdirs:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
98 absdir = os.path.join(destdir, subdir)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
99 if not os.path.isdir(absdir):
228
d2ddd037ddaf Fix a bug introduced by the subversion interface reorganization
Bernhard Herzog <bh@intevation.de>
parents: 224
diff changeset
100 export(os.path.join(localdir, subdir), absdir)
224
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
101
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
102 def last_changed_revision(self, localdir):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
103 """Returns the last changed revision of the working copy in localdir"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
104 return max([last_changed_revision(os.path.join(localdir, d))
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
105 for d in [localdir] + list(self.external_subdirs)])
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
106
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
107
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
108 class SvnWorkingCopy(object):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
109
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
110 """Represents a checkout of a subversion repository"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
111
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
112 def __init__(self, repository, localdir, logger=None):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
113 """
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
114 Initialize the working copy.
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
115 Parameters:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
116 repository -- The SvnRepository instance describing the
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
117 repository
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
118 localdir -- The directory for the working copy
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
119 logger -- logging object to use for some info/debug messages
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
120 """
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
121 self.repository = repository
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
122 self.localdir = localdir
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
123 self.logger = logger
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
124
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
125 def log_info(self, *args):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
126 if self.logger is not None:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
127 self.logger.info(*args)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
128
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
129 def update_or_checkout(self, revision=None):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
130 """Updates the working copy or creates by checking out the repository"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
131 if os.path.exists(self.localdir):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
132 self.log_info("Updating the working copy in %r", self.localdir)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
133 update(self.localdir, revision=revision)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
134 else:
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
135 self.log_info("The working copy in %r doesn't exist yet."
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
136 " Checking out from %r",
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
137 self.localdir, self.repository.url)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
138 self.repository.checkout(self.localdir, revision=revision)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
139
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
140 def export(self, destdir):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
141 """Exports the working copy to destdir"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
142 self.repository.export(self.localdir, destdir)
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
143
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
144 def last_changed_revision(self):
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
145 """Returns the last changed rev of the working copy"""
6bac65dcf258 Handle the svn repositories and working copies in a more object oriented way
Bernhard Herzog <bh@intevation.de>
parents: 208
diff changeset
146 return self.repository.last_changed_revision(self.localdir)
230
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
147
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
148
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
149 class ManualWorkingCopy(object):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
150
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
151 """A manually managed working copy"""
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
152
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
153 def __init__(self, directory):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
154 self.directory = directory
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
155
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
156 def update_or_checkout(self, revision=None, recurse=True):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
157 """This method does nothing"""
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
158 pass
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
159
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
160 def export(self, destdir):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
161 """Copies the entire working copy to destdir"""
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
162 shutil.copytree(self.directory, destdir)
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
163
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
164 def last_changed_revision(self):
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
165 """Always returns 0"""
e387b879fd38 Add treepkg.subversion.ManualWorkingCopy. Same interface as
Bernhard Herzog <bh@intevation.de>
parents: 228
diff changeset
166 return 0
273
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
167
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
168
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
169 class TagDetector(object):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
170
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
171 """Class to automatically find SVN tags and help package them
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
172
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
173 The tags are found using three parameters:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
174 url -- The base url of the SVN tags directory to use
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
175 pattern -- A regular expression matching the subdirectories to
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
176 consider in the tag directory specified by the url
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
177 subdir -- A subdirectory of the directory matched by pattern to
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
178 export and use to determine revision number
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
179
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
180 The subdir parameter is there to cope with the kdepim enterprise
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
181 tags. The URL for a tag is of the form
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
182 .../tags/kdepim/enterprise4.0.<date>.<rev> . Each such tag has
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
183 subdirectories for kdepim, kdelibs, etc. The url and pattern are
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
184 used to match the URL for the tag, and the subdir is used to select
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
185 which part of the tag is meant.
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
186
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
187 The subdir also determines which SVN directory's revision number is
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
188 used. Normally, just appending the subdir to the tag URL would be
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
189 enough for this, but the situation is more complex for
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
190 kdebase_workspace and kdebase_runtime, whose code comes from
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
191 different subdirectories of the kdebase-4.X-branch subdirectory (for
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
192 enterprise4 tags). Here the revision number must be taken from
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
193 kdebase-4.X-branch, but the URL to use when exporting the sources,
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
194 must refer to e.g. kdebase-4.1-branch/kdebase_workspace. To achieve
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
195 that, subdir may contain slashes to indicate subdirectories of
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
196 subdirectories, but only the first part of subdir (up to the first
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
197 slash) is used when determining the revision number.
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
198 """
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
199
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
200 def __init__(self, url, pattern, subdir):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
201 self.url = url
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
202 self.pattern = re.compile(pattern)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
203 self.subdir = subdir
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
204
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
205 def list_tags(self):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
206 matches = []
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
207 if self.url:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
208 for tag in list_url(self.url):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
209 if self.pattern.match(tag.rstrip("/")):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
210 matches.append(tag)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
211 return sorted(matches)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
212
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
213 def newest_tag_revision(self):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
214 """Determines the newest tag revision and returns (tagurl, revno)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
215 If no tag can be found, the method returns the tuple (None, None).
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
216 """
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
217 candidates = self.list_tags()
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
218 urlrev = (None, None)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
219 if candidates:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
220 newest = candidates[-1]
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
221 urlrev = self.determine_revision(self.url + "/" + newest,
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
222 self.subdir)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
223 return urlrev
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
224
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
225 def determine_revision(self, baseurl, subdir):
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
226 urlrev = (None, None)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
227 revision_url = baseurl + "/" + subdir.split("/")[0]
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
228 try:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
229 revision = last_changed_revision(revision_url)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
230 urlrev = (baseurl + "/" + subdir, revision)
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
231 except SubversionError:
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
232 pass
4b700b39c32f Refactoring: Move the TagDetector class into the treepkg.subversion module
Bernhard Herzog <bh@intevation.de>
parents: 269
diff changeset
233 return urlrev
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)