prepare_gaudi_release Namespace Reference

Functions

def checkGitVersion ()
 
def versionKey (x)
 
def findLatestTag ()
 
def releaseNotes
 
def updateReleaseNotes (path, notes)
 
def extract_version (path)
 
def change_cml_version (cml, newversion)
 
def change_version (packagedir, newversion)
 
def tag_bar
 
def newmain ()
 
def main ()
 

Variables

tuple _VK_RE = re.compile(r'(\d+|\D+)')
 
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 prepare_gaudi_release.change_cml_version (   cml,
  newversion 
)

Definition at line 110 of file prepare_gaudi_release.py.

110 def change_cml_version(cml, newversion):
111  if os.path.exists(cml):
112  out = []
113  changed = False
114  for l in open(cml):
115  m = _cml_version_pattern.match(l)
116  if m and m.group(1) != newversion:
117  logging.debug('%s: %s -> %s', cml, m.group(1), newversion)
118  l = l.replace(m.group(1), newversion)
119  changed = True
120  out.append(l)
121  if changed:
122  open(cml, "w").writelines(out)
123 
def change_cml_version(cml, newversion)
def prepare_gaudi_release.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 124 of file prepare_gaudi_release.py.

124 def change_version(packagedir, newversion):
125  """
126  Compare the version of the package with the new one and update the package if
127  needed.
128 
129  Returns true if the package have been modified.
130  """
131  global _req_version_pattern
132  changed = False
133  out = []
134  req = os.path.join(packagedir, 'cmt', 'requirements')
135  for l in open(req):
136  m = _req_version_pattern.match(l)
137  if m:
138  if m.group(1) != newversion:
139  logging.debug('%s: %s -> %s', packagedir, m.group(1), newversion)
140  l = l.replace(m.group(1),newversion)
141  changed = True
142  out.append(l)
143  if changed:
144  open(req,"w").writelines(out)
145  # verify the version.cmt file
146  ver = os.path.join(packagedir,"version.cmt")
147  if os.path.exists(ver):
148  current = open(ver).read().strip()
149  if current != newversion:
150  open(ver,"w").write(newversion + "\n")
151  # update CMakeLists.txt
152  cml = os.path.normpath(os.path.join(packagedir, 'CMakeLists.txt'))
153  change_cml_version(cml, newversion)
154  if 'GaudiKernel' in packagedir:
155  cml = os.path.normpath(os.path.join(packagedir, 'src', 'Util', 'CMakeLists.txt'))
156  change_cml_version(cml, newversion)
157  return changed
158 
def change_cml_version(cml, newversion)
def change_version(packagedir, newversion)
def prepare_gaudi_release.checkGitVersion ( )
Ensure we have a usable version of Git (>= 1.7.9.1).

See:
* https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/1.7.9.1.txt
* https://github.com/git/git/commit/36ed1913e1d5de0930e59db6eeec3ccb2bd58bd9

Definition at line 15 of file prepare_gaudi_release.py.

16  '''
17  Ensure we have a usable version of Git (>= 1.7.9.1).
18 
19  See:
20  * https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/1.7.9.1.txt
21  * https://github.com/git/git/commit/36ed1913e1d5de0930e59db6eeec3ccb2bd58bd9
22  '''
23  proc = Popen(['git', '--version'], stdout=PIPE)
24  version = proc.communicate()[0].split()[-1]
25  if proc.returncode:
26  raise RuntimeError('could not get git version')
27  if versionKey(version) < versionKey('1.7.9.1'):
28  raise RuntimeError('bad version of git found: %s (1.7.9.1 required)' % version)
29 
def prepare_gaudi_release.extract_version (   path)
Find the version number of a subdirectory.

Definition at line 99 of file prepare_gaudi_release.py.

99 def extract_version(path):
100  """
101  Find the version number of a subdirectory.
102  """
103  global _cml_version_pattern
104  for l in open(os.path.join(path, 'CMakeLists.txt')):
105  m = _cml_version_pattern.match(l)
106  if m:
107  return m.group(1)
108  return None
109 
def prepare_gaudi_release.findLatestTag ( )
Return the latest Gaudi tag (of the format "GAUDI/GAUDI_*").

Definition at line 40 of file prepare_gaudi_release.py.

41  '''
42  Return the latest Gaudi tag (of the format "GAUDI/GAUDI_*").
43  '''
44  logging.info('looking for latest tag')
45  cmd = ['git', 'tag']
46  logging.debug('using command %r', cmd)
47  proc = Popen(cmd, stdout=PIPE)
48  output = proc.communicate()[0]
49  tags = [tag
50  for tag in output.splitlines()
51  if tag.startswith('GAUDI/GAUDI_')]
52  if tags:
53  tags.sort(key=versionKey)
54  logging.info('found %s', tags[-1])
55  return tags[-1]
56  logging.info('no valid tag found')
57 
def prepare_gaudi_release.main ( )

Definition at line 178 of file prepare_gaudi_release.py.

178 def main():
179  logging.basicConfig(level=logging.DEBUG)
180  os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
181  # Find the version of HEPTools (LCG)
182  for l in open('toolchain.cmake'):
183  m = re.match(r'^\s*set\(\s*heptools_version\s+(\S*)\s*\)', l)
184  if m:
185  HEPToolsVers = m.group(1)
186  print "Using HEPTools", HEPToolsVers
187  break
188  else:
189  logging.error('Cannot find HEPTools version')
190  sys.exit(1)
191 
192  # Collect all the packages in the project with their directory
193  def all_subdirs():
194  for dirpath, dirnames, filenames in os.walk(os.curdir):
195  if 'CMakeLists.txt' in filenames and dirpath != os.curdir:
196  dirnames[:] = []
197  yield dirpath
198  else:
199  dirnames[:] = [dirname for dirname in dirnames
200  if not dirname.startswith('build.') and
201  dirname != 'cmake']
202 
203  # Packages which version must match the version of the project
204  special_subdirs = ["Gaudi", "GaudiExamples", "GaudiSys", "GaudiRelease"]
205 
206  # Ask for the version of the project
207  latest_tag = findLatestTag()
208 
209  old_version = latest_tag.split('_')[-1]
210  new_version = raw_input("The old version of the project is %s, which is the new one? " % old_version)
211 
212  old_versions = {}
213  release_notes = {}
214  new_versions = {}
215  # for each package in the project check if there were changes and ask for the new version number
216  for pkgdir in all_subdirs():
217  cmlfile = os.path.join(pkgdir, 'CMakeLists.txt')
218  reqfile = os.path.join(pkgdir, 'cmt', 'requirements')
219 
220  pkg = os.path.basename(pkgdir)
221  old_vers = extract_version(pkgdir)
222 
223  vers = None
224  if pkg in special_subdirs:
225  vers = new_version
226  else:
227  git_log = Popen(['git', 'log', '-m', '--first-parent',
228  '--stat', latest_tag + '..master', pkgdir],
229  stdout=PIPE).communicate()[0].strip()
230  if git_log:
231  msg = ('\nThe old version of {0} is {1}, these are the changes:\n'
232  '{2}\n'
233  'Which version you want (old is {1})? ').format(pkg,
234  old_vers,
235  git_log)
236  vers = raw_input(msg)
237  while not vers or vers == old_vers:
238  vers = raw_input('give me a version, please. ')
239  if vers:
240  change_version(pkgdir, vers)
241  updateReleaseNotes(pkgdir,
242  tag_bar(pkg, vers) + '\n\n' +
243  releaseNotes(pkgdir, latest_tag, 'master'))
244  new_versions[pkg] = vers or old_vers
245  print "=" * 80
246 
247  # The changes in the GaudiRelease requirements for the other packages can be postponed to now
248  reqfile = os.path.join('GaudiRelease', 'cmt', 'requirements')
249  out = []
250  for l in open(reqfile):
251  sl = l.strip().split()
252  if sl and sl[0] == "use":
253  if sl[1] in new_versions:
254  if sl[2] != new_versions[sl[1]]:
255  l = l.replace(sl[2], new_versions[sl[1]])
256  out.append(l)
257  open(reqfile, "w").writelines(out)
258  # Update project.info
259  config = ConfigParser.ConfigParser()
260  config.optionxform = str # make the options case sensitive
261  if os.path.exists('project.info'):
262  config.read('project.info')
263  if not config.has_section('Packages'):
264  config.add_section('Packages')
265  for pack_vers in sorted(new_versions.items()):
266  config.set('Packages', *pack_vers)
267  config.write(open('project.info', 'wb'))
268 
269  # update the global CMakeLists.txt
270  out = []
271  for l in open('CMakeLists.txt'):
272  if l.strip().startswith('gaudi_project'):
273  l = 'gaudi_project(Gaudi %s)\n' % new_version
274  out.append(l)
275  open('CMakeLists.txt', "w").writelines(out)
276 
277 
def updateReleaseNotes(path, notes)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
def change_version(packagedir, newversion)
def prepare_gaudi_release.newmain ( )

Definition at line 166 of file prepare_gaudi_release.py.

166 def newmain():
167  logging.basicConfig(level=logging.DEBUG)
168  latest_tag = findLatestTag()
169  for path in [d for d in os.listdir(os.curdir)
170  if os.path.exists(os.path.join(d, 'doc', 'release.notes'))]:
171  updateReleaseNotes(path,
172  (tag_bar(path, new_versions[path]) + '\n\n'
173  if path in new_versions
174  else '') +
175  releaseNotes(path, latest_tag, 'master'))
176 
177 
def updateReleaseNotes(path, notes)
def prepare_gaudi_release.releaseNotes (   path = os.curdir,
  from_tag = None,
  branch = None 
)
Return the release notes (in the old LHCb format) extracted from git
commits for a given path.

Definition at line 58 of file prepare_gaudi_release.py.

58 def releaseNotes(path=os.curdir, from_tag=None, branch=None):
59  '''
60  Return the release notes (in the old LHCb format) extracted from git
61  commits for a given path.
62  '''
63  cmd = ['git', 'log',
64  '--first-parent', '--date=short',
65  '--pretty=format:! %ad - commit %h%n%n%w(80,1,3)- %s%n%n%b%n']
66  if from_tag:
67  cmd.append('{0}..{1}'.format(from_tag, branch or ''))
68  elif branch:
69  cmd.append(branch)
70  cmd.append('--')
71  cmd.append(path)
72  logging.info('preparing release notes for %s%s', path,
73  ' since ' + from_tag if from_tag else '')
74  logging.debug('using command %r', cmd)
75  proc = Popen(cmd, stdout=PIPE)
76  return proc.communicate()[0]
77 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
def prepare_gaudi_release.tag_bar (   pkg,
  version = None 
)

Definition at line 159 of file prepare_gaudi_release.py.

159 def tag_bar(pkg, version=None):
160  title = ' %s %s ' % (pkg, version)
161  letf_chars = (78 - len(title)) / 2
162  right_chars = 78 - letf_chars - len(title)
163  separator = ('=' * letf_chars) + title + ('=' * right_chars)
164  return separator
165 
def prepare_gaudi_release.updateReleaseNotes (   path,
  notes 
)
Smartly prepend the content of notes to the release.notes file in path.

Definition at line 78 of file prepare_gaudi_release.py.

78 def updateReleaseNotes(path, notes):
79  '''
80  Smartly prepend the content of notes to the release.notes file in path.
81  '''
82  notes_filename = os.path.join(path, 'doc', 'release.notes')
83  logging.info('updating %s', notes_filename)
84  from itertools import takewhile, dropwhile
85  def dropuntil(predicate, iterable):
86  return dropwhile(lambda x: not predicate(x), iterable)
87  with open(notes_filename) as notes_file:
88  orig_data = iter(list(notes_file))
89  header = takewhile(str.strip, orig_data)
90  with open(notes_filename, 'w') as notes_file:
91  notes_file.writelines(header)
92  notes_file.write('\n')
93  notes_file.writelines(l.rstrip() + '\n' for l in notes.splitlines())
94  notes_file.writelines(dropuntil(re.compile(r'^!?============').match, orig_data))
95 
96 # guess current version
def updateReleaseNotes(path, notes)
def prepare_gaudi_release.versionKey (   x)
Key function to be passes to list.sort() to sort strings
as version numbers.

Definition at line 31 of file prepare_gaudi_release.py.

31 def versionKey(x):
32  '''
33  Key function to be passes to list.sort() to sort strings
34  as version numbers.
35  '''
36  return [int(i) if i[0] in '0123456789' else i
37  for i in _VK_RE.split(x)
38  if i]
39 

Variable Documentation

tuple prepare_gaudi_release._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 98 of file prepare_gaudi_release.py.

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

Definition at line 97 of file prepare_gaudi_release.py.

tuple prepare_gaudi_release._VK_RE = re.compile(r'(\d+|\D+)')

Definition at line 30 of file prepare_gaudi_release.py.