43 |
# to be able to sleep for a while |
# to be able to sleep for a while |
44 |
import time |
import time |
45 |
|
|
46 |
|
# version freeze |
47 |
|
import datetime |
48 |
|
|
49 |
MEDIA="Core Release Source" |
MEDIA="Core Release Source" |
50 |
URL="http://download.gnome.org/sources/" |
URL="http://download.gnome.org/sources/" |
51 |
PKGROOT='~/pkgs' |
PKGROOT='~/pkgs' |
52 |
SLEEP_INITIAL=300 |
SLEEP_INITIAL=180 |
53 |
|
SLEEP_REPEAT=30 |
54 |
|
SLEEP_TIMES=20 |
55 |
|
|
56 |
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
57 |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
259 |
else spec.sources() |
else spec.sources() |
260 |
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) |
261 |
|
|
262 |
def update(self, version): |
def update(self, version, force=False): |
263 |
"""Update specfile (increase version)""" |
"""Update specfile (increase version)""" |
264 |
cur_version = self.version |
cur_version = self.version |
265 |
|
|
271 |
|
|
272 |
if judgement < 5: |
if judgement < 5: |
273 |
print "WARNING: %s!" % (msg) |
print "WARNING: %s!" % (msg) |
274 |
return False |
if not force: return False |
275 |
|
|
276 |
# XXX - os.path.join is hackish |
# XXX - os.path.join is hackish |
277 |
if subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) != '': |
svn_diff_output = subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) |
278 |
|
if svn_diff_output != '': |
279 |
|
print svn_diff_output |
280 |
print >>sys.stderr, "ERROR: Package has uncommitted changes!" |
print >>sys.stderr, "ERROR: Package has uncommitted changes!" |
281 |
return False |
if not force: |
282 |
|
return False |
283 |
|
|
284 |
|
# Forcing package submission: revert changes |
285 |
|
try: |
286 |
|
print >>sys.stderr, "WARNING: Force used; reverting svn changes" |
287 |
|
subprocess.check_call(["svn", "revert", "-R", os.path.join(self.path, '..')]) |
288 |
|
except subprocess.CalledProcessError: |
289 |
|
return False |
290 |
|
|
291 |
with open(self.path, "rw") as f: |
with open(self.path, "rw") as f: |
292 |
data = f.read() |
data = f.read() |
314 |
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
315 |
return False |
return False |
316 |
|
|
317 |
|
|
318 |
|
# Try to download the new tarball various times and wait between attempts |
319 |
|
tries = 0 |
320 |
|
while tries < SLEEP_TIMES: |
321 |
|
tries += 1 |
322 |
|
if tries > 1: time.sleep(SLEEP_REPEAT) |
323 |
|
try: |
324 |
|
# Download new tarball |
325 |
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
326 |
|
# success, so exit loop |
327 |
|
break |
328 |
|
except subprocess.CalledProcessError, e: |
329 |
|
# mgarepo sync returns 1 if the tarball cannot be downloaded |
330 |
|
if e.returncode != 1: |
331 |
|
return False |
332 |
|
else: |
333 |
|
return False |
334 |
|
|
335 |
|
|
336 |
try: |
try: |
|
# Download new tarball |
|
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
|
337 |
# Check patches still apply |
# Check patches still apply |
338 |
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
339 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
340 |
|
# XXX tail -n 15 SPECS/log.$PACKAGE |
341 |
return False |
return False |
342 |
|
|
343 |
return True |
return True |
502 |
def get_downstream_names(): |
def get_downstream_names(): |
503 |
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]*)$') |
504 |
|
|
505 |
contents = subprocess.check_output(['urpmf', '--files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines() |
contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines() |
506 |
|
|
507 |
FILES = {} |
FILES = {} |
508 |
TARBALLS = {} |
TARBALLS = {} |
509 |
|
|
510 |
for line in contents: |
for line in contents: |
511 |
try: |
try: |
512 |
srpm, filename = line.split(":") |
srpm, version, filename = line.split("|") |
513 |
except ValueError: |
except ValueError: |
514 |
print >>sys.stderr, line |
print >>sys.stderr, line |
515 |
continue |
continue |
521 |
module = fileinfo['module'] |
module = fileinfo['module'] |
522 |
|
|
523 |
if module not in TARBALLS: |
if module not in TARBALLS: |
524 |
TARBALLS[module] = set() |
TARBALLS[module] = {} |
525 |
TARBALLS[module].add(srpm) |
TARBALLS[module][srpm] = version |
526 |
|
|
527 |
if srpm not in FILES: |
if srpm not in FILES: |
528 |
FILES[srpm] = set() |
FILES[srpm] = set() |
537 |
if upstream not in downstream: |
if upstream not in downstream: |
538 |
raise ValueError("No packages for upstream name: %s" % upstream) |
raise ValueError("No packages for upstream name: %s" % upstream) |
539 |
|
|
540 |
if len(downstream[upstream]) != 1: |
if len(downstream[upstream]) == 1: |
541 |
# XXX - Make it more intelligent |
return downstream[upstream].keys() |
542 |
raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream]))) |
|
543 |
|
# Directories packages are located in |
544 |
|
root = os.path.expanduser(PKGROOT) |
545 |
|
|
546 |
|
packages = {} |
547 |
|
for package in downstream[upstream].keys(): |
548 |
|
cwd = os.path.join(root, package) |
549 |
|
|
550 |
|
# Checkout package to ensure the checkout reflects the latest changes |
551 |
|
try: |
552 |
|
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
553 |
|
except subprocess.CalledProcessError: |
554 |
|
raise ValueError("Multiple packages found and cannot checkout %s" % package) |
555 |
|
|
556 |
|
# Determine version from spec file |
557 |
|
try: |
558 |
|
packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
559 |
|
except subprocess.CalledProcessError: |
560 |
|
raise ValueError("Multiple packages found and cannot determine version of %s" % package) |
561 |
|
|
562 |
|
# Return all packages reflecting the current version |
563 |
|
matches = [package for package in packages if packages[package] == version] |
564 |
|
if len(matches): |
565 |
|
return matches |
566 |
|
|
567 |
|
# Return all packages reflecting the version before the current version |
568 |
|
latest_version = get_latest_version(packages.values(), max_version=version) |
569 |
|
matches = [package for package in packages if packages[package] == latest_version] |
570 |
|
if len(matches): |
571 |
|
return matches |
572 |
|
|
573 |
return list(downstream[upstream]) |
# Give up |
574 |
|
raise ValueError("Multiple packages found and cannot determine package for version %s" % version) |
575 |
|
|
576 |
def write_file(path, data): |
def write_file(path, data): |
577 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
580 |
os.rename(fdst.name, path) |
os.rename(fdst.name, path) |
581 |
|
|
582 |
def cmd_co(options, parser): |
def cmd_co(options, parser): |
583 |
upstream = get_upstream_names() |
root = os.path.expanduser(PKGROOT) |
|
downstream, downstream_files = get_downstream_names() |
|
584 |
|
|
585 |
cwd = os.path.expanduser(PKGROOT) |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
586 |
|
print "%s => %s" % (module, package) |
587 |
|
subprocess.call(['mgarepo', 'co', package], cwd=root) |
588 |
|
|
589 |
matches = upstream & set(downstream.keys()) |
def join_streams(show_version=False, only_diff_version=False): |
590 |
for module in matches: |
root = os.path.expanduser(PKGROOT) |
|
print module, "\t".join(downstream[module]) |
|
|
for package in downstream[module]: |
|
|
subprocess.call(['mgarepo', 'co', package], cwd=cwd) |
|
591 |
|
|
|
def join_streams(): |
|
592 |
upstream = get_upstream_names() |
upstream = get_upstream_names() |
593 |
downstream, downstream_files = get_downstream_names() |
downstream, downstream_files = get_downstream_names() |
594 |
|
|
595 |
matches = upstream & set(downstream.keys()) |
matches = upstream & set(downstream.keys()) |
596 |
for module in matches: |
for module in matches: |
597 |
for package in downstream[module]: |
for package in downstream[module].keys(): |
598 |
yield (package, module) |
package_version = downstream[module][package] |
599 |
|
spec_version = None |
600 |
|
if show_version or only_diff_version: |
601 |
|
cwd = os.path.join(root, package) |
602 |
|
try: |
603 |
|
spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
604 |
|
except subprocess.CalledProcessError: |
605 |
|
spec_version = 'N/A' |
606 |
|
|
607 |
def cmd_ls(options, parser): |
if only_diff_version and package_version == spec_version: |
608 |
for package, module in sorted(join_streams()): |
continue |
|
print "\t".join((package, module)) if options.upstream else package |
|
609 |
|
|
610 |
def cmd_patches(options, parser): |
yield (package, module, package_version, spec_version, downstream_files[package]) |
|
upstream = get_upstream_names() |
|
|
downstream, downstream_files = get_downstream_names() |
|
611 |
|
|
612 |
path = os.path.expanduser(PKGROOT) |
def cmd_ls(options, parser): |
613 |
|
for package, module, package_version, spec_version, downstream_files in sorted(join_streams(show_version=options.show_version, only_diff_version=options.diff)): |
614 |
|
print package,"\t", |
615 |
|
if options.upstream: print module, "\t", |
616 |
|
if options.show_version: print spec_version, "\t", package_version, "\t", |
617 |
|
print |
618 |
|
|
619 |
import pprint |
def cmd_patches(options, parser): |
620 |
|
root = os.path.expanduser(PKGROOT) |
621 |
|
|
622 |
matches = upstream & set(downstream.keys()) |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
623 |
for module in sorted(matches): |
for filename in downstream_files: |
624 |
for srpm in downstream[module]: |
if '.patch' in filename or '.diff' in filename: |
625 |
for filename in downstream_files[srpm]: |
|
626 |
if '.patch' in filename or '.diff' in filename: |
p = Patch(os.path.join(root, package, "SOURCES", filename), show_path=options.path) |
627 |
|
valid = "" |
628 |
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path) |
forwarded = "" |
629 |
valid = "" |
if p.dep3['headers']: |
630 |
forwarded = "" |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
631 |
if p.dep3['headers']: |
if p.dep3['valid']: |
632 |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
valid="VALID" |
633 |
if p.dep3['valid']: |
print "\t".join((module, package, str(p), forwarded, valid)) |
|
valid="VALID" |
|
|
print "\t".join((module, srpm, str(p), forwarded, valid)) |
|
634 |
|
|
635 |
def cmd_dep3(options, parser): |
def cmd_dep3(options, parser): |
636 |
p = Patch(options.patch) |
p = Patch(options.patch) |
660 |
# SpecFile class handles the actual version+release change |
# SpecFile class handles the actual version+release change |
661 |
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
662 |
print "%s => %s" % (s.version, options.version) |
print "%s => %s" % (s.version, options.version) |
663 |
if not s.update(options.version): |
if not s.update(options.version, force=options.force): |
664 |
sys.exit(1) |
sys.exit(1) |
665 |
|
|
666 |
# Check hash, if given |
# Check hash, if given |
688 |
sys.exit(1) |
sys.exit(1) |
689 |
|
|
690 |
def cmd_parse_ftp_release_list(options, parser): |
def cmd_parse_ftp_release_list(options, parser): |
691 |
# XXX - not working yet |
def _send_reply_mail(contents, orig_msg, to, error=False): |
|
def _send_reply_mail(contents, orig_msg, to): |
|
692 |
"""Send an reply email""" |
"""Send an reply email""" |
693 |
contents.seek(0) |
contents.seek(0) |
694 |
msg = MIMEText(contents.read(), _charset='utf-8') |
msg = MIMEText(contents.read(), _charset='utf-8') |
695 |
msg['Subject'] = "Re: %s" % orig_msg['Subject'] |
if error: |
696 |
|
# XXX - ugly |
697 |
|
contents.seek(0) |
698 |
|
lastline = contents.read().rstrip().splitlines()[-1] |
699 |
|
# Remove things like "ERROR: " and so on from the last line |
700 |
|
lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline) |
701 |
|
subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)" |
702 |
|
else: |
703 |
|
subjecterror = "" |
704 |
|
msg['Subject'] = "Re: %s%s" % (orig_msg['Subject'], subjecterror) |
705 |
msg['To'] = to |
msg['To'] = to |
706 |
msg["In-Reply-To"] = orig_msg["Message-ID"] |
msg["In-Reply-To"] = orig_msg["Message-ID"] |
707 |
msg["References"] = orig_msg["Message-ID"] |
msg["References"] = orig_msg["Message-ID"] |
719 |
msg = email.email.message_from_file(sys.stdin) |
msg = email.email.message_from_file(sys.stdin) |
720 |
|
|
721 |
if options.mail: |
if options.mail: |
722 |
stdout = tempfile.NamedTemporaryFile() |
stdout = tempfile.TemporaryFile() |
723 |
stderr = stdout |
stderr = stdout |
724 |
else: |
else: |
725 |
stdout = sys.stdout |
stdout = sys.stdout |
731 |
hexdigest = msg['X-Module-SHA256-tar.xz'] |
hexdigest = msg['X-Module-SHA256-tar.xz'] |
732 |
except KeyError, e: |
except KeyError, e: |
733 |
print >>stderr, "ERROR: %s" % e |
print >>stderr, "ERROR: %s" % e |
734 |
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
735 |
sys.exit(1) |
sys.exit(1) |
736 |
|
|
737 |
try: |
try: |
738 |
packages = get_downstream_from_upstream(module, version) |
packages = get_downstream_from_upstream(module, version) |
739 |
except ValueError, e: |
except ValueError, e: |
740 |
print >>stderr, "ERROR: %s" % e |
print >>stderr, "ERROR: %s" % e |
741 |
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
742 |
sys.exit(1) |
sys.exit(1) |
743 |
|
|
744 |
if options.wait: |
if options.wait: |
745 |
# maildrop aborts and will try to deliver after 5min |
# maildrop aborts and will try to deliver after 5min |
746 |
# fork to avoid this |
# fork to avoid this |
747 |
if os.fork() != 0: sys.exit(0) |
if os.fork() != 0: sys.exit(0) |
748 |
time.sleep(SLEEP_INITIAL) |
# wait SLEEP_INITIAL after the message was sent |
749 |
|
secs = SLEEP_INITIAL |
750 |
|
t = email.utils.parsedate_tz(msg['Date']) |
751 |
|
if t is not None: |
752 |
|
msg_time = email.utils.mktime_tz(t) |
753 |
|
secs = SLEEP_INITIAL - (time.time() - msg_time) |
754 |
|
|
755 |
|
if secs > 0: time.sleep(secs) |
756 |
|
|
757 |
|
error = False |
758 |
for package in packages: |
for package in packages: |
759 |
subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr) |
cmd = ['mga-gnome', 'increase', '--submit', '--hash', hexdigest] |
760 |
|
if options.force: |
761 |
|
cmd.append('--force') |
762 |
|
cmd.extend((package, version)) |
763 |
|
if subprocess.call(cmd, stdout=stdout, stderr=stderr): |
764 |
|
error = True |
765 |
|
|
766 |
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=error) |
767 |
|
|
768 |
def main(): |
def main(): |
769 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
781 |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
782 |
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
783 |
help="Show upstream module") |
help="Show upstream module") |
784 |
|
subparser.add_argument( "--version", action="store_true", dest="show_version", |
785 |
|
help="Show version numbers") |
786 |
|
subparser.add_argument( "--diff", action="store_true", dest="diff", |
787 |
|
help="Only show packages with different version") |
788 |
subparser.set_defaults( |
subparser.set_defaults( |
789 |
func=cmd_ls, upstream=False |
func=cmd_ls, upstream=False, show_version=False, diff=False |
790 |
) |
) |
791 |
|
|
792 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
805 |
subparser = subparsers.add_parser('increase', help='Increase version number') |
subparser = subparsers.add_parser('increase', help='Increase version number') |
806 |
subparser.add_argument("package", help="Package name") |
subparser.add_argument("package", help="Package name") |
807 |
subparser.add_argument("version", help="Version number") |
subparser.add_argument("version", help="Version number") |
808 |
|
subparser.add_argument("-f", "--force", action="store_true", dest="force", |
809 |
|
help="Override warnings, just do it") |
810 |
subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream", |
subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream", |
811 |
help="Package name reflects the upstream name") |
help="Package name reflects the upstream name") |
812 |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
816 |
subparser.add_argument("--hash", dest="hexdigest", |
subparser.add_argument("--hash", dest="hexdigest", |
817 |
help="Hexdigest of the hash") |
help="Hexdigest of the hash") |
818 |
subparser.set_defaults( |
subparser.set_defaults( |
819 |
func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256" |
func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256", |
820 |
|
force=False |
821 |
) |
) |
822 |
|
|
823 |
subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email') |
subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email') |
824 |
subparser.add_argument("-m", "--mail", help="Email address to send the progress to") |
subparser.add_argument("-m", "--mail", help="Email address to send the progress to") |
825 |
subparser.add_argument("-w", "--wait", action="store_true", |
subparser.add_argument("-w", "--wait", action="store_true", |
826 |
help="Wait before trying to retrieve the new version") |
help="Wait before trying to retrieve the new version") |
827 |
|
subparser.add_argument("-f", "--force", action="store_true", |
828 |
|
help="Force submission") |
829 |
subparser.set_defaults( |
subparser.set_defaults( |
830 |
func=cmd_parse_ftp_release_list |
func=cmd_parse_ftp_release_list, force=False, wait=False |
831 |
) |
) |
832 |
|
|
833 |
if len(sys.argv) == 1: |
if len(sys.argv) == 1: |
850 |
sys.exit(0) |
sys.exit(0) |
851 |
|
|
852 |
if __name__ == "__main__": |
if __name__ == "__main__": |
853 |
|
os.environ['PYTHONUNBUFFERED'] = '1' |
854 |
main() |
main() |