Gaudi Framework, version v22r0

Home   Generated: 9 Feb 2011

tag_release.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003 Small script to prepare the tags and the distribution special directory for a
00004 release of Gaudi.
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, re, sys, tempfile, shutil
00011 from subprocess import Popen, PIPE
00012 
00013 _req_version_pattern = re.compile(r"^\s*version\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*$")
00014 def extract_version(f):
00015     """
00016     Find the version number in a requirements file.
00017     """
00018     global _req_version_pattern
00019     for l in open(f):
00020         m = _req_version_pattern.match(l)
00021         if m:
00022             return m.group(1)
00023     return None
00024 
00025 _use_pattern = re.compile(r"^\s*use\s*(\w+)\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*(\w+)?\s*$")
00026 def gather_new_versions(f):
00027     global _use_pattern
00028     versions = {}
00029     for l in open(f):
00030         m = _use_pattern.match(l)
00031         if m:
00032             versions[m.group(1)] = m.group(2)
00033     return versions
00034 
00035 def svn(*args, **kwargs):
00036     print "> svn", " ".join(args)
00037     return apply(Popen, (["svn"] + list(args),), kwargs)
00038 
00039 def svn_ls(url):
00040     return svn("ls", url, stdout = PIPE).communicate()[0].splitlines()
00041 
00042 def basename(url):
00043     return url.rsplit("/", 1)[-1]
00044 
00045 def dirname(url):
00046     return url.rsplit("/", 1)[1]
00047 
00048 def svn_exists(url):
00049     d,b = url.rsplit("/", 1)
00050     l = [x.rstrip("/") for x in svn_ls(d)]
00051     return b in l
00052 
00053 def checkout_structure(url, proj):
00054     def checkout_level(base):
00055         dirs = ["%s/%s" % (base, d) for d in svn_ls(base) if d.endswith("/")]
00056         apply(svn, ["up", "-N"] + dirs).wait()
00057         return dirs
00058 
00059     root = basename(url)
00060     svn("co","-N", url, root).wait()
00061     old_dir = os.getcwd()
00062     os.chdir(root)
00063     svn("up", "-N", proj).wait()
00064     for base in [proj, proj + "/trunk"]:
00065         checkout_level(base)
00066     checkout_level(proj + "/tags")
00067     os.chdir(old_dir)
00068     return root
00069 
00070 def main():
00071     use_pre = len(sys.argv) > 1 and 'pre' in  sys.argv
00072     url = "svn+ssh://svn.cern.ch/reps/gaudi"
00073     proj = "Gaudi"
00074     container = "GaudiRelease"
00075     packages = gather_new_versions("requirements")
00076     packages[container] = extract_version("requirements")
00077     tempdir = tempfile.mkdtemp()
00078     try:
00079         os.chdir(tempdir)
00080         # prepare repository structure (and move to its top level)
00081         os.chdir(checkout_structure(url, proj))
00082 
00083         # note that the project does not have "-pre"
00084         pvers = "%s_%s" % (proj.upper(), packages[container])
00085 
00086         # prepare project tag
00087         ptagdir = "%s/tags/%s/%s" % (proj, proj.upper(), pvers)
00088         if not svn_exists(ptagdir):
00089             svn("mkdir", ptagdir).wait()
00090             svn("cp", "%s/trunk/cmt" % proj, ptagdir + "/cmt").wait()
00091 
00092         # prepare package tags
00093         tag_re = re.compile(r"^v(\d+)r(\d+)(?:p(\d+))?$")
00094         for p in packages:
00095             tag = packages[p]
00096             pktagdir = "%s/tags/%s/%s" % (proj, p, tag)
00097             # I have to make the tag if it doesn't exist and (if we use -pre tags)
00098             # neither the -pre tag exists.
00099             no_tag = not svn_exists(pktagdir)
00100             make_tag = no_tag or (use_pre and no_tag and not svn_exists(pktagdir + "-pre"))
00101             if make_tag:
00102                 if use_pre:
00103                     pktagdir += "-pre"
00104                 svn("cp", "%s/trunk/%s" % (proj, p), pktagdir).wait()
00105                 # Atlas type of tag
00106                 tagElements = tag_re.match(tag)
00107                 if tagElements:
00108                     tagElements = "-".join([ "%02d" % int(el or "0") for el in tagElements.groups() ])
00109                     pktagdir = "%s/tags/%s/%s-%s" % (proj, p, p, tagElements)
00110                     svn("cp", "%s/trunk/%s" % (proj, p), pktagdir).wait()
00111             else:
00112                 if not no_tag:
00113                     svn("up", "-N", pktagdir).wait() # needed for the copy in the global tag
00114 
00115         if not use_pre:
00116             # prepare the full global tag too
00117             for p in packages:
00118                 tag = packages[p]
00119                 pktagdir = "%s/tags/%s/%s" % (proj, p, tag)
00120                 svn("cp", pktagdir, "%s/%s" % (ptagdir, p)).wait()
00121 
00122         svn("ci").wait()
00123 
00124     finally:
00125         shutil.rmtree(tempdir, ignore_errors = True)
00126 
00127     return 0
00128 
00129 if __name__ == '__main__':
00130     sys.exit(main())
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Wed Feb 9 16:24:59 2011 for Gaudi Framework, version v22r0 by Doxygen version 1.6.2 written by Dimitri van Heesch, © 1997-2004