diff options
author | Frederic Lepied <flepied@mandriva.com> | 2005-12-07 10:06:33 +0000 |
---|---|---|
committer | Frederic Lepied <flepied@mandriva.com> | 2005-12-07 10:06:33 +0000 |
commit | 2c78c40c9bfae22d1501022b2e52cf938b5a957e (patch) | |
tree | 33a030236dd735f665e7b1ff1a9fba203742ecc0 /RepSys/log.py | |
parent | aa9174bf0cce8d6a3c6e4d9e795be717da184406 (diff) | |
download | mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.tar mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.tar.gz mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.tar.bz2 mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.tar.xz mgarepo-2c78c40c9bfae22d1501022b2e52cf938b5a957e.zip |
Initial revisionR1_5_3_1-4mdktopic/V1_5_X@821topic/V1_5_X@819topic/V1_5_3@959topic/V1_5_3@819topic/V1_5_3
Diffstat (limited to 'RepSys/log.py')
-rw-r--r-- | RepSys/log.py | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/RepSys/log.py b/RepSys/log.py new file mode 100644 index 0000000..fa007fa --- /dev/null +++ b/RepSys/log.py @@ -0,0 +1,100 @@ +#!/usr/bin/python +from RepSys import Error, config +from RepSys.svn import SVN +import tempfile +import shutil +import time +import os + +def svn2rpm(pkgdirurl, rev=None, size=None): + concat = config.get("log", "concat", "").split() + svn = SVN() + log = svn.log(os.path.join(pkgdirurl, "current"), start=rev) + if (size is not None): + log = log[:size] + rpmlog = [] + lastauthor = None + for logentry in log: + entryheader = [] + if lastauthor != logentry.author or \ + not (logentry.author in concat or "*" in concat): + entryheader.append(time.strftime("* %a %b %d %Y ", logentry.date)) + entryheader.append(config.get("users", logentry.author, + logentry.author)) + entryheader.append("\n") + entryheader.append(time.strftime("+ %Y-%m-%d %H:%M:%S", + logentry.date)) + entryheader.append(" (%d)" % logentry.revision) + if lastauthor: + rpmlog.append("") + lastauthor = logentry.author + entrylines = [] + first = 1 + for line in logentry.lines: + if line: + line = line.replace("%", "%%") + if first: + first = 0 + if entryheader: + rpmlog.append("".join(entryheader)) + line = line.lstrip() + if line[0] != "-": + nextline = "- " + line + else: + nextline = line + elif line[0] != " " and line[0] != "-": + nextline = " " + line + else: + nextline = line + if nextline not in entrylines: + rpmlog.append(nextline) + entrylines.append(nextline) + return "\n".join(rpmlog)+"\n" + +def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None): + file = open(specfile) + lines = file.readlines() + file.close() + newlines = [] + found = 0 + + # Strip old changelogs + for line in lines: + if line.startswith("%changelog"): + found = 1 + elif not found: + newlines.append(line) + elif line.startswith("%"): + found = 0 + newlines.append(line) + + # Create new changelog + newlines.append("\n\n%changelog\n") + newlines.append(svn2rpm(pkgdirurl, rev, size)) + + # Merge old changelog, if available + oldurl = config.get("log", "oldurl") + if oldurl: + svn = SVN() + tmpdir = tempfile.mktemp() + try: + pkgname = os.path.basename(pkgdirurl) + pkgoldurl = os.path.join(oldurl, pkgname) + if svn.ls(pkgoldurl, noerror=1): + svn.checkout(pkgoldurl, tmpdir, rev=rev) + logfile = os.path.join(tmpdir, "log") + if os.path.isfile(logfile): + file = open(logfile) + newlines.append("\n") + newlines.append(file.read()) + file.close() + finally: + if os.path.isdir(tmpdir): + shutil.rmtree(tmpdir) + + # Write new specfile + file = open(specfile, "w") + file.writelines(newlines) + file.close() + +# vim:et:ts=4:sw=4 |