7 from __future__
import absolute_import, division, print_function
13 """Is file under svn control?"""
15 return re.search(
r"is not a working copy",
16 "".join(os.popen(
"svn info %s 2>&1" % file).readlines())) ==
None
19 """Return a dictionary of all the information returned by "svn info" for the specified file"""
22 raise RuntimeError(
"%s is not under svn control" % file)
24 infoList = os.popen(
"svn info %s" % file).readlines()
28 mat = re.search(
r"^([^:]+)\s*:\s*(.*)", line)
30 info[mat.group(1)] = mat.group(2)
35 """Is file on the trunk?"""
39 return re.search(
r"/trunk($|/)", info[
"URL"]) !=
None
42 """Return file's Revision as a string; if file is None return
43 a tuple (oldestRevision, youngestRevision, flags) as reported
44 by svnversion; e.g. (4123, 4168, ("M", "S")) (oldestRevision
45 and youngestRevision may be equal)
52 return info[
"Last Changed Rev"]
54 return info[
"Revision"]
57 raise RuntimeError(
"lastChanged makes no sense if file is None")
59 res = os.popen(
"svnversion . 2>&1").readline()
61 if res ==
"exported\n":
62 raise RuntimeError(
"No svn revision information is available")
64 versionRe =
r"^(?P<oldest>\d+)(:(?P<youngest>\d+))?(?P<flags>[MS]*)"
65 mat = re.search(versionRe, res)
67 matches = mat.groupdict()
68 if not matches[
"youngest"]:
69 matches[
"youngest"] = matches[
"oldest"]
72 res = os.popen(
"svnversion --committed . 2>&1").readline()
73 mat = re.search(versionRe, res)
75 matches = mat.groupdict()
76 return matches[
"youngest"], matches[
"youngest"], tuple(matches[
"flags"])
78 return matches[
"oldest"], matches[
"youngest"], tuple(matches[
"flags"])
80 raise RuntimeError(
"svnversion returned unexpected result \"%s\"" % res[:-1])
86 """Guess a version name given a HeadURL"""
88 if re.search(
r"/trunk$", HeadURL):
90 elif re.search(
r"/branches/(.+)$", HeadURL):
91 versionName =
"branch_%s+" % re.search(
r"/branches/(.+)$", HeadURL).group(1)
92 elif re.search(
r"/tags/(.+)$", HeadURL):
93 versionName =
"%s" % re.search(
r"/tags/(.*)$", HeadURL).group(1)
96 elif re.search(
r"/tickets/(\d+)$", HeadURL):
97 versionName =
"ticket_%s+" % re.search(
r"/tickets/(\d+)$", HeadURL).group(1)
99 print(
"Unable to guess versionName name from %s" % HeadURL, file=sys.stderr)
100 versionName =
"unknown+"
103 (oldest, youngest, flags) =
revision()
107 msg =
"You are installing, but have unchecked in files"
110 msg =
"You are installing, but have switched SVN URLs"
112 if oldest != youngest:
113 msg =
"You have a range of revisions in your tree (%s:%s); adopting %s" % \
114 (oldest, youngest, youngest)
118 raise RuntimeError(
"Problem with determining svn revision: %s" % msg)
120 versionName +=
"svn" + youngest
127 """A callback that knows about the LSST convention that a tagname such as
129 means the top of ticket 374, and
131 means revision 6021 on ticket 374. You may replace "ticket" with "branch" if you wish
133 The "versionName" may actually be the directory part of a URL, and ".../(branches|tags|tickets)/tagname"
137 mat = re.search(
r"/(branche|tag|ticket)s/(\d+(?:\.\d+)*)(?:([-+])((svn)?(\d+)))?$", versionName)
139 mat = re.search(
r"/(branch|ticket)_(\d+)(?:([-+])svn(\d+))?$", versionName)
142 if type ==
"branches":
144 ticket = mat.group(2)
146 revision = mat.group(4)
148 revision = re.sub(
"^svn",
"", revision)
150 return (type, ticket, revision, pm)
152 return (
None,
None,
None,
None)