| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tag_release.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 Small script to prepare the tags and the distribution special directory for a
4 release of Gaudi.
5 See https://twiki.cern.ch/twiki/bin/view/Gaudi/GaudiSVNRepository for a
6 description of the repository structure.
7 """
8 __author__ = "Marco Clemencic <Marco.Clemencic@cern.ch>"
9
10 import os, re, sys, tempfile, shutil
11 from subprocess import Popen, PIPE
12
13 _req_version_pattern = re.compile(r"^\s*version\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*$")
14 def extract_version(f):
15 """
16 Find the version number in a requirements file.
17 """
18 global _req_version_pattern
19 for l in open(f):
20 m = _req_version_pattern.match(l)
21 if m:
22 return m.group(1)
23 return None
24
25 _use_pattern = re.compile(r"^\s*use\s*(\w+)\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*(\w+)?\s*$")
26 def gather_new_versions(f):
27 global _use_pattern
28 versions = {}
29 for l in open(f):
30 m = _use_pattern.match(l)
31 if m:
32 versions[m.group(1)] = m.group(2)
33 return versions
34
35 def svn(*args, **kwargs):
36 print "> svn", " ".join(args)
37 return apply(Popen, (["svn"] + list(args),), kwargs)
38
39 def svn_ls(url):
40 return svn("ls", url, stdout = PIPE).communicate()[0].splitlines()
41
42 def basename(url):
43 return url.rsplit("/", 1)[-1]
44
45 def dirname(url):
46 return url.rsplit("/", 1)[1]
47
48 def svn_exists(url):
49 d,b = url.rsplit("/", 1)
50 l = [x.rstrip("/") for x in svn_ls(d)]
51 return b in l
52
53 def checkout_structure(url, proj, branch):
54 def checkout_level(base):
55 dirs = ["%s/%s" % (base, d) for d in svn_ls(base) if d.endswith("/")]
56 apply(svn, ["up", "-N"] + dirs).wait()
57 return dirs
58
59 root = basename(url)
60 svn("co","-N", url, root).wait()
61 old_dir = os.getcwd()
62 os.chdir(root)
63 svn("up", "-N", proj).wait()
64 br = [proj] + branch.split("/")
65 for base in [ "/".join(br[:n+1]) for n in range(len(br))]:
66 checkout_level(base)
67 checkout_level(proj + "/tags")
68 os.chdir(old_dir)
69 return root
70
71 def main():
72 from optparse import OptionParser
73 parser = OptionParser()
74 parser.add_option("--pre", action = "store_true",
75 help = "Create -pre tags instead of final tags.")
76 parser.add_option("-b", "--branch",
77 help = "Use the given (global) branch as source for the tags instead of the trunk")
78 opts, args = parser.parse_args()
79 if opts.branch:
80 opts.branch = "/".join(["branches", "GAUDI", opts.branch])
81 else:
82 opts.branch = "trunk"
83
84 url = "svn+ssh://svn.cern.ch/reps/gaudi"
85 proj = "Gaudi"
86 container = "GaudiRelease"
87 packages = gather_new_versions("requirements")
88 packages[container] = extract_version("requirements")
89 tempdir = tempfile.mkdtemp()
90 try:
91 os.chdir(tempdir)
92 # prepare repository structure (and move to its top level)
93 os.chdir(checkout_structure(url, proj, opts.branch))
94
95 # note that the project does not have "-pre"
96 pvers = "%s_%s" % (proj.upper(), packages[container])
97
98 # prepare project tag
99 ptagdir = "%s/tags/%s/%s" % (proj, proj.upper(), pvers)
100 if not svn_exists(ptagdir):
101 svn("mkdir", ptagdir).wait()
102 for f in ["cmt", "Makefile.cmt",
103 "Makefile-cmake.mk", "cmake", "CMakeLists.txt",
104 "configure", "toolchain.cmake"]:
105 svn("cp", "/".join([proj, opts.branch, f]), "/".join([ptagdir, f])).wait()
106
107 # prepare package tags
108 tag_re = re.compile(r"^v(\d+)r(\d+)(?:p(\d+))?$")
109 for p in packages:
110 tag = packages[p]
111 pktagdir = "%s/tags/%s/%s" % (proj, p, tag)
112 # I have to make the tag if it doesn't exist and (if we use -pre tags)
113 # neither the -pre tag exists.
114 no_tag = not svn_exists(pktagdir)
115 make_tag = no_tag or (opts.pre and no_tag and not svn_exists(pktagdir + "-pre"))
116 if make_tag:
117 if opts.pre:
118 pktagdir += "-pre"
119 svn("cp", "/".join([proj, opts.branch, p]), pktagdir).wait()
120 # Atlas type of tag
121 tagElements = tag_re.match(tag)
122 if tagElements:
123 tagElements = "-".join([ "%02d" % int(el or "0") for el in tagElements.groups() ])
124 pktagdir = "%s/tags/%s/%s-%s" % (proj, p, p, tagElements)
125 svn("cp", "/".join([proj, opts.branch, p]), pktagdir).wait()
126 else:
127 if not no_tag:
128 svn("up", "-N", pktagdir).wait() # needed for the copy in the global tag
129
130 if not opts.pre:
131 # prepare the full global tag too
132 for p in packages:
133 tag = packages[p]
134 pktagdir = "%s/tags/%s/%s" % (proj, p, tag)
135 svn("cp", pktagdir, "%s/%s" % (ptagdir, p)).wait()
136
137 svn("ci").wait()
138
139 finally:
140 shutil.rmtree(tempdir, ignore_errors = True)
141
142 return 0
143
144 if __name__ == '__main__':
145 sys.exit(main())