11 |
import errno |
import errno |
12 |
import tempfile |
import tempfile |
13 |
import shutil |
import shutil |
14 |
|
import rpm |
15 |
from sgmllib import SGMLParser |
from sgmllib import SGMLParser |
16 |
|
|
17 |
MEDIA="Core Release Source" |
MEDIA="Core Release Source" |
18 |
URL="http://download.gnome.org/sources/" |
URL="http://download.gnome.org/sources/" |
19 |
PKGROOT='~/pkgs' |
PKGROOT='~/pkgs' |
20 |
|
|
21 |
|
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
22 |
|
|
23 |
|
def version_cmp(a, b): |
24 |
|
"""Compares two versions |
25 |
|
|
26 |
|
Returns |
27 |
|
-1 if a < b |
28 |
|
0 if a == b |
29 |
|
1 if a > b |
30 |
|
""" |
31 |
|
|
32 |
|
return rpm.labelCompare(('1', a, '1'), ('1', b, '1')) |
33 |
|
|
34 |
|
def get_latest_version(versions, max_version=None): |
35 |
|
"""Gets the latest version number |
36 |
|
|
37 |
|
if max_version is specified, gets the latest version number before |
38 |
|
max_version""" |
39 |
|
latest = None |
40 |
|
for version in versions: |
41 |
|
if ( latest is None or version_cmp(version, latest) > 0 ) \ |
42 |
|
and ( max_version is None or version_cmp(version, max_version) < 0 ): |
43 |
|
latest = version |
44 |
|
return latest |
45 |
|
|
46 |
def line_input (file): |
def line_input (file): |
47 |
for line in file: |
for line in file: |
48 |
if line[-1] == '\n': |
if line[-1] == '\n': |
84 |
if href: |
if href: |
85 |
self.urls.extend(href) |
self.urls.extend(href) |
86 |
|
|
87 |
|
class SpecFile(object): |
88 |
|
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
89 |
|
re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
90 |
|
|
91 |
|
def __init__(self, path): |
92 |
|
self.path = path |
93 |
|
self.cwd = os.path.dirname(path) |
94 |
|
|
95 |
|
@property |
96 |
|
def version(self): |
97 |
|
return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0] |
98 |
|
|
99 |
|
def update(self, version): |
100 |
|
"""Update specfile (increase version)""" |
101 |
|
cur_version = self.version |
102 |
|
|
103 |
|
compare = version_cmp(version, cur_version) |
104 |
|
|
105 |
|
if compare == 0: |
106 |
|
print >>sys.stderr, "ERROR: Already at version %s!" % (cur_version) |
107 |
|
return False |
108 |
|
|
109 |
|
if compare != 1: |
110 |
|
print >>sys.stderr, "ERROR: Version %s is older than current version %s!" % (version, cur_version) |
111 |
|
return False |
112 |
|
|
113 |
|
# XXX - os.path.join is hackish |
114 |
|
if subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) != '': |
115 |
|
print >>sys.stderr, "ERROR: Package has uncommitted changes!" |
116 |
|
return False |
117 |
|
|
118 |
|
with open(self.path, "rw") as f: |
119 |
|
data = f.read() |
120 |
|
|
121 |
|
if data.count("%mkrel") != 1: |
122 |
|
print >>sys.stderr, "ERROR: Multiple %mkrel found; don't know what to do!" |
123 |
|
return False |
124 |
|
|
125 |
|
data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1) |
126 |
|
if nr != 1: |
127 |
|
print >>sys.stderr, "ERROR: Could not increase version!" |
128 |
|
return False |
129 |
|
|
130 |
|
data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1) |
131 |
|
if nr != 1: |
132 |
|
print >>sys.stderr, "ERROR: Could not reset release!" |
133 |
|
return False |
134 |
|
|
135 |
|
# Overwrite file with new version number |
136 |
|
write_file(self.path, data) |
137 |
|
|
138 |
|
|
139 |
|
# Verify that RPM also agrees that version number has changed |
140 |
|
if self.version != version: |
141 |
|
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
142 |
|
return False |
143 |
|
|
144 |
|
try: |
145 |
|
# Download new tarball |
146 |
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
147 |
|
# Check patches still apply |
148 |
|
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
149 |
|
except subprocess.CalledProcessError: |
150 |
|
return False |
151 |
|
|
152 |
|
return True |
153 |
|
|
154 |
class Patch(object): |
class Patch(object): |
155 |
"""Do things with patches""" |
"""Do things with patches""" |
156 |
|
|
230 |
r = self.re_dep3.match(line) |
r = self.re_dep3.match(line) |
231 |
if r: |
if r: |
232 |
info = r.groupdict() |
info = r.groupdict() |
233 |
|
|
234 |
|
# Avoid matching URLS |
235 |
|
if info['data'].startswith('//') and info['header'].lower () == info['header']: |
236 |
|
continue |
237 |
|
|
238 |
headers[info['header']] = info['data'] |
headers[info['header']] = info['data'] |
239 |
last_header = info['header'] |
last_header = info['header'] |
240 |
last_nr = nr |
last_nr = nr |
342 |
|
|
343 |
return TARBALLS, FILES |
return TARBALLS, FILES |
344 |
|
|
345 |
|
|
346 |
|
def write_file(path, data): |
347 |
|
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
348 |
|
fdst.write(data) |
349 |
|
fdst.flush() |
350 |
|
os.rename(fdst.name, path) |
351 |
|
|
352 |
def cmd_co(options, parser): |
def cmd_co(options, parser): |
353 |
upstream = get_upstream_names() |
upstream = get_upstream_names() |
354 |
downstream, downstream_files = get_downstream_names() |
downstream, downstream_files = get_downstream_names() |
382 |
for srpm in downstream[module]: |
for srpm in downstream[module]: |
383 |
for filename in downstream_files[srpm]: |
for filename in downstream_files[srpm]: |
384 |
if '.patch' in filename or '.diff' in filename: |
if '.patch' in filename or '.diff' in filename: |
385 |
|
|
386 |
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path) |
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path) |
387 |
print "\t".join((module, srpm, str(p))) |
valid = "" |
388 |
|
forwarded = "" |
389 |
if p.dep3['headers']: |
if p.dep3['headers']: |
390 |
pprint.pprint(p.dep3['headers']) |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
391 |
if p.dep3['valid']: |
if p.dep3['valid']: |
392 |
print "VALID" |
valid="VALID" |
393 |
|
print "\t".join((module, srpm, str(p), forwarded, valid)) |
394 |
|
|
395 |
def cmd_dep3(options, parser): |
def cmd_dep3(options, parser): |
396 |
p = Patch(options.patch) |
p = Patch(options.patch) |
397 |
p.add_dep3() |
p.add_dep3() |
398 |
|
|
399 |
|
def cmd_package_new_version(options, parser): |
400 |
|
package = options.package |
401 |
|
|
402 |
|
root = os.path.expanduser(PKGROOT) |
403 |
|
cwd = os.path.join(root, package) |
404 |
|
|
405 |
|
try: |
406 |
|
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
407 |
|
except subprocess.CalledProcessError: |
408 |
|
sys.exit(1) |
409 |
|
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
410 |
|
print "%s => %s" % (s.version, options.version) |
411 |
|
if not s.update(options.version): |
412 |
|
sys.exit(1) |
413 |
|
|
414 |
|
if options.submit: |
415 |
|
try: |
416 |
|
# checkin changes |
417 |
|
subprocess.check_call(['mgarepo', 'ci', '-m', 'new version'], cwd=cwd) |
418 |
|
# and submit |
419 |
|
subprocess.check_call(['mgarepo', 'submit'], cwd=cwd) |
420 |
|
except subprocess.CalledProcessError: |
421 |
|
sys.exit(1) |
422 |
|
|
423 |
|
|
424 |
def main(): |
def main(): |
425 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
426 |
epilog="""Report bugs to Olav Vitters""" |
epilog="""Report bugs to Olav Vitters""" |
452 |
func=cmd_dep3, path=False |
func=cmd_dep3, path=False |
453 |
) |
) |
454 |
|
|
455 |
|
subparser = subparsers.add_parser('increase', help='Increase version number') |
456 |
|
subparser.add_argument("package", help="Package name") |
457 |
|
subparser.add_argument("version", help="Version number") |
458 |
|
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
459 |
|
help="Commit changes and submit") |
460 |
|
subparser.set_defaults( |
461 |
|
func=cmd_package_new_version, submit=False |
462 |
|
) |
463 |
|
|
464 |
if len(sys.argv) == 1: |
if len(sys.argv) == 1: |
465 |
parser.print_help() |
parser.print_help() |
466 |
sys.exit(2) |
sys.exit(2) |