| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

# finalize_tags.py

Go to the documentation of this file.

    00001 #!/usr/bin/env python
    00002 """
    00003 Small script finalize the "-pre" tags into regular tags for the packages in Gaudi.
    00004
    00005 See https://twiki.cern.ch/twiki/bin/view/Gaudi/GaudiSVNRepository for a
    00006 description of the repository structure.
    00007 """
    00008 __author__ = "Marco Clemencic <Marco.Clemencic@cern.ch>"
    00009
    00010 import os, sys
    00011 import tempfile, shutil, re
    00012 from subprocess import Popen, PIPE
    00013
    00014 def _spawn(*args, **kwargs):
    00015     cmd = args
    00016     cwd = kwargs.get("cwd", os.getcwd())
    00017     print ">>>> %s: %s" % (cwd, cmd)
    00018     return apply(Popen, (cmd,), kwargs)
    00019 def _exec_cmd(*args, **kwargs):
    00020     return apply(_spawn, args, kwargs).wait()
    00021 def _exec_cmd_output(*args, **kwargs):
    00022     kwargs["stdout"] = PIPE
    00023     p = apply(_spawn, args, kwargs)
    00024     out = p.communicate()[0]
    00025     return out, p.returncode
    00026
    00027 def svn(*args, **kwargs):
    00028     return apply(_exec_cmd, ["svn"] + list(args), kwargs)
    00029
    00030 def svn_output(*args, **kwargs):
    00031     return apply(_exec_cmd_output, ["svn"] + list(args), kwargs)
    00032
    00033 for c in ["co", "up", "ci", "ls", "add", "rm", "cp", "mkdir", "mv", "pg"]:
    00034     exec """
    00035 def svn_%(cmd)s(*args, **kwargs):
    00036     return apply(svn, ["%(cmd)s"] + list(args), kwargs)
    00037 def svn_%(cmd)s_output(*args, **kwargs):
    00038     return apply(svn_output, ["%(cmd)s"] + list(args), kwargs)
    00039 """ % {"cmd": c}
    00040
    00041 svn_ci_real = svn_ci
    00042 def svn_ci_fake(args, cwd = "."):
    00043     cmd = ["svn", "ci"] + args
    00044     print "(n)> %s: %s" % (cwd, cmd)
    00045 #svn_ci = svn_ci_fake
    00046
    00047 def basename(url):
    00048     return url.rsplit("/", 1)[-1]
    00049
    00050 def dirname(url):
    00051     return url.rsplit("/", 1)[1]
    00052
    00053 def svn_exists(url):
    00054     d,b = url.rsplit("/", 1)
    00055     l = [x.rstrip("/") for x in svn_ls(d)]
    00056     return b in l
    00057
    00058 def checkout_structure(url, proj):
    00059     def checkout_level(base):
    00060         dirs = ["%s/%s" % (base, d) for d in svn_ls_output(base)[0].splitlines() if d.endswith("/")]
    00061         apply(svn, ["up", "-N"] + dirs)
    00062         return dirs
    00063     root = basename(url)
    00064     svn("co","-N", url, root)
    00065     old_dir = os.getcwd()
    00066     os.chdir(root)
    00067     packages = [ pkg
    00068                  for pkg, prj in
    00069                    [ x.split()
    00070                      for x in [ x.strip()
    00071                                 for x in svn_pg_output("packages", ".")[0].splitlines()]
    00072                      if x and not x.startswith("#") ]
    00073                  if prj == proj ]
    00074     pkg_tag_dirs = [ proj + "/tags/" + pkg for pkg in packages ]
    00075     apply(svn, ["up", "-N", proj, proj + "/tags"] + pkg_tag_dirs)
    00076     os.chdir(old_dir)
    00077     return root, packages
    00078
    00079 def svn_listdir(path):
    00080     return [f.rstrip("/") for f in svn_ls_output(path)[0].splitlines()]
    00081
    00082 def main():
    00083     url = "svn+ssh://svn.cern.ch/reps/gaudi"
    00084     proj = "Gaudi"
    00085     tempdir = tempfile.mkdtemp()
    00086     try:
    00087         os.chdir(tempdir)
    00088
    00089         # prepare repository structure (and move to its top level)
    00090         root, packages = checkout_structure(url, proj)
    00091         os.chdir(root)
    00092
    00093         pre_rx = re.compile("(v[0-9]+r[0-9]+(p[0-9]+)?)-pre([0-9]*)")
    00094         for p in packages:
    00095             entries = svn_listdir("%s/tags/%s" %(proj, p))
    00096             # get the list of -pre tags in the package
    00097             pre_tags = [ (t.group(0), t.group(1), t.group(3))
    00098                          for t in map(pre_rx.match, entries)
    00099                          if t ]
    00100             # extract the latest -pre tag for each tag
    00101             tags = {}
    00102             for pt, t, ptv in pre_tags:
    00103                 if ptv:
    00104                     ptv = int(ptv)
    00105                 else:
    00106                     ptv = -1
    00107                 if (t not in tags) or (tags[t][0] < ptv):
    00108                     tags[t] = (ptv, pt)
    00109             # throw away unneeded information from the map
    00110             tags = dict(zip(tags.keys(), map(lambda a: a[1], tags.values())))
    00111             for tag in tags:
    00112                 pretagdir = "%s/tags/%s/%s" %(proj, p, tags[tag])
    00113                 tagdir = "%s/tags/%s/%s" %(proj, p, tag)
    00114                 if tag not in entries:
    00115                     svn_up("-N", pretagdir)
    00116                     svn_cp(pretagdir, tagdir)
    00117
    00118         return svn_ci()
    00119
    00120     finally:
    00121         shutil.rmtree(tempdir, ignore_errors = True)
    00122         pass
    00123
    00124 if __name__ == '__main__':
    00125     sys.exit(main())

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines