All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
update_versions Namespace Reference

Functions

def extract_version
 
def change_cml_version
 
def change_version
 
def gather_new_versions
 
def extract_recent_rel_notes
 
def add_release_separator_bar
 
def main
 

Variables

string __author__ = "Marco Clemencic <Marco.Clemencic@cern.ch>"
 
string __version__ = "$Id: update_versions.py,v 1.3 2008/11/10 19:43:31 marcocle Exp $"
 
tuple _req_version_pattern = re.compile(r"^\s*version\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*$")
 
tuple _cml_version_pattern = re.compile(r"^\s*gaudi_subdir\s*\(\s*\S+\s+(v[0-9]+r[0-9]+(?:p[0-9]+)?)\)\s*$")
 
tuple _use_pattern = re.compile(r"^\s*use\s*(\w+)\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*(\w+)?\s*$")
 

Function Documentation

def update_versions.add_release_separator_bar (   filename,
  pkg,
  version 
)

Definition at line 103 of file update_versions.py.

104 def add_release_separator_bar(filename, pkg, version):
105  changelog_entry = re.compile(r'^(! [0-9]{4}-[0-9]{2}-[0-9]{2} -)|============')
106  title = " %s %s " % (pkg, version)
107  letf_chars = (78 - len(title)) / 2
108  right_chars = 78 - letf_chars - len(title)
109  separator = ("=" * letf_chars) + title + ("=" * right_chars) + "\n"
110  out = []
111  found = False
112  for l in open(filename):
113  # looking for the first changelog entry
114  if not found:
115  if changelog_entry.match(l):
116  out.append(separator)
117  found = True
118  # if found, just go on appending lines
119  out.append(l)
120  if found:
121  open(filename,"w").writelines(out)
122  else:
123  print "Warning: could not update release.notes in %s" % pkg
def update_versions.change_cml_version (   cml,
  newversion 
)

Definition at line 24 of file update_versions.py.

24 
25 def change_cml_version(cml, newversion):
26  if os.path.exists(cml):
27  out = []
28  changed = False
29  for l in open(cml):
30  m = _cml_version_pattern.match(l)
31  if m and m.group(1) != newversion:
32  print "%s: %s -> %s"%(cml, m.group(1), newversion)
33  l = l.replace(m.group(1), newversion)
34  changed = True
35  out.append(l)
36  if changed:
37  open(cml, "w").writelines(out)
def update_versions.change_version (   packagedir,
  newversion 
)
Compare the version of the package with the new one and update the package if
needed.

Returns true if the package have been modified.

Definition at line 38 of file update_versions.py.

38 
39 def change_version(packagedir, newversion):
40  """
41  Compare the version of the package with the new one and update the package if
42  needed.
43 
44  Returns true if the package have been modified.
45  """
46  global _req_version_pattern
47  changed = False
48  out = []
49  req = os.path.join(packagedir,"requirements")
50  for l in open(req):
51  m = _req_version_pattern.match(l)
52  if m:
53  if m.group(1) != newversion:
54  print "%s: %s -> %s"%(packagedir,m.group(1),newversion)
55  l = l.replace(m.group(1),newversion)
56  changed = True
57  out.append(l)
58  if changed:
59  open(req,"w").writelines(out)
60  # verify the version.cmt file
61  ver = os.path.join(packagedir,"version.cmt")
62  if os.path.exists(ver):
63  current = open(ver).read().strip()
64  if current != newversion:
65  open(ver,"w").write(newversion + "\n")
66  # update CMakeLists.txt
67  cml = os.path.normpath(os.path.join(packagedir, "..", "CMakeLists.txt"))
68  change_cml_version(cml, newversion)
69  if "GaudiKernel" in packagedir:
70  cml = os.path.normpath(os.path.join(packagedir, "..", "src", "Util", "CMakeLists.txt"))
71  change_cml_version(cml, newversion)
72  return changed
def update_versions.extract_recent_rel_notes (   filename)

Definition at line 83 of file update_versions.py.

83 
84 def extract_recent_rel_notes(filename):
85  changelog_entry = re.compile(r'^(! [0-9]{4}-[0-9]{2}-[0-9]{2} -)|!?============')
86  separator_entry = re.compile(r'^!?============')
87  notes = []
88  state = "searching"
89  for l in open(filename):
90  # looking for the first changelog entry
91  if state == "searching":
92  if changelog_entry.match(l):
93  state = "found"
94  # when found, we start collecting lines until the next separator
95  if state == "found":
96  if not separator_entry.match(l):
97  notes.append(l)
98  else:
99  break
100  # remove trailing empty lines
101  while notes and not notes[-1].strip(): notes.pop()
102  return "".join(notes)
def update_versions.extract_version (   f)
Find the version number in a requirements file.

Definition at line 13 of file update_versions.py.

13 
14 def extract_version(f):
15  """
16  Find the version number in a requirements file.
17  """
18  global _req_version_pattern
19  for l in open(f):
20  m = _req_version_pattern.match(l)
21  if m:
22  return m.group(1)
23  return None
def update_versions.gather_new_versions (   f)

Definition at line 74 of file update_versions.py.

74 
75 def gather_new_versions(f):
76  global _use_pattern
77  versions = {}
78  for l in open(f):
79  m = _use_pattern.match(l)
80  if m:
81  versions[m.group(1)] = m.group(2)
82  return versions
def update_versions.main ( )

Definition at line 124 of file update_versions.py.

125 def main():
126 
127  # Find the version of LCGCMT
128  m = re.search("use\s*LCGCMT\s*LCGCMT_(\S*)",open(os.path.join("..","..","cmt","project.cmt")).read())
129  if m:
130  LCGCMTVers = m.group(1)
131  print "Using LCGCMT", LCGCMTVers
132  else:
133  print "Cannot find LCGCMT version"
134  sys.exit(1)
135 
136  # Collect all the packages in the project with their directory
137  # (I want to preserve the order that cmt broadcast gives)
138  all_packages_tmp = []
139  exec(os.popen(r"""cmt broadcast 'echo "all_packages_tmp.append((\"<package>\"", \"$PWD\""))"'""","r").read())
140  all_packages_names = []
141  all_packages = {}
142  for k,v in all_packages_tmp:
143  all_packages_names.append(k)
144  all_packages[k] = v
145 
146  # Packages which version must match the version of the project
147  special_packages = ["Gaudi", "GaudiExamples", "GaudiSys", "GaudiRelease"]
148 
149  # Ask for the version of the project
150  old_version = extract_version("requirements")
151  new_version = raw_input("The old version of the project is %s, which is the new one? " % old_version)
152 
153  old_versions = {}
154  release_notes = {}
155  new_versions = {}
156  # for each package in the project check if there were changes and ask for the new version number
157  for pkg in all_packages_names:
158  reqfile = os.path.join(all_packages[pkg], "requirements")
159  relnotefile = os.path.join(all_packages[pkg], "..", "doc", "release.notes")
160  old_versions[pkg] = extract_version(reqfile)
161  if os.path.exists(relnotefile): # ignore missing release.notes
162  release_notes[pkg] = extract_recent_rel_notes(relnotefile)
163  else:
164  release_notes[pkg] = ""
165  if pkg in special_packages:
166  new_versions[pkg] = new_version
167  else:
168  if release_notes[pkg]:
169  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]))
170  else:
171  new_versions[pkg] = old_versions[pkg]
172  # update infos
173  if new_versions[pkg] != old_versions[pkg]:
174  change_version(all_packages[pkg], new_versions[pkg])
175  if os.path.exists(relnotefile):
176  add_release_separator_bar(relnotefile, pkg, new_versions[pkg])
177  print "=" * 80
178  # The changes in the GaudiRelease requirements for the other packages can be postponed to now
179  reqfile = os.path.join(all_packages["GaudiRelease"], "requirements")
180  out = []
181  for l in open(reqfile):
182  sl = l.strip().split()
183  if sl and sl[0] == "use":
184  if sl[1] in new_versions:
185  if sl[2] != new_versions[sl[1]]:
186  l = l.replace(sl[2], new_versions[sl[1]])
187  out.append(l)
188  open(reqfile, "w").writelines(out)
189 
190  # update the global release notes
191  new_lines = []
192  new_lines.append("<!-- ====================================================================== -->")
193  data = { "vers": new_version, "date": time.strftime("%Y-%m-%d") }
194  new_lines.append('<h2><a name="%(vers)s">Gaudi %(vers)s</a> (%(date)s)</h2>' % data)
195  data = { "vers": LCGCMTVers }
196  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)
197  new_lines.append("<h3>General Changes</h3>")
198  new_lines.append('<ul>\n<li><br/>\n (<span class="author"></span>)</li>\n</ul>')
199  new_lines.append("<h3>Packages Changes</h3>")
200  new_lines.append("<ul>")
201  for pkg in all_packages_names:
202  if release_notes[pkg]:
203  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]))
204  new_lines.append(release_notes[pkg].replace('&','&amp;') \
205  .replace('<','&lt;') \
206  .replace('>','&gt;') + "</pre>")
207  new_lines.append("</li>")
208  new_lines.append("</ul>")
209 
210  global_rel_notes = os.path.join("..", "doc", "release.notes.html")
211  out = []
212  separator = re.compile("<!-- =+ -->")
213  block_added = False
214  for l in open(global_rel_notes):
215  if not block_added and separator.match(l.strip()):
216  out.append("\n".join(new_lines) + "\n")
217  block_added = True
218  out.append(l)
219  open(global_rel_notes, "w").writelines(out)
220 
221  # update the global CMakeLists.txt
222  global_cmakelists = os.path.join("..","..","CMakeLists.txt")
223  out = []
224  for l in open(global_cmakelists):
225  if l.strip().startswith('gaudi_project'):
226  l = 'gaudi_project(Gaudi %s)\n' % new_version
227  out.append(l)
228  open(global_cmakelists, "w").writelines(out)

Variable Documentation

string update_versions.__author__ = "Marco Clemencic <Marco.Clemencic@cern.ch>"

Definition at line 3 of file update_versions.py.

string update_versions.__version__ = "$Id: update_versions.py,v 1.3 2008/11/10 19:43:31 marcocle Exp $"

Definition at line 4 of file update_versions.py.

tuple update_versions._cml_version_pattern = re.compile(r"^\s*gaudi_subdir\s*\(\s*\S+\s+(v[0-9]+r[0-9]+(?:p[0-9]+)?)\)\s*$")

Definition at line 12 of file update_versions.py.

tuple update_versions._req_version_pattern = re.compile(r"^\s*version\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*$")

Definition at line 11 of file update_versions.py.

tuple update_versions._use_pattern = re.compile(r"^\s*use\s*(\w+)\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*(\w+)?\s*$")

Definition at line 73 of file update_versions.py.