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 |
33 |
import urllib2 |
import urllib2 |
34 |
import urlparse |
import urlparse |
35 |
|
|
36 |
|
# for checking hashes |
37 |
|
import hashlib |
38 |
|
|
39 |
|
# for parsing ftp-release-list emails |
40 |
|
import email |
41 |
|
from email.mime.text import MIMEText |
42 |
|
|
43 |
|
# to be able to sleep for a while |
44 |
|
import time |
45 |
|
|
46 |
MEDIA="Core Release Source" |
MEDIA="Core Release Source" |
47 |
URL="http://download.gnome.org/sources/" |
URL="http://download.gnome.org/sources/" |
48 |
PKGROOT='~/pkgs' |
PKGROOT='~/pkgs' |
49 |
|
SLEEP_INITIAL=300 |
50 |
|
|
51 |
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
52 |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
85 |
5+: Ok""" |
5+: Ok""" |
86 |
versions = (version_old, version_new) |
versions = (version_old, version_new) |
87 |
|
|
|
print " => ".join(versions) |
|
|
|
|
88 |
# First do a basic version comparison to ensure version_new is actually newer |
# First do a basic version comparison to ensure version_new is actually newer |
89 |
compare = version_cmp(version_new, version_old) |
compare = version_cmp(version_new, version_old) |
90 |
|
|
213 |
if not hasattr(tarfile.TarFile, 'xzopen'): |
if not hasattr(tarfile.TarFile, 'xzopen'): |
214 |
tarfile.open = XzTarFile.open |
tarfile.open = XzTarFile.open |
215 |
|
|
216 |
|
def is_valid_hash(path, algo, hexdigest): |
217 |
|
if algo not in hashlib.algorithms: |
218 |
|
raise ValueError("Unknown hash algorithm: %s" % algo) |
219 |
|
|
220 |
|
local_hash = getattr(hashlib, algo)() |
221 |
|
|
222 |
|
with open(path, 'rb') as fp: |
223 |
|
data = fp.read(32768) |
224 |
|
while data: |
225 |
|
local_hash.update(data) |
226 |
|
data = fp.read(32768) |
227 |
|
|
228 |
|
return local_hash.hexdigest() == hexdigest |
229 |
|
|
230 |
class SpecFile(object): |
class SpecFile(object): |
231 |
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
232 |
re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?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) |
238 |
@property |
@property |
239 |
def version(self): |
def version(self): |
240 |
return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0] |
return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0] |
241 |
|
@property |
242 |
|
def sources(self): |
243 |
|
ts = rpm.ts() |
244 |
|
spec = ts.parseSpec(self.path) |
245 |
|
srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \ |
246 |
|
else spec.sources() |
247 |
|
return dict((os.path.basename(name), name) for name, no, flags in srclist) |
248 |
|
|
249 |
def update(self, version): |
def update(self, version): |
250 |
"""Update specfile (increase version)""" |
"""Update specfile (increase version)""" |
489 |
|
|
490 |
return TARBALLS, FILES |
return TARBALLS, FILES |
491 |
|
|
492 |
|
def get_downstream_from_upstream(upstream, version): |
493 |
|
# Determine the package name |
494 |
|
downstream, downstream_files = get_downstream_names() |
495 |
|
|
496 |
|
if upstream not in downstream: |
497 |
|
raise ValueError("No packages for upstream name: %s" % upstream) |
498 |
|
|
499 |
|
if len(downstream[upstream]) != 1: |
500 |
|
# XXX - Make it more intelligent |
501 |
|
raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream]))) |
502 |
|
|
503 |
|
return list(downstream[upstream]) |
504 |
|
|
505 |
def write_file(path, data): |
def write_file(path, data): |
506 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
520 |
for package in downstream[module]: |
for package in downstream[module]: |
521 |
subprocess.call(['mgarepo', 'co', package], cwd=cwd) |
subprocess.call(['mgarepo', 'co', package], cwd=cwd) |
522 |
|
|
523 |
def cmd_ls(options, parser): |
def join_streams(): |
524 |
upstream = get_upstream_names() |
upstream = get_upstream_names() |
525 |
downstream, downstream_files = get_downstream_names() |
downstream, downstream_files = get_downstream_names() |
526 |
|
|
527 |
matches = upstream & set(downstream.keys()) |
matches = upstream & set(downstream.keys()) |
528 |
for module in matches: |
for module in matches: |
529 |
print "\n".join(sorted(downstream[module])) |
for package in downstream[module]: |
530 |
|
yield (package, module) |
531 |
|
|
532 |
|
def cmd_ls(options, parser): |
533 |
|
for package, module in sorted(join_streams()): |
534 |
|
print "\t".join((package, module)) if options.upstream else package |
535 |
|
|
536 |
def cmd_patches(options, parser): |
def cmd_patches(options, parser): |
537 |
upstream = get_upstream_names() |
upstream = get_upstream_names() |
563 |
def cmd_package_new_version(options, parser): |
def cmd_package_new_version(options, parser): |
564 |
# Determine the package name |
# Determine the package name |
565 |
if options.upstream: |
if options.upstream: |
566 |
downstream, downstream_files = get_downstream_names() |
try: |
567 |
|
package = get_downstream_from_upstream(options.package, options.version)[0] |
568 |
if options.package not in downstream: |
except ValueError, e: |
569 |
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])) |
|
570 |
sys.exit(1) |
sys.exit(1) |
|
|
|
|
package = list(downstream[options.package])[0] |
|
571 |
else: |
else: |
572 |
package = options.package |
package = options.package |
573 |
|
|
587 |
if not s.update(options.version): |
if not s.update(options.version): |
588 |
sys.exit(1) |
sys.exit(1) |
589 |
|
|
590 |
|
# Check hash, if given |
591 |
|
if options.hexdigest is not None: |
592 |
|
sources = [name for name, origname in s.sources.iteritems() if '://' in origname] |
593 |
|
if not len(sources): |
594 |
|
print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!" |
595 |
|
sys.stderr(1) |
596 |
|
|
597 |
|
for filename in sources: |
598 |
|
if not is_valid_hash(os.path.join(cwd, "SOURCES", filename), options.algo, options.hexdigest): |
599 |
|
print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path |
600 |
|
print >>sys.stderr, "ERROR: Reverting changes!" |
601 |
|
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd) |
602 |
|
sys.exit(1) |
603 |
|
|
604 |
# We can even checkin and submit :-) |
# We can even checkin and submit :-) |
605 |
if options.submit: |
if options.submit: |
606 |
try: |
try: |
611 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
612 |
sys.exit(1) |
sys.exit(1) |
613 |
|
|
614 |
|
def cmd_parse_ftp_release_list(options, parser): |
615 |
|
# XXX - not working yet |
616 |
|
def _send_reply_mail(contents, orig_msg, to): |
617 |
|
"""Send an reply email""" |
618 |
|
contents.seek(0) |
619 |
|
msg = MIMEText(contents.read(), _charset='utf-8') |
620 |
|
msg['Subject'] = "Re: %s" % orig_msg['Subject'] |
621 |
|
msg['To'] = to |
622 |
|
msg["In-Reply-To"] = orig_msg["Message-ID"] |
623 |
|
msg["References"] = orig_msg["Message-ID"] |
624 |
|
|
625 |
|
# Call sendmail program directly so it doesn't matter if the service is running |
626 |
|
cmd = ['/usr/sbin/sendmail', '-oi', '--'] |
627 |
|
cmd.extend([to]) |
628 |
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE) |
629 |
|
p.stdin.write(msg.as_string()) |
630 |
|
p.stdin.flush() |
631 |
|
p.stdin.close() |
632 |
|
p.wait() |
633 |
|
|
634 |
|
|
635 |
|
msg = email.email.message_from_file(sys.stdin) |
636 |
|
|
637 |
|
if options.mail: |
638 |
|
stdout = tempfile.NamedTemporaryFile() |
639 |
|
stderr = stdout |
640 |
|
else: |
641 |
|
stdout = sys.stdout |
642 |
|
stderr = sys.stderr |
643 |
|
|
644 |
|
try: |
645 |
|
module = msg['X-Module-Name'] |
646 |
|
version = msg['X-Module-Version'] |
647 |
|
hexdigest = msg['X-Module-SHA256-tar.xz'] |
648 |
|
except KeyError, e: |
649 |
|
print >>stderr, "ERROR: %s" % e |
650 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
651 |
|
sys.exit(1) |
652 |
|
|
653 |
|
try: |
654 |
|
packages = get_downstream_from_upstream(module, version) |
655 |
|
except ValueError, e: |
656 |
|
print >>stderr, "ERROR: %s" % e |
657 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
658 |
|
sys.exit(1) |
659 |
|
|
660 |
|
if options.wait: |
661 |
|
# maildrop aborts and will try to deliver after 5min |
662 |
|
# fork to avoid this |
663 |
|
if os.fork() != 0: sys.exit(0) |
664 |
|
time.sleep(SLEEP_INITIAL) |
665 |
|
|
666 |
|
for package in packages: |
667 |
|
subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr) |
668 |
|
|
669 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
670 |
|
|
671 |
def main(): |
def main(): |
672 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
682 |
) |
) |
683 |
|
|
684 |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
685 |
|
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
686 |
|
help="Show upstream module") |
687 |
subparser.set_defaults( |
subparser.set_defaults( |
688 |
func=cmd_ls |
func=cmd_ls, upstream=False |
689 |
) |
) |
690 |
|
|
691 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
708 |
help="Package name reflects the upstream name") |
help="Package name reflects the upstream name") |
709 |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
710 |
help="Commit changes and submit") |
help="Commit changes and submit") |
711 |
|
subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo", |
712 |
|
help="Hash algorithm") |
713 |
|
subparser.add_argument("--hash", dest="hexdigest", |
714 |
|
help="Hexdigest of the hash") |
715 |
|
subparser.set_defaults( |
716 |
|
func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256" |
717 |
|
) |
718 |
|
|
719 |
|
subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email') |
720 |
|
subparser.add_argument("-m", "--mail", help="Email address to send the progress to") |
721 |
|
subparser.add_argument("-w", "--wait", action="store_true", |
722 |
|
help="Wait before trying to retrieve the new version") |
723 |
subparser.set_defaults( |
subparser.set_defaults( |
724 |
func=cmd_package_new_version, submit=False, upstream=False |
func=cmd_parse_ftp_release_list |
725 |
) |
) |
726 |
|
|
727 |
if len(sys.argv) == 1: |
if len(sys.argv) == 1: |