Gaudi Framework, version v25r2

Home   Generated: Wed Jun 4 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
finalize_tags.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 Small script finalize the "-pre" tags into regular tags for the packages in Gaudi.
4 
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, sys
11 import tempfile, shutil, re
12 from subprocess import Popen, PIPE
13 
14 def _spawn(*args, **kwargs):
15  cmd = args
16  cwd = kwargs.get("cwd", os.getcwd())
17  print ">>>> %s: %s" % (cwd, cmd)
18  return apply(Popen, (cmd,), kwargs)
19 def _exec_cmd(*args, **kwargs):
20  return apply(_spawn, args, kwargs).wait()
21 def _exec_cmd_output(*args, **kwargs):
22  kwargs["stdout"] = PIPE
23  p = apply(_spawn, args, kwargs)
24  out = p.communicate()[0]
25  return out, p.returncode
26 
27 def svn(*args, **kwargs):
28  return apply(_exec_cmd, ["svn"] + list(args), kwargs)
29 
30 def svn_output(*args, **kwargs):
31  return apply(_exec_cmd_output, ["svn"] + list(args), kwargs)
32 
33 for c in ["co", "up", "ci", "ls", "add", "rm", "cp", "mkdir", "mv", "pg"]:
34  exec """
35 def svn_%(cmd)s(*args, **kwargs):
36  return apply(svn, ["%(cmd)s"] + list(args), kwargs)
37 def svn_%(cmd)s_output(*args, **kwargs):
38  return apply(svn_output, ["%(cmd)s"] + list(args), kwargs)
39 """ % {"cmd": c}
40 
41 svn_ci_real = svn_ci
42 def svn_ci_fake(args, cwd = "."):
43  cmd = ["svn", "ci"] + args
44  print "(n)> %s: %s" % (cwd, cmd)
45 #svn_ci = svn_ci_fake
46 
47 def basename(url):
48  return url.rsplit("/", 1)[-1]
49 
50 def dirname(url):
51  return url.rsplit("/", 1)[1]
52 
53 def svn_exists(url):
54  d,b = url.rsplit("/", 1)
55  l = [x.rstrip("/") for x in svn_ls(d)]
56  return b in l
57 
58 def checkout_structure(url, proj):
59  def checkout_level(base):
60  dirs = ["%s/%s" % (base, d) for d in svn_ls_output(base)[0].splitlines() if d.endswith("/")]
61  apply(svn, ["up", "-N"] + dirs)
62  return dirs
63  root = basename(url)
64  svn("co","-N", url, root)
65  old_dir = os.getcwd()
66  os.chdir(root)
67  packages = [ pkg
68  for pkg, prj in
69  [ x.split()
70  for x in [ x.strip()
71  for x in svn_pg_output("packages", ".")[0].splitlines()]
72  if x and not x.startswith("#") ]
73  if prj == proj ]
74  pkg_tag_dirs = [ proj + "/tags/" + pkg for pkg in packages ]
75  apply(svn, ["up", "-N", proj, proj + "/tags"] + pkg_tag_dirs)
76  os.chdir(old_dir)
77  return root, packages
78 
79 def svn_listdir(path):
80  return [f.rstrip("/") for f in svn_ls_output(path)[0].splitlines()]
81 
82 def main():
83  url = "svn+ssh://svn.cern.ch/reps/gaudi"
84  proj = "Gaudi"
85  tempdir = tempfile.mkdtemp()
86  try:
87  os.chdir(tempdir)
88 
89  # prepare repository structure (and move to its top level)
90  root, packages = checkout_structure(url, proj)
91  os.chdir(root)
92 
93  pre_rx = re.compile("(v[0-9]+r[0-9]+(p[0-9]+)?)-pre([0-9]*)")
94  for p in packages:
95  entries = svn_listdir("%s/tags/%s" %(proj, p))
96  # get the list of -pre tags in the package
97  pre_tags = [ (t.group(0), t.group(1), t.group(3))
98  for t in map(pre_rx.match, entries)
99  if t ]
100  # extract the latest -pre tag for each tag
101  tags = {}
102  for pt, t, ptv in pre_tags:
103  if ptv:
104  ptv = int(ptv)
105  else:
106  ptv = -1
107  if (t not in tags) or (tags[t][0] < ptv):
108  tags[t] = (ptv, pt)
109  # throw away unneeded information from the map
110  tags = dict(zip(tags.keys(), map(lambda a: a[1], tags.values())))
111  for tag in tags:
112  pretagdir = "%s/tags/%s/%s" %(proj, p, tags[tag])
113  tagdir = "%s/tags/%s/%s" %(proj, p, tag)
114  if tag not in entries:
115  svn_up("-N", pretagdir)
116  svn_cp(pretagdir, tagdir)
117 
118  return svn_ci()
119 
120  finally:
121  shutil.rmtree(tempdir, ignore_errors = True)
122  pass
123 
124 if __name__ == '__main__':
125  sys.exit(main())

Generated at Wed Jun 4 2014 14:48:58 for Gaudi Framework, version v25r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004