diff options
author | Bogdano Arendartchuk <bogdano@mandriva.org> | 2008-03-03 21:06:55 +0000 |
---|---|---|
committer | Bogdano Arendartchuk <bogdano@mandriva.org> | 2008-03-03 21:06:55 +0000 |
commit | 3be56dcf69b2edca96aaf68cce75608649b6572e (patch) | |
tree | dfc9223f9bb2a8f2c20ff9453c4a6dee700ae52c | |
parent | 1e929f67375b699cdcac0b1557d115eed7035ae8 (diff) | |
download | mgarepo-3be56dcf69b2edca96aaf68cce75608649b6572e.tar mgarepo-3be56dcf69b2edca96aaf68cce75608649b6572e.tar.gz mgarepo-3be56dcf69b2edca96aaf68cce75608649b6572e.tar.bz2 mgarepo-3be56dcf69b2edca96aaf68cce75608649b6572e.tar.xz mgarepo-3be56dcf69b2edca96aaf68cce75608649b6572e.zip |
Add configuration option to sort the generated changelog
The boolean option "sort" in the [log] section can be used to make repsys
sort all the entries after generating the changelog from svn and
concatenating with the one found in "misc/".
It was also added another option to merge the log found in the spec (those
that don't have the %changelog section stripped).
The current problem with this implementation is that SILENTed entries in
svn will not be merged with those found in %changelog or in misc. Not a
problem really.
-rw-r--r-- | RepSys/log.py | 67 |
1 files changed, 56 insertions, 11 deletions
diff --git a/RepSys/log.py b/RepSys/log.py index 60cf0d5..4a74716 100644 --- a/RepSys/log.py +++ b/RepSys/log.py @@ -8,6 +8,8 @@ try: except ImportError: raise Error, "repsys requires the package python-cheetah" +from cStringIO import StringIO + import sys import os import re @@ -464,11 +466,41 @@ def svn2rpm(pkgdirurl, rev=None, size=None, submit=False, data = dump_file(releases[::-1], currentlog=currentlog, template=template) return data +def _split_changelog(stream): + current = None + count = 0 + for line in stream: + if line.startswith("*"): + if current: + yield current + fields = line.split() + rawdate = " ".join(fields[:5]) + try: + date = time.strptime(rawdate, "* %a %b %d %Y") + except ValueError, e: + raise Error, "failed to parse spec changelog: %s" % e + curlines = [line] + current = (date, -count, curlines) + count += 1 # used to ensure stable sorting when using tuples + elif current: + curlines.append(line) + else: + pass # not good, but ignore + if current: + yield current +def sort_changelog(stream): + entries = list(_split_changelog(stream)) + log = StringIO() + for time, count, elines in sorted(entries, reverse=True): + log.writelines(elines) + return log def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None, - submit=False, template=None, macros=[], exported=None): - newlines = [] + submit=False, sort=False, template=None, macros=[], exported=None): + oldspec = StringIO() + newlog = StringIO() + oldlog = StringIO() found = 0 # Strip old changelogs @@ -476,15 +508,17 @@ def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None, if line.startswith("%changelog"): found = 1 elif not found: - newlines.append(line) + oldspec.write(line) + elif found: + oldlog.write(line) elif line.startswith("%"): found = 0 - newlines.append(line) + oldspec.write(line) - # Create new changelog - newlines.append("\n\n%changelog\n") - newlines.append(svn2rpm(pkgdirurl, rev=rev, size=size, submit=submit, - template=template, macros=macros, exported=exported)) + rawsvnlog = svn2rpm(pkgdirurl, rev=rev, size=size, submit=submit, + template=template, macros=macros, + exported=exported) + newlog.write(rawsvnlog) # Merge old changelog, if available oldurl = config.get("log", "oldurl") @@ -504,18 +538,29 @@ def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None, logfile = os.path.join(tmpdir, "log") if os.path.isfile(logfile): file = open(logfile) - newlines.append("\n") + newlog.write("\n") # TODO needed? log = file.read() log = escape_macros(log) - newlines.append(log) + newlog.write(log) file.close() finally: if os.path.isdir(tmpdir): shutil.rmtree(tmpdir) + if sort or config.getbool("log", "sort", False): + if config.getbool("log", "merge-spec", False): + oldlog.seek(0) + newlog.writelines(oldlog) + newlog.seek(0) + newlog = sort_changelog(newlog) + # Write new specfile + newlog.seek(0) + oldspec.seek(0) file = open(specfile, "w") - file.write("".join(newlines)) + file.writelines(oldspec) + file.write("\n\n%changelog\n") + file.writelines(newlog) file.close() |