3 Script to prepare the release of Gaudi.
5 @author Marco Clemencic
13 from subprocess
import Popen, PIPE
15 _VK_RE = re.compile(
r'(\d+|\D+)')
18 Key function to be passes to list.sort() to sort strings
21 return [int(i)
if i[0]
in '0123456789' else i
22 for i
in _VK_RE.split(
'v10r31')
27 Return the latest Gaudi tag (of the format "GAUDI/GAUDI_*").
29 logging.info(
'looking for latest tag')
31 logging.debug(
'using command %r', cmd)
32 proc = Popen(cmd, stdout=PIPE)
33 output = proc.communicate()[0]
35 for tag
in output.splitlines()
36 if tag.startswith(
'GAUDI/GAUDI_')]
38 tags.sort(key=versionKey)
39 logging.info(
'found %s', tags[-1])
41 logging.info(
'no valid tag found')
45 Return the release notes (in the old LHCb format) extracted from git
46 commits for a given path.
49 '--first-parent',
'--date=short',
50 '--pretty=format:! %ad - commit %h%n%n%w(80,1,3)- %s%n%n%b%n']
52 cmd.append(
'{0}..{1}'.
format(from_tag, branch
or ''))
57 logging.info(
'preparing release notes for %s%s', path,
58 ' since ' + from_tag
if from_tag
else '')
59 logging.debug(
'using command %r', cmd)
60 proc = Popen(cmd, stdout=PIPE)
61 return proc.communicate()[0]
65 Smartly prepend the content of notes to the release.notes file in path.
67 notes_filename = os.path.join(path,
'doc',
'release.notes')
68 logging.info(
'updating %s', notes_filename)
69 from itertools
import takewhile, dropwhile
70 def dropuntil(predicate, iterable):
71 return dropwhile(
lambda x:
not predicate(x), iterable)
72 with open(notes_filename)
as notes_file:
73 orig_data = iter(list(notes_file))
74 header = takewhile(str.strip, orig_data)
75 with open(notes_filename,
'w')
as notes_file:
76 notes_file.writelines(header)
77 notes_file.write(
'\n')
78 notes_file.writelines(l.rstrip() +
'\n' for l
in notes.splitlines())
79 notes_file.writelines(dropuntil(re.compile(
r'^!?============').match, orig_data))
82 _req_version_pattern = re.compile(
r"^\s*version\s*(v[0-9]+r[0-9]+(?:p[0-9]+)?)\s*$")
83 _cml_version_pattern = re.compile(
r"^\s*gaudi_subdir\s*\(\s*\S+\s+(v[0-9]+r[0-9]+(?:p[0-9]+)?)\)\s*$")
86 Find the version number of a subdirectory.
88 global _cml_version_pattern
89 for l
in open(os.path.join(path,
'CMakeLists.txt')):
90 m = _cml_version_pattern.match(l)
96 if os.path.exists(cml):
100 m = _cml_version_pattern.match(l)
101 if m
and m.group(1) != newversion:
102 logging.debug(
'%s: %s -> %s', cml, m.group(1), newversion)
103 l = l.replace(m.group(1), newversion)
107 open(cml,
"w").writelines(out)
111 Compare the version of the package with the new one and update the package if
114 Returns true if the package have been modified.
116 global _req_version_pattern
119 req = os.path.join(packagedir,
'cmt',
'requirements')
121 m = _req_version_pattern.match(l)
123 if m.group(1) != newversion:
124 logging.debug(
'%s: %s -> %s', packagedir, m.group(1), newversion)
125 l = l.replace(m.group(1),newversion)
129 open(req,
"w").writelines(out)
131 ver = os.path.join(packagedir,
"version.cmt")
132 if os.path.exists(ver):
133 current = open(ver).read().strip()
134 if current != newversion:
135 open(ver,
"w").write(newversion +
"\n")
137 cml = os.path.normpath(os.path.join(packagedir,
'CMakeLists.txt'))
139 if 'GaudiKernel' in packagedir:
140 cml = os.path.normpath(os.path.join(packagedir,
'src',
'Util',
'CMakeLists.txt'))
145 title =
' %s %s ' % (pkg, version)
146 letf_chars = (78 - len(title)) / 2
147 right_chars = 78 - letf_chars - len(title)
148 separator = (
'=' * letf_chars) + title + (
'=' * right_chars)
152 logging.basicConfig(level=logging.DEBUG)
154 for path
in [d
for d
in os.listdir(os.curdir)
155 if os.path.exists(os.path.join(d,
'doc',
'release.notes'))]:
157 (
tag_bar(path, new_versions[path]) +
'\n\n'
158 if path
in new_versions
164 logging.basicConfig(level=logging.DEBUG)
166 os.chdir(os.path.dirname(os.path.dirname(__file__)))
169 for l
in open(
'toolchain.cmake'):
170 m = re.match(
r'^\s*set\(\s*heptools_version\s+(\S*)\s*\)', l)
172 HEPToolsVers = m.group(1)
173 print "Using HEPTools", HEPToolsVers
176 logging.error(
'Cannot find HEPTools version')
181 for dirpath, dirnames, filenames
in os.walk(os.curdir):
182 if 'CMakeLists.txt' in filenames
and dirpath != os.curdir:
186 dirnames[:] = [dirname
for dirname
in dirnames
187 if not dirname.startswith(
'build.')
and
191 special_subdirs = [
"Gaudi",
"GaudiExamples",
"GaudiSys",
"GaudiRelease"]
196 old_version = latest_tag.split(
'_')[-1]
197 new_version = raw_input(
"The old version of the project is %s, which is the new one? " % old_version)
203 for pkgdir
in all_subdirs():
204 cmlfile = os.path.join(pkgdir,
'CMakeLists.txt')
205 reqfile = os.path.join(pkgdir,
'cmt',
'requirements')
207 pkg = os.path.basename(pkgdir)
211 if pkg
in special_subdirs:
214 git_log = Popen([
'git',
'log',
'-m',
'--first-parent',
215 '--stat', latest_tag +
'..master', pkgdir],
216 stdout=PIPE).communicate()[0].strip()
218 msg = (
'\nThe old version of {0} is {1}, these are the changes:\n'
220 'Which version you want (old is {1})? ').
format(pkg,
223 vers = raw_input(msg)
224 while not vers
or vers == old_vers:
225 vers = raw_input(
'give me a version')
231 new_versions[pkg] = vers
or old_vers
235 reqfile = os.path.join(
'GaudiRelease',
'cmt',
'requirements')
237 for l
in open(reqfile):
238 sl = l.strip().split()
239 if sl
and sl[0] ==
"use":
240 if sl[1]
in new_versions:
241 if sl[2] != new_versions[sl[1]]:
242 l = l.replace(sl[2], new_versions[sl[1]])
244 open(reqfile,
"w").writelines(out)
246 config = ConfigParser.ConfigParser()
247 config.optionxform = str
248 if os.path.exists(
'project.info'):
249 config.read(
'project.info')
250 if not config.has_section(
'Packages'):
251 config.add_section(
'Packages')
252 for pack_vers
in sorted(new_versions.items()):
253 config.set(
'Packages', *pack_vers)
254 config.write(open(
'project.info',
'wb'))
258 for l
in open(
'CMakeLists.txt'):
259 if l.strip().startswith(
'gaudi_project'):
260 l =
'gaudi_project(Gaudi %s)\n' % new_version
262 open(
'CMakeLists.txt',
"w").writelines(out)
265 if __name__ ==
'__main__':
def updateReleaseNotes(path, notes)
def change_cml_version(cml, newversion)
def extract_version(path)
def change_version(packagedir, newversion)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".