Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
update_versions.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 __author__ = "Marco Clemencic <Marco.Clemencic@cern.ch>"
4 __version__ = "$Id: update_versions.py,v 1.3 2008/11/10 19:43:31 marcocle Exp $"
5 
6 import os, re, sys, time
7 
8 # special_packages = [ "Gaudi", "GaudiSys", "GaudiExamples" ]
9 
10 # guess current version
11 _req_version_pattern = re.compile(r"^\s*version\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*$")
12 _cml_version_pattern = re.compile(r"^\s*gaudi_subdir\s*\(\s*\S+\s+(v[0-9]+r[0-9]+(?:p[0-9]+)?)\)\s*$")
13 _hwaf_hpyscript_version_pattern = re.compile(r"^\s*[\"']version[\"']\s*:\s*[\"'](v[0-9]+r[0-9]+(?:p[0-9]+)?)[\"'].*$")
14 _hwaf_ymlscript_version_pattern = re.compile(r"^\s*version\s*:\s*[\"'](v[0-9]+r[0-9]+(?:p[0-9]+)?)[\"'].*$")
15 
17  """
18  Find the version number in a requirements file.
19  """
20  global _req_version_pattern
21  for l in open(f):
22  m = _req_version_pattern.match(l)
23  if m:
24  return m.group(1)
25  return None
26 
27 def change_cml_version(cml, newversion):
28  if os.path.exists(cml):
29  out = []
30  changed = False
31  for l in open(cml):
32  m = _cml_version_pattern.match(l)
33  if m and m.group(1) != newversion:
34  print "%s: %s -> %s"%(cml, m.group(1), newversion)
35  l = l.replace(m.group(1), newversion)
36  changed = True
37  out.append(l)
38  if changed:
39  open(cml, "w").writelines(out)
40 
41 def change_hwaf_version(pkgdir, newversion):
42  hname = os.path.join(pkgdir, "..", "hscript.py")
43  yname = os.path.join(pkgdir, "..", "hscript.yml")
44  fname = None
45  pat = None
46  if os.path.exists(hname):
47  pat = _hwaf_hpyscript_version_pattern
48  fname = hname
49  elif os.path.exists(yname):
50  pat = _hwaf_ymlscript_version_pattern
51  fname = yname
52  else:
53  print ("*** package [%s] has no hwaf script" % pkgdir)
54  return
55 
56  out = []
57  changed = False
58  for l in open(fname):
59  m = pat.match(l)
60  if m and m.group(1) != newversion:
61  print "%s: %s -> %s"%(fname, m.group(1), newversion)
62  l = l.replace(m.group(1), newversion)
63  changed = True
64  out.append(l)
65  if changed:
66  open(fname, "w").writelines(out)
67  return
68 
69 def change_version(packagedir, newversion):
70  """
71  Compare the version of the package with the new one and update the package if
72  needed.
73 
74  Returns true if the package have been modified.
75  """
76  global _req_version_pattern
77  changed = False
78  out = []
79  req = os.path.join(packagedir,"requirements")
80  for l in open(req):
81  m = _req_version_pattern.match(l)
82  if m:
83  if m.group(1) != newversion:
84  print "%s: %s -> %s"%(packagedir,m.group(1),newversion)
85  l = l.replace(m.group(1),newversion)
86  changed = True
87  out.append(l)
88  if changed:
89  open(req,"w").writelines(out)
90  # verify the version.cmt file
91  ver = os.path.join(packagedir,"version.cmt")
92  if os.path.exists(ver):
93  current = open(ver).read().strip()
94  if current != newversion:
95  open(ver,"w").write(newversion + "\n")
96  # update CMakeLists.txt
97  cml = os.path.normpath(os.path.join(packagedir, "..", "CMakeLists.txt"))
98  change_cml_version(cml, newversion)
99  if "GaudiKernel" in packagedir:
100  cml = os.path.normpath(os.path.join(packagedir, "..", "src", "Util", "CMakeLists.txt"))
101  change_cml_version(cml, newversion)
102 
103  # update hscripts
104  change_hwaf_version(packagedir, newversion)
105  return changed
106 
107 _use_pattern = re.compile(r"^\s*use\s*(\w+)\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*(\w+)?\s*$")
109  global _use_pattern
110  versions = {}
111  for l in open(f):
112  m = _use_pattern.match(l)
113  if m:
114  versions[m.group(1)] = m.group(2)
115  return versions
116 
118  changelog_entry = re.compile(r'^(! [0-9]{4}-[0-9]{2}-[0-9]{2} -)|!?============')
119  separator_entry = re.compile(r'^!?============')
120  notes = []
121  state = "searching"
122  for l in open(filename):
123  # looking for the first changelog entry
124  if state == "searching":
125  if changelog_entry.match(l):
126  state = "found"
127  # when found, we start collecting lines until the next separator
128  if state == "found":
129  if not separator_entry.match(l):
130  notes.append(l)
131  else:
132  break
133  # remove trailing empty lines
134  while notes and not notes[-1].strip(): notes.pop()
135  return "".join(notes)
136 
137 def add_release_separator_bar(filename, pkg, version):
138  changelog_entry = re.compile(r'^(! [0-9]{4}-[0-9]{2}-[0-9]{2} -)|============')
139  title = " %s %s " % (pkg, version)
140  letf_chars = (78 - len(title)) / 2
141  right_chars = 78 - letf_chars - len(title)
142  separator = ("=" * letf_chars) + title + ("=" * right_chars) + "\n"
143  out = []
144  found = False
145  for l in open(filename):
146  # looking for the first changelog entry
147  if not found:
148  if changelog_entry.match(l):
149  out.append(separator)
150  found = True
151  # if found, just go on appending lines
152  out.append(l)
153  if found:
154  open(filename,"w").writelines(out)
155  else:
156  print "Warning: could not update release.notes in %s" % pkg
157 
158 def main():
159 
160  # Find the version of LCGCMT
161  m = re.search("use\s*LCGCMT\s*LCGCMT_(\S*)",open(os.path.join("..","..","cmt","project.cmt")).read())
162  if m:
163  LCGCMTVers = m.group(1)
164  print "Using LCGCMT", LCGCMTVers
165  else:
166  print "Cannot find LCGCMT version"
167  sys.exit(1)
168 
169  # Collect all the packages in the project with their directory
170  # (I want to preserve the order that cmt broadcast gives)
171  all_packages_tmp = []
172  exec(os.popen(r"""cmt broadcast 'echo "all_packages_tmp.append((\"<package>\"", \"$PWD\""))"'""","r").read())
173  all_packages_names = []
174  all_packages = {}
175  for k,v in all_packages_tmp:
176  all_packages_names.append(k)
177  all_packages[k] = v
178 
179  # Packages which version must match the version of the project
180  special_packages = ["Gaudi", "GaudiExamples", "GaudiSys", "GaudiRelease"]
181 
182  # Ask for the version of the project
183  old_version = extract_version("requirements")
184  new_version = raw_input("The old version of the project is %s, which is the new one? " % old_version)
185 
186  old_versions = {}
187  release_notes = {}
188  new_versions = {}
189  # for each package in the project check if there were changes and ask for the new version number
190  for pkg in all_packages_names:
191  reqfile = os.path.join(all_packages[pkg], "requirements")
192  relnotefile = os.path.join(all_packages[pkg], "..", "doc", "release.notes")
193  old_versions[pkg] = extract_version(reqfile)
194  if os.path.exists(relnotefile): # ignore missing release.notes
195  release_notes[pkg] = extract_recent_rel_notes(relnotefile)
196  else:
197  release_notes[pkg] = ""
198  if pkg in special_packages:
199  new_versions[pkg] = new_version
200  else:
201  if release_notes[pkg]:
202  new_versions[pkg] = raw_input("\nThe old version of %s is %s, this are the changes:\n%s\nWhich version you want (old is %s)? " % (pkg, old_versions[pkg], release_notes[pkg], old_versions[pkg]))
203  else:
204  new_versions[pkg] = old_versions[pkg]
205  # update infos
206  if new_versions[pkg] != old_versions[pkg]:
207  change_version(all_packages[pkg], new_versions[pkg])
208  if os.path.exists(relnotefile):
209  add_release_separator_bar(relnotefile, pkg, new_versions[pkg])
210  print "=" * 80
211  # The changes in the GaudiRelease requirements for the other packages can be postponed to now
212  reqfile = os.path.join(all_packages["GaudiRelease"], "requirements")
213  out = []
214  for l in open(reqfile):
215  sl = l.strip().split()
216  if sl and sl[0] == "use":
217  if sl[1] in new_versions:
218  if sl[2] != new_versions[sl[1]]:
219  l = l.replace(sl[2], new_versions[sl[1]])
220  out.append(l)
221  open(reqfile, "w").writelines(out)
222 
223  # update the global release notes
224  new_lines = []
225  new_lines.append("<!-- ====================================================================== -->")
226  data = { "vers": new_version, "date": time.strftime("%Y-%m-%d") }
227  new_lines.append('<h2><a name="%(vers)s">Gaudi %(vers)s</a> (%(date)s)</h2>' % data)
228  data = { "vers": LCGCMTVers }
229  new_lines.append('<h3>Externals version: <a href="http://lcgsoft.cern.ch/index.py?page=cfg_overview&cfg=%(vers)s">LCGCMT_%(vers)s</a></h3>' % data)
230  new_lines.append("<h3>General Changes</h3>")
231  new_lines.append('<ul>\n<li><br/>\n (<span class="author"></span>)</li>\n</ul>')
232  new_lines.append("<h3>Packages Changes</h3>")
233  new_lines.append("<ul>")
234  for pkg in all_packages_names:
235  if release_notes[pkg]:
236  new_lines.append('<li>%s (%s):\n<ul>\n<li><br/>\n (<span class="author"></span>)</li>\n</ul>\n<pre>'%(pkg,new_versions[pkg]))
237  new_lines.append(release_notes[pkg].replace('&','&amp;') \
238  .replace('<','&lt;') \
239  .replace('>','&gt;') + "</pre>")
240  new_lines.append("</li>")
241  new_lines.append("</ul>")
242 
243  global_rel_notes = os.path.join("..", "doc", "release.notes.html")
244  out = []
245  separator = re.compile("<!-- =+ -->")
246  block_added = False
247  for l in open(global_rel_notes):
248  if not block_added and separator.match(l.strip()):
249  out.append("\n".join(new_lines) + "\n")
250  block_added = True
251  out.append(l)
252  open(global_rel_notes, "w").writelines(out)
253 
254  # update the global CMakeLists.txt
255  global_cmakelists = os.path.join("..","..","CMakeLists.txt")
256  out = []
257  for l in open(global_cmakelists):
258  if l.strip().startswith('gaudi_project'):
259  l = 'gaudi_project(Gaudi %s)\n' % new_version
260  out.append(l)
261  open(global_cmakelists, "w").writelines(out)
262 
263 if __name__ == '__main__':
264  main()

Generated at Mon Feb 17 2014 14:37:48 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004