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 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*$")
 

Function Documentation

def update_versions.add_release_separator_bar (   filename,
  pkg,
  version 
)

Definition at line 94 of file update_versions.py.

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

Definition at line 25 of file update_versions.py.

25 
26 def change_cml_version(cml, newversion):
27  if os.path.exists(cml):
28  out = []
29  changed = False
30  for l in open(cml):
31  m = _cml_version_pattern.match(l)
32  if m and m.group(1) != newversion:
33  print "%s: %s -> %s"%(cml, m.group(1), newversion)
34  l = l.replace(m.group(1), newversion)
35  changed = True
36  out.append(l)
37  if changed:
38  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 39 of file update_versions.py.

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

Definition at line 74 of file update_versions.py.

74 
75 def extract_recent_rel_notes(filename):
76  changelog_entry = re.compile(r'^(! [0-9]{4}-[0-9]{2}-[0-9]{2} -)|!?============')
77  separator_entry = re.compile(r'^!?============')
78  notes = []
79  state = "searching"
80  for l in open(filename):
81  # looking for the first changelog entry
82  if state == "searching":
83  if changelog_entry.match(l):
84  state = "found"
85  # when found, we start collecting lines until the next separator
86  if state == "found":
87  if not separator_entry.match(l):
88  notes.append(l)
89  else:
90  break
91  # remove trailing empty lines
92  while notes and not notes[-1].strip(): notes.pop()
93  return "".join(notes)
def update_versions.extract_version (   path)
Find the version number of a subdirectory.

Definition at line 14 of file update_versions.py.

14 
15 def extract_version(path):
16  """
17  Find the version number of a subdirectory.
18  """
19  global _cml_version_pattern
20  for l in open(os.path.join(path, 'CMakeLists.txt')):
21  m = _cml_version_pattern.match(l)
22  if m:
23  return m.group(1)
24  return None
def update_versions.main ( )

Definition at line 115 of file update_versions.py.

116 def main():
117 
118  # Find the version of HEPTools (LCG)
119  for l in open('toolchain.cmake'):
120  m = re.match(r'^\s*set\(\s*heptools_version\s+(\S*)\s*\)', l)
121  if m:
122  HEPToolsVers = m.group(1)
123  print "Using HEPTools", HEPToolsVers
124  break
125  else:
126  print "Cannot find HEPTools version"
127  sys.exit(1)
128 
129  # Collect all the packages in the project with their directory
130  def all_subdirs():
131  for dirpath, dirnames, filenames in os.walk(os.curdir):
132  if 'CMakeLists.txt' in filenames and dirpath != os.curdir:
133  dirnames[:] = []
134  yield dirpath
135  else:
136  dirnames[:] = [dirname for dirname in dirnames
137  if not dirname.startswith('build.') and
138  dirname != 'cmake']
139 
140  # Packages which version must match the version of the project
141  special_subdirs = ["Gaudi", "GaudiExamples", "GaudiSys", "GaudiRelease"]
142 
143  # Ask for the version of the project
144  top_cml = ' '.join(l.strip().split('#', 1)[0]
145  for l in open('CMakeLists.txt').readlines())
146  old_version = re.search(r'gaudi_project\(\s*\S+\s+(\S+)', top_cml).group(1)
147  new_version = raw_input("The old version of the project is %s, which is the new one? " % old_version)
148 
149  old_versions = {}
150  release_notes = {}
151  new_versions = {}
152  # for each package in the project check if there were changes and ask for the new version number
153  for pkgdir in all_subdirs():
154  relnotefile = os.path.join(pkgdir, 'doc', 'release.notes')
155  cmlfile = os.path.join(pkgdir, 'CMakeLists.txt')
156  reqfile = os.path.join(pkgdir, 'cmt', 'requirements')
157 
158  pkg = os.path.basename(pkgdir)
159  old_versions[pkg] = extract_version(pkgdir)
160 
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 
166  if pkg in special_subdirs:
167  new_versions[pkg] = new_version
168  else:
169  if release_notes[pkg]:
170  msg = ('\nThe old version of %s is %s, these are the changes:\n'
171  '%s\n'
172  'Which version you want (old is %s)? ') % \
173  (pkg, old_versions[pkg], release_notes[pkg],
174  old_versions[pkg])
175  new_versions[pkg] = raw_input(msg)
176  else:
177  new_versions[pkg] = old_versions[pkg]
178  # update infos
179  if new_versions[pkg] != old_versions[pkg]:
180  change_version(pkgdir, new_versions[pkg])
181  if os.path.exists(relnotefile):
182  add_release_separator_bar(relnotefile, pkg, new_versions[pkg])
183  print "=" * 80
184  # The changes in the GaudiRelease requirements for the other packages can be postponed to now
185  reqfile = os.path.join('GaudiRelease', 'cmt', 'requirements')
186  out = []
187  for l in open(reqfile):
188  sl = l.strip().split()
189  if sl and sl[0] == "use":
190  if sl[1] in new_versions:
191  if sl[2] != new_versions[sl[1]]:
192  l = l.replace(sl[2], new_versions[sl[1]])
193  out.append(l)
194  open(reqfile, "w").writelines(out)
195  # Update project.info
196  config = ConfigParser.ConfigParser()
197  config.optionxform = str # make the options case sensitive
198  if os.path.exists('project.info'):
199  config.read('project.info')
200  if not config.has_section('Packages'):
201  config.add_section('Packages')
202  for pack_vers in sorted(new_versions.items()):
203  config.set('Packages', *pack_vers)
204  config.write(open('project.info', 'wb'))
205 
206  if new_version != old_version:
207  # update the global release notes
208  new_lines = []
209  new_lines.append("<!-- ====================================================================== -->")
210  data = { "vers": new_version, "date": time.strftime("%Y-%m-%d") }
211  new_lines.append('<h2><a name="%(vers)s">Gaudi %(vers)s</a> (%(date)s)</h2>' % data)
212  data = { "vers": HEPToolsVers }
213  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)
214  new_lines.append("<h3>General Changes</h3>")
215  new_lines.append('<ul>\n<li><br/>\n (<span class="author"></span>)</li>\n</ul>')
216  new_lines.append("<h3>Packages Changes</h3>")
217  new_lines.append("<ul>")
218  for pkg in release_notes:
219  if release_notes[pkg]:
220  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]))
221  new_lines.append(release_notes[pkg].replace('&','&amp;') \
222  .replace('<','&lt;') \
223  .replace('>','&gt;') + "</pre>")
224  new_lines.append("</li>")
225  new_lines.append("</ul>")
226 
227  global_rel_notes = os.path.join("GaudiRelease", "doc", "release.notes.html")
228  out = []
229  separator = re.compile("<!-- =+ -->")
230  block_added = False
231  for l in open(global_rel_notes):
232  if not block_added and separator.match(l.strip()):
233  out.append("\n".join(new_lines) + "\n")
234  block_added = True
235  out.append(l)
236  open(global_rel_notes, "w").writelines(out)
237 
238  # update the global CMakeLists.txt
239  out = []
240  for l in open('CMakeLists.txt'):
241  if l.strip().startswith('gaudi_project'):
242  l = 'gaudi_project(Gaudi %s)\n' % new_version
243  out.append(l)
244  open('CMakeLists.txt', "w").writelines(out)
245 

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 13 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 12 of file update_versions.py.