1 |
#!/usr/bin/python |
#!/usr/bin/python -u |
2 |
|
|
3 |
# A lot of the code comes from ftpadmin, see |
# A lot of the code comes from ftpadmin, see |
4 |
# http://git.gnome.org/browse/sysadmin-bin/tree/ftpadmin |
# http://git.gnome.org/browse/sysadmin-bin/tree/ftpadmin |
36 |
# for checking hashes |
# for checking hashes |
37 |
import hashlib |
import hashlib |
38 |
|
|
39 |
MEDIA="Core Release Source" |
# for parsing ftp-release-list emails |
40 |
URL="http://download.gnome.org/sources/" |
import email |
41 |
PKGROOT='~/pkgs' |
from email.mime.text import MIMEText |
42 |
|
|
43 |
|
# to be able to sleep for a while |
44 |
|
import time |
45 |
|
|
46 |
|
# version freeze |
47 |
|
import datetime |
48 |
|
|
49 |
|
# packages --sort |
50 |
|
import itertools |
51 |
|
|
52 |
|
# check-latest |
53 |
|
import requests |
54 |
|
|
55 |
|
SLEEP_INITIAL=180 |
56 |
|
SLEEP_REPEAT=30 |
57 |
|
SLEEP_TIMES=20 |
58 |
|
|
59 |
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
60 |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
82 |
latest = version |
latest = version |
83 |
return latest |
return latest |
84 |
|
|
85 |
|
def get_safe_max_version(version): |
86 |
|
if not re_majmin.match(version): |
87 |
|
return None |
88 |
|
|
89 |
|
majmin_nr = map(long, re_majmin.sub(r'\1', version).split('.')) |
90 |
|
|
91 |
|
if majmin_nr[1] % 2 == 0: |
92 |
|
return "%d.%d" % (majmin_nr[0], majmin_nr[1] + 1) |
93 |
|
else: |
94 |
|
return "%d.%d" % (majmin_nr[0], majmin_nr[1] + 2) |
95 |
|
|
96 |
def judge_version_increase(version_old, version_new): |
def judge_version_increase(version_old, version_new): |
97 |
"""Judge quality of version increase: |
"""Judge quality of version increase: |
98 |
|
|
108 |
compare = version_cmp(version_new, version_old) |
compare = version_cmp(version_new, version_old) |
109 |
|
|
110 |
if compare == 0: |
if compare == 0: |
111 |
|
# 1.0.0 -> 1.0.1 |
112 |
return (-2, "Already at version %s!" % (version_old)) |
return (-2, "Already at version %s!" % (version_old)) |
113 |
|
|
114 |
if compare != 1: |
if compare != 1: |
115 |
|
# 1.0.1 -> 1.0.0 |
116 |
return (-3, "Version %s is older than current version %s!" % (version_new, version_old)) |
return (-3, "Version %s is older than current version %s!" % (version_new, version_old)) |
117 |
|
|
118 |
# Version is newer, but we don't want to see if it follows the GNOME versioning scheme |
# Version is newer, but we don't want to see if it follows the GNOME versioning scheme |
133 |
# Major+minor the same? Then go ahead and upgrade! |
# Major+minor the same? Then go ahead and upgrade! |
134 |
if majmins[0] == majmins[1]: |
if majmins[0] == majmins[1]: |
135 |
# Majmin of both versions are the same, looks good! |
# Majmin of both versions are the same, looks good! |
136 |
|
# 1.1.x -> 1.1.x or 1.0.x -> 1.0.x |
137 |
return (10, None) |
return (10, None) |
138 |
|
|
139 |
# More detailed analysis needed, so figure out the numbers |
# More detailed analysis needed, so figure out the numbers |
141 |
|
|
142 |
# Check/ensure major version number is the same |
# Check/ensure major version number is the same |
143 |
if majmin_nrs[0][0] != majmin_nrs[1][0]: |
if majmin_nrs[0][0] != majmin_nrs[1][0]: |
144 |
|
# 1.0.x -> 2.0.x |
145 |
return (1, "Major version number increase") |
return (1, "Major version number increase") |
146 |
|
|
147 |
# Minor indicates stable/unstable |
# Minor indicates stable/unstable |
150 |
# Upgrading to unstable is weird |
# Upgrading to unstable is weird |
151 |
if not devstate[1]: |
if not devstate[1]: |
152 |
if devstate[0]: |
if devstate[0]: |
153 |
|
# 1.2.x -> 1.3.x |
154 |
return (1, "Stable to unstable increase") |
return (1, "Stable to unstable increase") |
155 |
|
|
156 |
|
# 1.3.x -> 1.5.x |
157 |
return (4, "Unstable to unstable version increase") |
return (4, "Unstable to unstable version increase") |
158 |
|
|
159 |
# Unstable => stable is always ok |
# Unstable => stable is always ok |
160 |
if not devstate[0]: |
if not devstate[0]: |
161 |
|
# 1.1.x -> 1.2.x |
162 |
return (5, "Unstable to stable") |
return (5, "Unstable to stable") |
163 |
|
|
164 |
# Can only be increase of minors from one stable to the next |
# Can only be increase of minors from one stable to the next |
165 |
|
# 1.0.x -> 1.2.x |
166 |
return (6, "Stable version increase") |
return (6, "Stable version increase") |
167 |
|
|
168 |
def line_input (file): |
def line_input (file): |
273 |
else spec.sources() |
else spec.sources() |
274 |
return dict((os.path.basename(name), name) for name, no, flags in srclist) |
return dict((os.path.basename(name), name) for name, no, flags in srclist) |
275 |
|
|
276 |
def update(self, version): |
def update(self, version, force=False): |
277 |
"""Update specfile (increase version)""" |
"""Update specfile (increase version)""" |
278 |
cur_version = self.version |
cur_version = self.version |
279 |
|
|
285 |
|
|
286 |
if judgement < 5: |
if judgement < 5: |
287 |
print "WARNING: %s!" % (msg) |
print "WARNING: %s!" % (msg) |
288 |
return False |
if not force: return False |
289 |
|
|
290 |
# XXX - os.path.join is hackish |
# XXX - os.path.join is hackish |
291 |
if subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) != '': |
svn_diff_output = subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) |
292 |
|
if svn_diff_output != '': |
293 |
|
print svn_diff_output |
294 |
print >>sys.stderr, "ERROR: Package has uncommitted changes!" |
print >>sys.stderr, "ERROR: Package has uncommitted changes!" |
295 |
return False |
if not force: |
296 |
|
return False |
297 |
|
|
298 |
|
# Forcing package submission: revert changes |
299 |
|
try: |
300 |
|
print >>sys.stderr, "WARNING: Force used; reverting svn changes" |
301 |
|
subprocess.check_call(["svn", "revert", "-R", os.path.join(self.path, '..')]) |
302 |
|
except subprocess.CalledProcessError: |
303 |
|
return False |
304 |
|
|
305 |
with open(self.path, "rw") as f: |
with open(self.path, "rw") as f: |
306 |
data = f.read() |
data = f.read() |
328 |
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
329 |
return False |
return False |
330 |
|
|
331 |
|
|
332 |
|
# Try to download the new tarball various times and wait between attempts |
333 |
|
tries = 0 |
334 |
|
while tries < SLEEP_TIMES: |
335 |
|
tries += 1 |
336 |
|
if tries > 1: time.sleep(SLEEP_REPEAT) |
337 |
|
try: |
338 |
|
# Download new tarball |
339 |
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
340 |
|
# success, so exit loop |
341 |
|
break |
342 |
|
except subprocess.CalledProcessError, e: |
343 |
|
# mgarepo sync returns 1 if the tarball cannot be downloaded |
344 |
|
if e.returncode != 1: |
345 |
|
return False |
346 |
|
else: |
347 |
|
return False |
348 |
|
|
349 |
|
|
350 |
try: |
try: |
|
# Download new tarball |
|
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
|
351 |
# Check patches still apply |
# Check patches still apply |
352 |
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
353 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
354 |
|
logfile = os.path.join(os.path.dirname(self.path), 'log.%s' % os.path.splitext(os.path.basename(self.path))[0]) |
355 |
|
if os.path.exists(logfile): |
356 |
|
subprocess.call(['tail', '-n', '15', logfile]) |
357 |
return False |
return False |
358 |
|
|
359 |
return True |
return True |
498 |
|
|
499 |
return self._svn_author |
return self._svn_author |
500 |
|
|
|
def get_upstream_names(): |
|
|
urlopen = urllib2.build_opener() |
|
501 |
|
|
502 |
good_dir = re.compile('^[-A-Za-z0-9_+.]+/$') |
class Upstream(object): |
503 |
|
|
504 |
|
URL="http://download.gnome.org/sources/" |
505 |
|
limit = None |
506 |
|
_cache_versions = {} |
507 |
|
|
508 |
|
def __init__(self): |
509 |
|
urlopen = urllib2.build_opener() |
510 |
|
|
511 |
|
good_dir = re.compile('^[-A-Za-z0-9_+.]+/$') |
512 |
|
|
513 |
|
# Get the files |
514 |
|
usock = urlopen.open(self.URL) |
515 |
|
parser = urllister() |
516 |
|
parser.feed(usock.read()) |
517 |
|
usock.close() |
518 |
|
parser.close() |
519 |
|
files = parser.urls |
520 |
|
|
521 |
|
tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)]) |
522 |
|
if self.limit is not None: |
523 |
|
tarballs.intersection_update(self.limit) |
524 |
|
|
525 |
|
self.names = tarballs |
526 |
|
|
527 |
# Get the files |
@classmethod |
528 |
usock = urlopen.open(URL) |
def versions(cls, module): |
529 |
parser = urllister() |
# XXX - ugly |
530 |
parser.feed(usock.read()) |
if module not in cls._cache_versions: |
531 |
usock.close() |
versions = None |
532 |
parser.close() |
|
533 |
files = parser.urls |
url = '%s%s/cache.json' % (cls.URL, module) |
534 |
|
r = requests.get(url) |
535 |
|
j = r.json |
536 |
|
if j is not None and len(j) > 2 and module in j[2]: |
537 |
|
versions = j[2][module] |
538 |
|
|
539 |
tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)]) |
cls._cache_versions[module] = versions |
540 |
|
|
541 |
return tarballs |
return cls._cache_versions[module] |
542 |
|
|
543 |
def get_downstream_names(): |
class Downstream(object): |
544 |
re_file = re.compile(r'^(?P<module>.*?)[_-](?:(?P<oldversion>([0-9]+[\.])*[0-9]+)-)?(?P<version>([0-9]+[\.\-])*[0-9]+)\.(?P<format>(?:tar\.|diff\.)?[a-z][a-z0-9]*)$') |
re_file = re.compile(r'^(?P<module>.*?)[_-](?:(?P<oldversion>([0-9]+[\.])*[0-9]+)-)?(?P<version>([0-9]+[\.\-])*[0-9]+)\.(?P<format>(?:tar\.|diff\.)?[a-z][a-z0-9]*)$') |
545 |
|
|
546 |
contents = subprocess.check_output(['urpmf', '--files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines() |
MEDIA="Core Release Source" |
547 |
|
PKGROOT='~/pkgs' |
548 |
|
DISTRO=None |
549 |
|
|
550 |
FILES = {} |
def __init__(self): |
551 |
TARBALLS = {} |
contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", self.MEDIA], close_fds=True).strip("\n").splitlines() |
552 |
|
|
553 |
for line in contents: |
FILES = {} |
554 |
try: |
TARBALLS = {} |
|
srpm, filename = line.split(":") |
|
|
except ValueError: |
|
|
print >>sys.stderr, line |
|
|
continue |
|
555 |
|
|
556 |
if '.tar' in filename: |
for line in contents: |
557 |
r = re_file.match(filename) |
try: |
558 |
if r: |
srpm, version, filename = line.split("|") |
559 |
fileinfo = r.groupdict() |
except ValueError: |
560 |
module = fileinfo['module'] |
print >>sys.stderr, line |
561 |
|
continue |
|
if module not in TARBALLS: |
|
|
TARBALLS[module] = set() |
|
|
TARBALLS[module].add(srpm) |
|
|
|
|
|
if srpm not in FILES: |
|
|
FILES[srpm] = set() |
|
|
FILES[srpm].add(filename) |
|
562 |
|
|
563 |
return TARBALLS, FILES |
if '.tar' in filename: |
564 |
|
r = self.re_file.match(filename) |
565 |
|
if r: |
566 |
|
fileinfo = r.groupdict() |
567 |
|
module = fileinfo['module'] |
568 |
|
|
569 |
|
if module not in TARBALLS: |
570 |
|
TARBALLS[module] = {} |
571 |
|
TARBALLS[module][srpm] = version |
572 |
|
|
573 |
|
if srpm not in FILES: |
574 |
|
FILES[srpm] = set() |
575 |
|
FILES[srpm].add(filename) |
576 |
|
|
577 |
|
self.tarballs = TARBALLS |
578 |
|
self.files = FILES |
579 |
|
|
580 |
|
@classmethod |
581 |
|
def co(cls, package, cwd=None): |
582 |
|
if cwd is None: |
583 |
|
cwd = os.path.expanduser(cls.PKGROOT) |
584 |
|
|
585 |
|
cmd = ['mgarepo', 'co'] |
586 |
|
if cls.DISTRO: |
587 |
|
cmd.extend(('-d', cls.DISTRO)) |
588 |
|
cmd.append(package) |
589 |
|
return subprocess.check_call(cmd, cwd=cwd) |
590 |
|
|
591 |
|
def get_downstream_from_upstream(self, upstream, version): |
592 |
|
if upstream not in self.tarballs: |
593 |
|
raise ValueError("No packages for upstream name: %s" % upstream) |
594 |
|
|
595 |
|
if len(self.tarballs[upstream]) == 1: |
596 |
|
return self.tarballs[upstream].keys() |
597 |
|
|
598 |
|
# Directories packages are located in |
599 |
|
root = os.path.expanduser(self.PKGROOT) |
600 |
|
|
601 |
|
packages = {} |
602 |
|
for package in self.tarballs[upstream].keys(): |
603 |
|
cwd = os.path.join(root, package) |
604 |
|
|
605 |
|
# Checkout package to ensure the checkout reflects the latest changes |
606 |
|
try: |
607 |
|
self.co(package, cwd=root) |
608 |
|
except subprocess.CalledProcessError: |
609 |
|
raise ValueError("Multiple packages found and cannot checkout %s" % package) |
610 |
|
|
611 |
|
# Determine version from spec file |
612 |
|
try: |
613 |
|
packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
614 |
|
except subprocess.CalledProcessError: |
615 |
|
raise ValueError("Multiple packages found and cannot determine version of %s" % package) |
616 |
|
|
617 |
|
# Return all packages reflecting the current version |
618 |
|
matches = [package for package in packages if packages[package] == version] |
619 |
|
if len(matches): |
620 |
|
return matches |
621 |
|
|
622 |
|
# Return all packages reflecting the version before the current version |
623 |
|
latest_version = get_latest_version(packages.values(), max_version=version) |
624 |
|
matches = [package for package in packages if packages[package] == latest_version] |
625 |
|
if len(matches): |
626 |
|
return matches |
627 |
|
|
628 |
|
# Give up |
629 |
|
raise ValueError("Multiple packages found and cannot determine package for version %s" % version) |
630 |
|
|
631 |
def write_file(path, data): |
def write_file(path, data): |
632 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
635 |
os.rename(fdst.name, path) |
os.rename(fdst.name, path) |
636 |
|
|
637 |
def cmd_co(options, parser): |
def cmd_co(options, parser): |
638 |
upstream = get_upstream_names() |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
639 |
downstream, downstream_files = get_downstream_names() |
print "%s => %s" % (module, package) |
640 |
|
try: |
641 |
|
Downstream.co(package) |
642 |
|
except subprocess.CalledProcessError: |
643 |
|
pass |
644 |
|
|
645 |
cwd = os.path.expanduser(PKGROOT) |
def join_streams(show_version=False, only_diff_version=False): |
646 |
|
root = os.path.expanduser(Downstream.PKGROOT) |
647 |
|
|
648 |
matches = upstream & set(downstream.keys()) |
upstream = Upstream().names |
649 |
for module in matches: |
downstream = Downstream() |
|
print module, "\t".join(downstream[module]) |
|
|
for package in downstream[module]: |
|
|
subprocess.call(['mgarepo', 'co', package], cwd=cwd) |
|
|
|
|
|
def join_streams(): |
|
|
upstream = get_upstream_names() |
|
|
downstream, downstream_files = get_downstream_names() |
|
650 |
|
|
651 |
matches = upstream & set(downstream.keys()) |
matches = upstream & set(downstream.tarballs.keys()) |
652 |
for module in matches: |
for module in matches: |
653 |
for package in downstream[module]: |
for package in downstream.tarballs[module].keys(): |
654 |
yield (package, module) |
package_version = downstream.tarballs[module][package] |
655 |
|
spec_version = None |
656 |
|
if show_version or only_diff_version: |
657 |
|
cwd = os.path.join(root, package) |
658 |
|
try: |
659 |
|
spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
660 |
|
except subprocess.CalledProcessError: |
661 |
|
spec_version = 'N/A' |
662 |
|
|
663 |
|
if only_diff_version and package_version == spec_version: |
664 |
|
continue |
665 |
|
|
666 |
|
yield (package, module, package_version, spec_version, downstream.files[package]) |
667 |
|
|
668 |
def cmd_ls(options, parser): |
def cmd_ls(options, parser): |
669 |
for package, module in sorted(join_streams()): |
streams = join_streams(show_version=options.show_version, only_diff_version=options.diff) |
670 |
print "\t".join((package, module)) if options.upstream else package |
if options.sort: |
671 |
|
SORT=dict(zip(options.sort.read().splitlines(), itertools.count())) |
672 |
|
|
673 |
def cmd_patches(options, parser): |
streams = sorted(streams, key=lambda a: (SORT.get(a[1], 9999), a[0])) |
674 |
upstream = get_upstream_names() |
else: |
675 |
downstream, downstream_files = get_downstream_names() |
streams = sorted(streams) |
676 |
|
|
677 |
path = os.path.expanduser(PKGROOT) |
for package, module, package_version, spec_version, downstream_files in streams: |
678 |
|
sys.stdout.write(package) |
679 |
|
if options.upstream: sys.stdout.write("\t%s" % module) |
680 |
|
if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version)) |
681 |
|
print |
682 |
|
|
683 |
|
def cmd_check_latest(options, parser): |
684 |
|
streams = join_streams(show_version=True) |
685 |
|
|
686 |
|
for package, module, package_version, spec_version, downstream_files in streams: |
687 |
|
sys.stdout.write(package) |
688 |
|
sys.stdout.write("\t%s\t%s" % (spec_version, package_version)) |
689 |
|
|
690 |
|
safe_max_version = get_safe_max_version(spec_version) |
691 |
|
|
692 |
|
versions = Upstream.versions(module) |
693 |
|
if versions: |
694 |
|
latest_version = get_latest_version(versions) |
695 |
|
safe_version = get_latest_version(versions, safe_max_version) |
696 |
|
|
697 |
|
if version_cmp(latest_version, spec_version) < 0: latest_version = 'N/A' |
698 |
|
if version_cmp(safe_version, spec_version) < 0: safe_version = 'N/A' |
699 |
|
|
700 |
|
sys.stdout.write("\t%s" % latest_version) |
701 |
|
sys.stdout.write("\t%s" % safe_version) |
702 |
|
print |
703 |
|
|
704 |
import pprint |
def cmd_patches(options, parser): |
705 |
|
root = os.path.expanduser(Downstream.PKGROOT) |
706 |
|
|
707 |
matches = upstream & set(downstream.keys()) |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
708 |
for module in sorted(matches): |
for filename in downstream_files: |
709 |
for srpm in downstream[module]: |
if '.patch' in filename or '.diff' in filename: |
710 |
for filename in downstream_files[srpm]: |
|
711 |
if '.patch' in filename or '.diff' in filename: |
p = Patch(os.path.join(root, package, "SOURCES", filename), show_path=options.path) |
712 |
|
valid = "" |
713 |
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path) |
forwarded = "" |
714 |
valid = "" |
if p.dep3['headers']: |
715 |
forwarded = "" |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
716 |
if p.dep3['headers']: |
if p.dep3['valid']: |
717 |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
valid="VALID" |
718 |
if p.dep3['valid']: |
print "\t".join((module, package, str(p), forwarded, valid)) |
|
valid="VALID" |
|
|
print "\t".join((module, srpm, str(p), forwarded, valid)) |
|
719 |
|
|
720 |
def cmd_dep3(options, parser): |
def cmd_dep3(options, parser): |
721 |
p = Patch(options.patch) |
p = Patch(options.patch) |
724 |
def cmd_package_new_version(options, parser): |
def cmd_package_new_version(options, parser): |
725 |
# Determine the package name |
# Determine the package name |
726 |
if options.upstream: |
if options.upstream: |
727 |
downstream, downstream_files = get_downstream_names() |
try: |
728 |
|
package = Downstream().get_downstream_from_upstream(options.package, options.version)[0] |
729 |
if options.package not in downstream: |
except ValueError, e: |
730 |
print >>sys.stderr, "ERROR: No packages for upstream name: %s" % options.package |
print >>sys.stderr, "ERROR: %s" % e |
|
sys.exit(1) |
|
|
|
|
|
if len(downstream[options.package]) != 1: |
|
|
# XXX - Make it more intelligent |
|
|
print >>sys.stderr, "ERROR: Multiple packages found for %s: %s" % (options.package, ", ".join(downstream[options.package])) |
|
731 |
sys.exit(1) |
sys.exit(1) |
|
|
|
|
package = list(downstream[options.package])[0] |
|
732 |
else: |
else: |
733 |
package = options.package |
package = options.package |
734 |
|
|
735 |
# Directories packages are located in |
# Directories packages are located in |
736 |
root = os.path.expanduser(PKGROOT) |
root = os.path.expanduser(Downstream.PKGROOT) |
737 |
cwd = os.path.join(root, package) |
cwd = os.path.join(root, package) |
738 |
|
|
739 |
# Checkout package to ensure the checkout reflects the latest changes |
# Checkout package to ensure the checkout reflects the latest changes |
740 |
try: |
try: |
741 |
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
Downstream.co(package, cwd=root) |
742 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
743 |
sys.exit(1) |
sys.exit(1) |
744 |
|
|
745 |
# SpecFile class handles the actual version+release change |
# SpecFile class handles the actual version+release change |
746 |
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
747 |
print "%s => %s" % (s.version, options.version) |
print "%s => %s" % (s.version, options.version) |
748 |
if not s.update(options.version): |
if not s.update(options.version, force=options.force): |
749 |
sys.exit(1) |
sys.exit(1) |
750 |
|
|
751 |
# Check hash, if given |
# Check hash, if given |
756 |
sys.stderr(1) |
sys.stderr(1) |
757 |
|
|
758 |
for filename in sources: |
for filename in sources: |
759 |
if not is_valid_hash(os.path.join(cwd, "SOURCES", filename), options.algo, options.hexdigest): |
path = os.path.join(cwd, "SOURCES", filename) |
760 |
|
if not is_valid_hash(path, options.algo, options.hexdigest): |
761 |
print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path |
print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path |
762 |
print >>sys.stderr, "ERROR: Reverting changes!" |
print >>sys.stderr, "ERROR: Reverting changes!" |
763 |
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd) |
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd) |
764 |
sys.exit(1) |
sys.exit(1) |
765 |
|
|
766 |
# We can even checkin and submit :-) |
try: |
767 |
if options.submit: |
# If we made it this far, checkin the changes |
768 |
try: |
subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd) |
769 |
# checkin changes |
|
770 |
subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd) |
# Submit is optional |
771 |
# and submit |
if options.submit: |
772 |
subprocess.check_call(['mgarepo', 'submit'], cwd=cwd) |
cmd = ['mgarepo', 'submit'] |
773 |
except subprocess.CalledProcessError: |
if Downstream.DISTRO: |
774 |
sys.exit(1) |
cmd.extend(('--define', 'section=core/updates_testing', '-t', Downstream.DISTRO)) |
775 |
|
subprocess.check_call(cmd, cwd=cwd) |
776 |
|
except subprocess.CalledProcessError: |
777 |
|
sys.exit(1) |
778 |
|
|
779 |
|
def cmd_parse_ftp_release_list(options, parser): |
780 |
|
def _send_reply_mail(contents, orig_msg, to, packages=[], error=False): |
781 |
|
"""Send an reply email""" |
782 |
|
contents.seek(0) |
783 |
|
msg = MIMEText(contents.read(), _charset='utf-8') |
784 |
|
|
785 |
|
if error: |
786 |
|
# XXX - ugly |
787 |
|
contents.seek(0) |
788 |
|
lastline = contents.read().rstrip().splitlines()[-1] |
789 |
|
# Remove things like "ERROR: " and so on from the last line |
790 |
|
lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline) |
791 |
|
# Remove things like " - " (youri output from mgarepo submit) |
792 |
|
lastline = re.sub(r'^\s+-\s+', '', lastline) |
793 |
|
subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)" |
794 |
|
else: |
795 |
|
subjecterror = "" |
796 |
|
|
797 |
|
if packages: |
798 |
|
subject = "%s %s%s" % (", ".join(packages), orig_msg['X-Module-Version'], subjecterror) |
799 |
|
else: |
800 |
|
subject = "Re: %s%s" % (orig_msg['Subject'], subjecterror) |
801 |
|
|
802 |
|
msg['Subject'] = subject |
803 |
|
msg['To'] = to |
804 |
|
msg["In-Reply-To"] = orig_msg["Message-ID"] |
805 |
|
msg["References"] = orig_msg["Message-ID"] |
806 |
|
|
807 |
|
# Call sendmail program directly so it doesn't matter if the service is running |
808 |
|
cmd = ['/usr/sbin/sendmail', '-oi', '--'] |
809 |
|
cmd.extend([to]) |
810 |
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE) |
811 |
|
p.stdin.write(msg.as_string()) |
812 |
|
p.stdin.flush() |
813 |
|
p.stdin.close() |
814 |
|
p.wait() |
815 |
|
|
816 |
|
|
817 |
|
msg = email.email.message_from_file(sys.stdin) |
818 |
|
|
819 |
|
if options.mail: |
820 |
|
stdout = tempfile.TemporaryFile() |
821 |
|
stderr = stdout |
822 |
|
else: |
823 |
|
stdout = sys.stdout |
824 |
|
stderr = sys.stderr |
825 |
|
|
826 |
|
try: |
827 |
|
module = msg['X-Module-Name'] |
828 |
|
version = msg['X-Module-Version'] |
829 |
|
hexdigest = msg['X-Module-SHA256-tar.xz'] |
830 |
|
except KeyError, e: |
831 |
|
print >>stderr, "ERROR: %s" % e |
832 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
833 |
|
sys.exit(1) |
834 |
|
|
835 |
|
try: |
836 |
|
packages = Downstream().get_downstream_from_upstream(module, version) |
837 |
|
except ValueError, e: |
838 |
|
print >>stderr, "ERROR: %s" % e |
839 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
840 |
|
sys.exit(1) |
841 |
|
|
842 |
|
if options.wait: |
843 |
|
# maildrop aborts and will try to deliver after 5min |
844 |
|
# fork to avoid this |
845 |
|
if os.fork() != 0: sys.exit(0) |
846 |
|
# wait SLEEP_INITIAL after the message was sent |
847 |
|
secs = SLEEP_INITIAL |
848 |
|
t = email.utils.parsedate_tz(msg['Date']) |
849 |
|
if t is not None: |
850 |
|
msg_time = email.utils.mktime_tz(t) |
851 |
|
secs = SLEEP_INITIAL - (time.time() - msg_time) |
852 |
|
|
853 |
|
if secs > 0: time.sleep(secs) |
854 |
|
|
855 |
|
error = False |
856 |
|
for package in packages: |
857 |
|
cmd = ['mga-gnome', 'increase', '--hash', hexdigest] |
858 |
|
if options.submit: |
859 |
|
cmd.append('--submit') |
860 |
|
if options.force: |
861 |
|
cmd.append('--force') |
862 |
|
cmd.extend((package, version)) |
863 |
|
if subprocess.call(cmd, stdout=stdout, stderr=stderr): |
864 |
|
error = True |
865 |
|
|
866 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail, packages=packages, error=error) |
867 |
|
|
868 |
def main(): |
def main(): |
869 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
870 |
epilog="""Report bugs to Olav Vitters""" |
epilog="""Report bugs to Olav Vitters""" |
871 |
parser = argparse.ArgumentParser(description=description,epilog=epilog) |
parser = argparse.ArgumentParser(description=description,epilog=epilog) |
872 |
|
parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0), |
873 |
|
dest="limit_upstream", metavar="FILE", |
874 |
|
help="File containing upstream names") |
875 |
|
parser.add_argument("-d", "--distro", action="store", dest="distro", |
876 |
|
help="Distribution release") |
877 |
|
|
878 |
# SUBPARSERS |
# SUBPARSERS |
879 |
subparsers = parser.add_subparsers(title='subcommands') |
subparsers = parser.add_subparsers(title='subcommands') |
886 |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
887 |
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
888 |
help="Show upstream module") |
help="Show upstream module") |
889 |
|
subparser.add_argument( "--version", action="store_true", dest="show_version", |
890 |
|
help="Show version numbers") |
891 |
|
subparser.add_argument( "--diff", action="store_true", dest="diff", |
892 |
|
help="Only show packages with different version") |
893 |
|
subparser.add_argument( "--sort", type=argparse.FileType('r', 0), |
894 |
|
dest="sort", metavar="FILE", |
895 |
|
help="Sort packages according to order in given FILE") |
896 |
|
|
897 |
subparser.set_defaults( |
subparser.set_defaults( |
898 |
func=cmd_ls, upstream=False |
func=cmd_ls, upstream=False, show_version=False, diff=False |
899 |
|
) |
900 |
|
|
901 |
|
subparser = subparsers.add_parser('check-latest', help='check for latest version of packages') |
902 |
|
subparser.set_defaults( |
903 |
|
func=cmd_check_latest |
904 |
) |
) |
905 |
|
|
906 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
919 |
subparser = subparsers.add_parser('increase', help='Increase version number') |
subparser = subparsers.add_parser('increase', help='Increase version number') |
920 |
subparser.add_argument("package", help="Package name") |
subparser.add_argument("package", help="Package name") |
921 |
subparser.add_argument("version", help="Version number") |
subparser.add_argument("version", help="Version number") |
922 |
|
subparser.add_argument("-f", "--force", action="store_true", dest="force", |
923 |
|
help="Override warnings, just do it") |
924 |
subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream", |
subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream", |
925 |
help="Package name reflects the upstream name") |
help="Package name reflects the upstream name") |
926 |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
930 |
subparser.add_argument("--hash", dest="hexdigest", |
subparser.add_argument("--hash", dest="hexdigest", |
931 |
help="Hexdigest of the hash") |
help="Hexdigest of the hash") |
932 |
subparser.set_defaults( |
subparser.set_defaults( |
933 |
func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256" |
func=cmd_package_new_version, submit=True, upstream=False, hexdigest=None, algo="sha256", |
934 |
|
force=False |
935 |
|
) |
936 |
|
|
937 |
|
subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email') |
938 |
|
subparser.add_argument("-m", "--mail", help="Email address to send the progress to") |
939 |
|
subparser.add_argument("-w", "--wait", action="store_true", |
940 |
|
help="Wait before trying to retrieve the new version") |
941 |
|
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
942 |
|
help="Commit changes and submit") |
943 |
|
subparser.add_argument("-f", "--force", action="store_true", |
944 |
|
help="Force submission") |
945 |
|
subparser.set_defaults( |
946 |
|
func=cmd_parse_ftp_release_list, force=False, wait=False |
947 |
) |
) |
948 |
|
|
949 |
if len(sys.argv) == 1: |
if len(sys.argv) == 1: |
951 |
sys.exit(2) |
sys.exit(2) |
952 |
|
|
953 |
options = parser.parse_args() |
options = parser.parse_args() |
954 |
|
if options.limit_upstream: |
955 |
|
Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines()) |
956 |
|
|
957 |
|
if options.distro: |
958 |
|
Downstream.PKGROOT = os.path.join('~/pkgs', options.distro) |
959 |
|
Downstream.MEDIA = "Core Release %s Source" % options.distro |
960 |
|
Downstream.DISTRO = options.distro |
961 |
|
|
962 |
try: |
try: |
963 |
options.func(options, parser) |
options.func(options, parser) |
973 |
sys.exit(0) |
sys.exit(0) |
974 |
|
|
975 |
if __name__ == "__main__": |
if __name__ == "__main__": |
976 |
|
os.environ['PYTHONUNBUFFERED'] = '1' |
977 |
main() |
main() |