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 |
logfile = os.path.join(os.path.dirname(self.path), 'log.%s' % os.path.splitext(os.path.basename(self.path))[0]) |
341 |
|
if os.path.exists(logfile): |
342 |
|
subprocess.call(['tail', '-n', '15', logfile]) |
343 |
return False |
return False |
344 |
|
|
345 |
return True |
return True |
484 |
|
|
485 |
return self._svn_author |
return self._svn_author |
486 |
|
|
|
def get_upstream_names(): |
|
|
urlopen = urllib2.build_opener() |
|
487 |
|
|
488 |
good_dir = re.compile('^[-A-Za-z0-9_+.]+/$') |
class Upstream(object): |
489 |
|
|
490 |
# Get the files |
limit = None |
|
usock = urlopen.open(URL) |
|
|
parser = urllister() |
|
|
parser.feed(usock.read()) |
|
|
usock.close() |
|
|
parser.close() |
|
|
files = parser.urls |
|
491 |
|
|
492 |
tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)]) |
def __init__(self): |
493 |
|
urlopen = urllib2.build_opener() |
494 |
|
|
495 |
return tarballs |
good_dir = re.compile('^[-A-Za-z0-9_+.]+/$') |
496 |
|
|
497 |
def get_downstream_names(): |
# Get the files |
498 |
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]*)$') |
usock = urlopen.open(URL) |
499 |
|
parser = urllister() |
500 |
contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines() |
parser.feed(usock.read()) |
501 |
|
usock.close() |
502 |
FILES = {} |
parser.close() |
503 |
TARBALLS = {} |
files = parser.urls |
504 |
|
|
505 |
for line in contents: |
tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)]) |
506 |
try: |
if self.limit is not None: |
507 |
srpm, version, filename = line.split("|") |
tarballs.intersection_update(self.limit) |
|
except ValueError: |
|
|
print >>sys.stderr, line |
|
|
continue |
|
|
|
|
|
if '.tar' in filename: |
|
|
r = re_file.match(filename) |
|
|
if r: |
|
|
fileinfo = r.groupdict() |
|
|
module = fileinfo['module'] |
|
|
|
|
|
if module not in TARBALLS: |
|
|
TARBALLS[module] = {} |
|
|
TARBALLS[module][srpm] = version |
|
|
|
|
|
if srpm not in FILES: |
|
|
FILES[srpm] = set() |
|
|
FILES[srpm].add(filename) |
|
508 |
|
|
509 |
return TARBALLS, FILES |
self.names = tarballs |
510 |
|
|
511 |
def get_downstream_from_upstream(upstream, version): |
class Downstream(object): |
512 |
# Determine the package name |
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]*)$') |
|
downstream, downstream_files = get_downstream_names() |
|
513 |
|
|
514 |
if upstream not in downstream: |
def __init__(self): |
515 |
raise ValueError("No packages for upstream name: %s" % upstream) |
contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines() |
516 |
|
|
517 |
if len(downstream[upstream]) == 1: |
FILES = {} |
518 |
return downstream[upstream].keys() |
TARBALLS = {} |
519 |
|
|
520 |
# Directories packages are located in |
for line in contents: |
521 |
root = os.path.expanduser(PKGROOT) |
try: |
522 |
|
srpm, version, filename = line.split("|") |
523 |
|
except ValueError: |
524 |
|
print >>sys.stderr, line |
525 |
|
continue |
526 |
|
|
527 |
packages = {} |
if '.tar' in filename: |
528 |
for package in downstream[upstream].keys(): |
r = self.re_file.match(filename) |
529 |
cwd = os.path.join(root, package) |
if r: |
530 |
|
fileinfo = r.groupdict() |
531 |
|
module = fileinfo['module'] |
532 |
|
|
533 |
|
if module not in TARBALLS: |
534 |
|
TARBALLS[module] = {} |
535 |
|
TARBALLS[module][srpm] = version |
536 |
|
|
537 |
|
if srpm not in FILES: |
538 |
|
FILES[srpm] = set() |
539 |
|
FILES[srpm].add(filename) |
540 |
|
|
541 |
|
self.tarballs = TARBALLS |
542 |
|
self.files = FILES |
543 |
|
|
544 |
|
def get_downstream_from_upstream(self, upstream, version): |
545 |
|
if upstream not in self.tarballs: |
546 |
|
raise ValueError("No packages for upstream name: %s" % upstream) |
547 |
|
|
548 |
|
if len(self.tarballs[upstream]) == 1: |
549 |
|
return self.tarballs[upstream].keys() |
550 |
|
|
551 |
|
# Directories packages are located in |
552 |
|
root = os.path.expanduser(PKGROOT) |
553 |
|
|
554 |
|
packages = {} |
555 |
|
for package in self.tarballs[upstream].keys(): |
556 |
|
cwd = os.path.join(root, package) |
557 |
|
|
558 |
# Checkout package to ensure the checkout reflects the latest changes |
# Checkout package to ensure the checkout reflects the latest changes |
559 |
try: |
try: |
560 |
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
561 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
562 |
raise ValueError("Multiple packages found and cannot checkout %s" % package) |
raise ValueError("Multiple packages found and cannot checkout %s" % package) |
563 |
|
|
564 |
# Determine version from spec file |
# Determine version from spec file |
565 |
try: |
try: |
566 |
packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
567 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
568 |
raise ValueError("Multiple packages found and cannot determine version of %s" % package) |
raise ValueError("Multiple packages found and cannot determine version of %s" % package) |
569 |
|
|
570 |
# Return all packages reflecting the current version |
# Return all packages reflecting the current version |
571 |
matches = [package for package in packages if packages[package] == version] |
matches = [package for package in packages if packages[package] == version] |
572 |
if len(matches): |
if len(matches): |
573 |
return matches |
return matches |
574 |
|
|
575 |
# Return all packages reflecting the version before the current version |
# Return all packages reflecting the version before the current version |
576 |
latest_version = get_latest_version(packages.values(), max_version=version) |
latest_version = get_latest_version(packages.values(), max_version=version) |
577 |
matches = [package for package in packages if packages[package] == latest_version] |
matches = [package for package in packages if packages[package] == latest_version] |
578 |
if len(matches): |
if len(matches): |
579 |
return matches |
return matches |
580 |
|
|
581 |
# Give up |
# Give up |
582 |
raise ValueError("Multiple packages found and cannot determine package for version %s" % version) |
raise ValueError("Multiple packages found and cannot determine package for version %s" % version) |
583 |
|
|
584 |
def write_file(path, data): |
def write_file(path, data): |
585 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
597 |
def join_streams(show_version=False, only_diff_version=False): |
def join_streams(show_version=False, only_diff_version=False): |
598 |
root = os.path.expanduser(PKGROOT) |
root = os.path.expanduser(PKGROOT) |
599 |
|
|
600 |
upstream = get_upstream_names() |
upstream = Upstream().names |
601 |
downstream, downstream_files = get_downstream_names() |
downstream = Downstream() |
602 |
|
|
603 |
matches = upstream & set(downstream.keys()) |
matches = upstream & set(downstream.tarballs.keys()) |
604 |
for module in matches: |
for module in matches: |
605 |
for package in downstream[module].keys(): |
for package in downstream.tarballs[module].keys(): |
606 |
package_version = downstream[module][package] |
package_version = downstream.tarballs[module][package] |
607 |
spec_version = None |
spec_version = None |
608 |
if show_version or only_diff_version: |
if show_version or only_diff_version: |
609 |
cwd = os.path.join(root, package) |
cwd = os.path.join(root, package) |
615 |
if only_diff_version and package_version == spec_version: |
if only_diff_version and package_version == spec_version: |
616 |
continue |
continue |
617 |
|
|
618 |
yield (package, module, package_version, spec_version, downstream_files[package]) |
yield (package, module, package_version, spec_version, downstream.files[package]) |
619 |
|
|
620 |
def cmd_ls(options, parser): |
def cmd_ls(options, parser): |
621 |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams(show_version=options.show_version, only_diff_version=options.diff)): |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams(show_version=options.show_version, only_diff_version=options.diff)): |
622 |
print package,"\t", |
sys.stdout.write(package) |
623 |
if options.upstream: print module, "\t", |
if options.upstream: sys.stdout.write("\t%s" % module) |
624 |
if options.show_version: print spec_version, "\t", package_version, "\t", |
if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version)) |
625 |
print |
print |
626 |
|
|
627 |
def cmd_patches(options, parser): |
def cmd_patches(options, parser): |
648 |
# Determine the package name |
# Determine the package name |
649 |
if options.upstream: |
if options.upstream: |
650 |
try: |
try: |
651 |
package = get_downstream_from_upstream(options.package, options.version)[0] |
package = Downstream().get_downstream_from_upstream(options.package, options.version)[0] |
652 |
except ValueError, e: |
except ValueError, e: |
653 |
print >>sys.stderr, "ERROR: %s" % e |
print >>sys.stderr, "ERROR: %s" % e |
654 |
sys.exit(1) |
sys.exit(1) |
679 |
sys.stderr(1) |
sys.stderr(1) |
680 |
|
|
681 |
for filename in sources: |
for filename in sources: |
682 |
if not is_valid_hash(os.path.join(cwd, "SOURCES", filename), options.algo, options.hexdigest): |
path = os.path.join(cwd, "SOURCES", filename) |
683 |
|
if not is_valid_hash(path, options.algo, options.hexdigest): |
684 |
print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path |
print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path |
685 |
print >>sys.stderr, "ERROR: Reverting changes!" |
print >>sys.stderr, "ERROR: Reverting changes!" |
686 |
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd) |
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd) |
692 |
# checkin changes |
# checkin changes |
693 |
subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd) |
subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd) |
694 |
# and submit |
# and submit |
695 |
subprocess.check_call(['mgarepo', 'submit'], cwd=cwd) |
# XXX HACK NOT TO AUTO SUBMIT ATM |
696 |
|
if options.hexdigest is None: |
697 |
|
subprocess.check_call(['mgarepo', 'submit'], cwd=cwd) |
698 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
699 |
sys.exit(1) |
sys.exit(1) |
700 |
|
|
701 |
def cmd_parse_ftp_release_list(options, parser): |
def cmd_parse_ftp_release_list(options, parser): |
702 |
def _send_reply_mail(contents, orig_msg, to, error=False): |
def _send_reply_mail(contents, orig_msg, to, packages=[], error=False): |
703 |
"""Send an reply email""" |
"""Send an reply email""" |
704 |
contents.seek(0) |
contents.seek(0) |
705 |
msg = MIMEText(contents.read(), _charset='utf-8') |
msg = MIMEText(contents.read(), _charset='utf-8') |
706 |
|
|
707 |
if error: |
if error: |
708 |
# XXX - ugly |
# XXX - ugly |
709 |
contents.seek(0) |
contents.seek(0) |
710 |
lastline = contents.read().splitlines()[-1] |
lastline = contents.read().rstrip().splitlines()[-1] |
711 |
# Remove things like "ERROR: " and so on from the last line |
# Remove things like "ERROR: " and so on from the last line |
712 |
lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline) |
lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline) |
713 |
|
# Remove things like " - " (youri output from mgarepo submit) |
714 |
|
lastline = re.sub(r'^\s+-\s+', '', lastline) |
715 |
subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)" |
subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)" |
716 |
else: |
else: |
717 |
subjecterror = "" |
subjecterror = "" |
718 |
msg['Subject'] = "Re: %s%s" % (orig_msg['Subject'], subjecterror) |
|
719 |
|
if packages: |
720 |
|
subject = "%s %s%s" % (", ".join(packages), orig_msg['X-Module-Version'], subjecterror) |
721 |
|
else: |
722 |
|
subject = "Re: %s%s" % (orig_msg['Subject'], subjecterror) |
723 |
|
|
724 |
|
msg['Subject'] = subject |
725 |
msg['To'] = to |
msg['To'] = to |
726 |
msg["In-Reply-To"] = orig_msg["Message-ID"] |
msg["In-Reply-To"] = orig_msg["Message-ID"] |
727 |
msg["References"] = orig_msg["Message-ID"] |
msg["References"] = orig_msg["Message-ID"] |
755 |
sys.exit(1) |
sys.exit(1) |
756 |
|
|
757 |
try: |
try: |
758 |
packages = get_downstream_from_upstream(module, version) |
packages = Downstream().get_downstream_from_upstream(module, version) |
759 |
except ValueError, e: |
except ValueError, e: |
760 |
print >>stderr, "ERROR: %s" % e |
print >>stderr, "ERROR: %s" % e |
761 |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
783 |
if subprocess.call(cmd, stdout=stdout, stderr=stderr): |
if subprocess.call(cmd, stdout=stdout, stderr=stderr): |
784 |
error = True |
error = True |
785 |
|
|
786 |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=error) |
if options.mail: _send_reply_mail(stdout, msg, options.mail, packages=packages, error=error) |
787 |
|
|
788 |
def main(): |
def main(): |
789 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
790 |
epilog="""Report bugs to Olav Vitters""" |
epilog="""Report bugs to Olav Vitters""" |
791 |
parser = argparse.ArgumentParser(description=description,epilog=epilog) |
parser = argparse.ArgumentParser(description=description,epilog=epilog) |
792 |
|
parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0), |
793 |
|
dest="limit_upstream", metavar="FILE", |
794 |
|
help="File containing upstream names") |
795 |
|
|
796 |
# SUBPARSERS |
# SUBPARSERS |
797 |
subparsers = parser.add_subparsers(title='subcommands') |
subparsers = parser.add_subparsers(title='subcommands') |
858 |
sys.exit(2) |
sys.exit(2) |
859 |
|
|
860 |
options = parser.parse_args() |
options = parser.parse_args() |
861 |
|
if options.limit_upstream: |
862 |
|
Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines()) |
863 |
|
|
864 |
try: |
try: |
865 |
options.func(options, parser) |
options.func(options, parser) |
875 |
sys.exit(0) |
sys.exit(0) |
876 |
|
|
877 |
if __name__ == "__main__": |
if __name__ == "__main__": |
878 |
|
os.environ['PYTHONUNBUFFERED'] = '1' |
879 |
main() |
main() |