| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 2010

# 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)
    00090             svn("cp", "%s/trunk/cmt" % proj, ptagdir + "/cmt").wait()
    00091
    00092         # prepare package tags
    00093         for p in packages:
    00094             tag = packages[p]
    00095             pktagdir = "%s/tags/%s/%s" % (proj, p, tag)
    00096             # I have to make the tag if it doesn't exist and (if we use -pre tags)
    00097             # neither the -pre tag exists.
    00098             no_tag = not svn_exists(pktagdir)
    00099             make_tag = no_tag or (use_pre and no_tag and not svn_exists(pktagdir + "-pre"))
    00100             if make_tag:
    00101                 if use_pre:
    00102                     pktagdir += "-pre"
    00103                 svn("cp", "%s/trunk/%s" % (proj, p), pktagdir).wait()
    00104             else:
    00105                 if not no_tag:
    00106                     svn("up", "-N", pktagdir).wait() # needed for the copy in the global tag
    00107
    00108         if not use_pre:
    00109             # prepare the full global tag too
    00110             for p in packages:
    00111                 tag = packages[p]
    00112                 pktagdir = "%s/tags/%s/%s" % (proj, p, tag)
    00113                 svn("cp", pktagdir, "%s/%s" % (ptagdir, p)).wait()
    00114
    00115         svn("ci").wait()
    00116
    00117     finally:
    00118         shutil.rmtree(tempdir, ignore_errors = True)
    00119
    00120     return 0
    00121
    00122 if __name__ == '__main__':
    00123     sys.exit(main())