summaryrefslogtreecommitdiffstats
path: root/mgagnome
diff options
context:
space:
mode:
authorOlav Vitters <ovitters@mageia.org>2012-02-22 16:06:51 +0000
committerOlav Vitters <ovitters@mageia.org>2012-02-22 16:06:51 +0000
commitd83ff17e3bbcc85853ee24a9e142253ee925fc0a (patch)
tree74fb85a6d8a39f4d29d11f8408a9bd59c6dcedd9 /mgagnome
parent412acd5a103eca4a8f703c661960f3e086a32d24 (diff)
downloadmgagnome-d83ff17e3bbcc85853ee24a9e142253ee925fc0a.tar
mgagnome-d83ff17e3bbcc85853ee24a9e142253ee925fc0a.tar.gz
mgagnome-d83ff17e3bbcc85853ee24a9e142253ee925fc0a.tar.bz2
mgagnome-d83ff17e3bbcc85853ee24a9e142253ee925fc0a.tar.xz
mgagnome-d83ff17e3bbcc85853ee24a9e142253ee925fc0a.zip
Add ability to increase the version number of a given package
Command tries to be careful and does various checks (patches still apply, etc)
Diffstat (limited to 'mgagnome')
-rwxr-xr-xmgagnome142
1 files changed, 139 insertions, 3 deletions
diff --git a/mgagnome b/mgagnome
index 7441623..1b4b8a5 100755
--- a/mgagnome
+++ b/mgagnome
@@ -17,6 +17,57 @@ MEDIA="Core Release Source"
URL="http://download.gnome.org/sources/"
PKGROOT='~/pkgs'
+re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')
+
+def version_cmp(a, b):
+ """Compares two versions
+
+ Returns
+ -1 if a < b
+ 0 if a == b
+ 1 if a > b
+
+ Logic from Bugzilla::Install::Util::vers_cmp"""
+ A = re_version.findall(a.lstrip('0'))
+ B = re_version.findall(b.lstrip('0'))
+
+ while A and B:
+ a = A.pop(0)
+ b = B.pop(0)
+
+ if a == b:
+ continue
+ elif a == '-':
+ return -1
+ elif b == '-':
+ return 1
+ elif a == '.':
+ return -1
+ elif b == '.':
+ return 1
+ elif a.isdigit() and b.isdigit():
+ c = cmp(a, b) if (a.startswith('0') or b.startswith('0')) else cmp(int(a, 10), int(b, 10))
+ if c:
+ return c
+ else:
+ c = cmp(a.upper(), b.upper())
+ if c:
+ return c
+
+ return cmp(len(A), len(B))
+
+def get_latest_version(versions, max_version=None):
+ """Gets the latest version number
+
+ if max_version is specified, gets the latest version number before
+ max_version"""
+ latest = None
+ for version in versions:
+ if ( latest is None or version_cmp(version, latest) > 0 ) \
+ and ( max_version is None or version_cmp(version, max_version) < 0 ):
+ latest = version
+ return latest
+
def line_input (file):
for line in file:
if line[-1] == '\n':
@@ -58,6 +109,58 @@ class urllister(SGMLParser):
if href:
self.urls.extend(href)
+class SpecFile(object):
+ re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
+ re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
+
+ def __init__(self, path):
+ self.path = path
+ self.cwd = os.path.dirname(path)
+
+ @property
+ def version(self):
+ return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0]
+ def update(self, version):
+ """Update specfile (increase version)"""
+ cur_version = self.version
+
+ if version_cmp(version, cur_version) != 1:
+ print >>sys.stderr, "ERROR: Version %s is older than current version %s!" % (version, cur_version)
+ return False
+
+ with open(self.path, "rw") as f:
+ data = f.read()
+
+ if data.count("%mkrel") != 1:
+ print "WARNING: Multiple %mkrel found; don't know what to do!"
+ return False
+
+ data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1)
+ if nr != 1:
+ print "WARNING: Could not increase version!"
+ return False
+
+ data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1)
+ if nr != 1:
+ print "WARNING: Could not reset release!"
+ return False
+
+ # Overwrite file with new version number
+ write_file(self.path, data)
+
+
+ # Check RPM also agrees that version number has increased
+ if self.version != version:
+ print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version
+ return False
+
+ # Download new tarball
+ subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)
+ # Check patches still apply
+ subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd)
+
+ return True
+
class Patch(object):
"""Do things with patches"""
@@ -137,6 +240,11 @@ class Patch(object):
r = self.re_dep3.match(line)
if r:
info = r.groupdict()
+
+ # Avoid matching URLS
+ if info['data'].startswith('//') and info['header'].lower () == info['header']:
+ continue
+
headers[info['header']] = info['data']
last_header = info['header']
last_nr = nr
@@ -244,6 +352,13 @@ def get_downstream_names():
return TARBALLS, FILES
+
+def write_file(path, data):
+ with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst:
+ fdst.write(data)
+ fdst.flush()
+ os.rename(fdst.name, path)
+
def cmd_co(options, parser):
upstream = get_upstream_names()
downstream, downstream_files = get_downstream_names()
@@ -277,17 +392,31 @@ def cmd_patches(options, parser):
for srpm in downstream[module]:
for filename in downstream_files[srpm]:
if '.patch' in filename or '.diff' in filename:
+
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path)
- print "\t".join((module, srpm, str(p)))
+ valid = ""
+ forwarded = ""
if p.dep3['headers']:
- pprint.pprint(p.dep3['headers'])
+ forwarded = p.dep3['headers'].get('Forwarded', "no")
if p.dep3['valid']:
- print "VALID"
+ valid="VALID"
+ print "\t".join((module, srpm, str(p), forwarded, valid))
def cmd_dep3(options, parser):
p = Patch(options.patch)
p.add_dep3()
+def cmd_package_new_version(options, parser):
+ cwd = os.path.expanduser(PKGROOT)
+ package = options.package
+
+ subprocess.call(['mgarepo', 'co', package], cwd=cwd)
+ s = SpecFile(os.path.join(cwd, package, "SPECS", "%s.spec" % package))
+ print s.version
+ if not s.update(options.version):
+ sys.exit(1)
+
+
def main():
description = """Mageia GNOME commands."""
epilog="""Report bugs to Olav Vitters"""
@@ -319,6 +448,13 @@ def main():
func=cmd_dep3, path=False
)
+ subparser = subparsers.add_parser('increase', help='Increase version number')
+ subparser.add_argument("package", help="Package name")
+ subparser.add_argument("version", help="Version number")
+ subparser.set_defaults(
+ func=cmd_package_new_version, path=False
+ )
+
if len(sys.argv) == 1:
parser.print_help()
sys.exit(2)