| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# update_versions.py

Go to the documentation of this file.

    00001 #!/usr/bin/env python
    00002
    00003 __author__ = "Marco Clemencic <Marco.Clemencic@cern.ch>"
    00004 __version__ = "$Id: update_versions.py,v 1.3 2008/11/10 19:43:31 marcocle Exp $"
    00005
    00006 import os, re, sys, time
    00007
    00008 # special_packages = [ "Gaudi", "GaudiSys", "GaudiExamples" ]
    00009
    00010 # guess current version
    00011 _req_version_pattern = re.compile(r"^\s*version\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*$")
    00012 def extract_version(f):
    00013     """
    00014     Find the version number in a requirements file.
    00015     """
    00016     global _req_version_pattern
    00017     for l in open(f):
    00018         m = _req_version_pattern.match(l)
    00019         if m:
    00020             return m.group(1)
    00021     return None
    00022
    00023 def change_version(packagedir, newversion):
    00024     """
    00025     Compare the version of the package with the new one and update the package if
    00026     needed.
    00027
    00028     Returns true if the package have been modified.
    00029     """
    00030     global _req_version_pattern
    00031     changed = False
    00032     out = []
    00033     req = os.path.join(packagedir,"requirements")
    00034     for l in open(req):
    00035         m = _req_version_pattern.match(l)
    00036         if m:
    00037             if m.group(1) != newversion:
    00038                 print "%s: %s -> %s"%(packagedir,m.group(1),newversion)
    00039                 l = l.replace(m.group(1),newversion)
    00040                 changed = True
    00041         out.append(l)
    00042     if changed:
    00043         open(req,"w").writelines(out)
    00044     # verify the version.cmt file
    00045     ver = os.path.join(packagedir,"version.cmt")
    00046     if os.path.exists(ver):
    00047         current = open(ver).read().strip()
    00048         if current != newversion:
    00049             open(ver,"w").write(newversion + "\n")
    00050     return changed
    00051
    00052 _use_pattern = re.compile(r"^\s*use\s*(\w+)\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*(\w+)?\s*$")
    00053 def gather_new_versions(f):
    00054     global _use_pattern
    00055     versions = {}
    00056     for l in open(f):
    00057         m = _use_pattern.match(l)
    00058         if m:
    00059             versions[m.group(1)] = m.group(2)
    00060     return versions
    00061
    00062 def update_release_notes(filename, pkg, version):
    00063     changelog_entry = re.compile(r'^(! [0-9]{4}-[0-9]{2}-[0-9]{2} -)|============')
    00064     separator_entry = re.compile(r'^============')
    00065     separator = "================ %s %s ====================================\n"
    00066     out = []
    00067     notes = []
    00068     state = "searching"
    00069     for l in open(filename):
    00070         if state == "searching":
    00071             if changelog_entry.match(l):
    00072                 out.append(separator%(pkg,version))
    00073                 state = "found"
    00074         if state == "found":
    00075             if not separator_entry.match(l):
    00076                 notes.append(l)
    00077             else:
    00078                 state = "over"
    00079         out.append(l)
    00080     if state != "searching":
    00081         open(filename,"w").writelines(out)
    00082     else:
    00083         print "Warning: could not update release.notes in %s"%pkg
    00084     # remove trailing empty lines
    00085     while notes and not notes[-1].strip(): notes.pop()
    00086     return "".join(notes)
    00087
    00088 def main():
    00089
    00090     m = re.search("use\s*LCGCMT\s*LCGCMT_(\S*)",open(os.path.join("..","..","cmt","project.cmt")).read())
    00091     if m:
    00092         LCGCMTVers = m.group(1)
    00093     else:
    00094         print "Cannot find LCGCMT version"
    00095         sys.exit(1)
    00096
    00097     all_packages = {}
    00098     exec(os.popen(r"""cmt broadcast 'echo "all_packages[\"<package>\"]" = \"$PWD\"'""","r").read())
    00099
    00100     versions = gather_new_versions("requirements")
    00101     release_notes = {}
    00102     for pkg in all_packages:
    00103         if pkg in versions:
    00104             print "Updating %s"%pkg
    00105             if change_version(all_packages[pkg],versions[pkg]):
    00106                 relnotes = os.path.join(all_packages[pkg],"..","doc","release.notes")
    00107                 release_notes[pkg] = update_release_notes(relnotes, pkg, versions[pkg])
    00108             else:
    00109                 print "%s unchanged"%pkg
    00110
    00111     print "<!-- ====================================================================== -->"
    00112     data = { "vers": versions["Gaudi"], "date": time.strftime("%Y-%m-%d") }
    00113     print '<h2><a name="%(vers)s">Gaudi %(vers)s</a> (%(date)s)</h2>' % data
    00114     data = { "vers": LCGCMTVers }
    00115     print '<h3>Externals version: <a href="http://lcgsoft.cern.ch/index.py?page=cfg_overview&cfg=%(vers)s">LCGCMT_%(vers)s</a></h3>' % data
    00116     print "<h3>Packages Changes</h3>"
    00117     print "<ul>"
    00118     for pkg in release_notes:
    00119         if release_notes[pkg]:
    00120             print '<li>%s (%s):\n<ul>\n<li><br/>\n    (<span class="author"></span>)</li>\n</ul>\n<pre>'%(pkg,versions[pkg])
    00121             print release_notes[pkg].replace('&','&amp;') \
    00122                                     .replace('<','&lt;') \
    00123                                     .replace('>','&gt;') + "<pre>"
    00124             print "</li>"
    00125     print "</ul>"
    00126
    00127 if __name__ == '__main__':
    00128     main()