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

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

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

Definition at line 13 of file update_versions.py.

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

Definition at line 114 of file update_versions.py.

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

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.