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 |
|
# 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 |
53 |
|
|
54 |
|
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
55 |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
56 |
|
|
57 |
def version_cmp(a, b): |
def version_cmp(a, b): |
88 |
5+: Ok""" |
5+: Ok""" |
89 |
versions = (version_old, version_new) |
versions = (version_old, version_new) |
90 |
|
|
|
print " => ".join(versions) |
|
|
|
|
91 |
# 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 |
92 |
compare = version_cmp(version_new, version_old) |
compare = version_cmp(version_new, version_old) |
93 |
|
|
94 |
if compare == 0: |
if compare == 0: |
95 |
|
# 1.0.0 -> 1.0.1 |
96 |
return (-2, "Already at version %s!" % (version_old)) |
return (-2, "Already at version %s!" % (version_old)) |
97 |
|
|
98 |
if compare != 1: |
if compare != 1: |
99 |
|
# 1.0.1 -> 1.0.0 |
100 |
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)) |
101 |
|
|
102 |
# 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 |
117 |
# Major+minor the same? Then go ahead and upgrade! |
# Major+minor the same? Then go ahead and upgrade! |
118 |
if majmins[0] == majmins[1]: |
if majmins[0] == majmins[1]: |
119 |
# Majmin of both versions are the same, looks good! |
# Majmin of both versions are the same, looks good! |
120 |
|
# 1.1.x -> 1.1.x or 1.0.x -> 1.0.x |
121 |
return (10, None) |
return (10, None) |
122 |
|
|
123 |
# More detailed analysis needed, so figure out the numbers |
# More detailed analysis needed, so figure out the numbers |
125 |
|
|
126 |
# Check/ensure major version number is the same |
# Check/ensure major version number is the same |
127 |
if majmin_nrs[0][0] != majmin_nrs[1][0]: |
if majmin_nrs[0][0] != majmin_nrs[1][0]: |
128 |
|
# 1.0.x -> 2.0.x |
129 |
return (1, "Major version number increase") |
return (1, "Major version number increase") |
130 |
|
|
131 |
# Minor indicates stable/unstable |
# Minor indicates stable/unstable |
134 |
# Upgrading to unstable is weird |
# Upgrading to unstable is weird |
135 |
if not devstate[1]: |
if not devstate[1]: |
136 |
if devstate[0]: |
if devstate[0]: |
137 |
|
# 1.2.x -> 1.3.x |
138 |
return (1, "Stable to unstable increase") |
return (1, "Stable to unstable increase") |
139 |
|
|
140 |
|
# 1.3.x -> 1.5.x |
141 |
return (4, "Unstable to unstable version increase") |
return (4, "Unstable to unstable version increase") |
142 |
|
|
143 |
# Unstable => stable is always ok |
# Unstable => stable is always ok |
144 |
if not devstate[0]: |
if not devstate[0]: |
145 |
|
# 1.1.x -> 1.2.x |
146 |
return (5, "Unstable to stable") |
return (5, "Unstable to stable") |
147 |
|
|
148 |
# Can only be increase of minors from one stable to the next |
# Can only be increase of minors from one stable to the next |
149 |
|
# 1.0.x -> 1.2.x |
150 |
return (6, "Stable version increase") |
return (6, "Stable version increase") |
151 |
|
|
152 |
def line_input (file): |
def line_input (file): |
224 |
if not hasattr(tarfile.TarFile, 'xzopen'): |
if not hasattr(tarfile.TarFile, 'xzopen'): |
225 |
tarfile.open = XzTarFile.open |
tarfile.open = XzTarFile.open |
226 |
|
|
227 |
|
def is_valid_hash(path, algo, hexdigest): |
228 |
|
if algo not in hashlib.algorithms: |
229 |
|
raise ValueError("Unknown hash algorithm: %s" % algo) |
230 |
|
|
231 |
|
local_hash = getattr(hashlib, algo)() |
232 |
|
|
233 |
|
with open(path, 'rb') as fp: |
234 |
|
data = fp.read(32768) |
235 |
|
while data: |
236 |
|
local_hash.update(data) |
237 |
|
data = fp.read(32768) |
238 |
|
|
239 |
|
return local_hash.hexdigest() == hexdigest |
240 |
|
|
241 |
class SpecFile(object): |
class SpecFile(object): |
242 |
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) |
243 |
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) |
249 |
@property |
@property |
250 |
def version(self): |
def version(self): |
251 |
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] |
252 |
|
@property |
253 |
|
def sources(self): |
254 |
|
ts = rpm.ts() |
255 |
|
spec = ts.parseSpec(self.path) |
256 |
|
srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \ |
257 |
|
else spec.sources() |
258 |
|
return dict((os.path.basename(name), name) for name, no, flags in srclist) |
259 |
|
|
260 |
def update(self, version): |
def update(self, version): |
261 |
"""Update specfile (increase version)""" |
"""Update specfile (increase version)""" |
268 |
return False |
return False |
269 |
|
|
270 |
if judgement < 5: |
if judgement < 5: |
271 |
print >>sys.stderr, "WARNING: %s!" % (msg) |
print "WARNING: %s!" % (msg) |
272 |
return False |
return False |
273 |
|
|
274 |
# XXX - os.path.join is hackish |
# XXX - os.path.join is hackish |
500 |
|
|
501 |
return TARBALLS, FILES |
return TARBALLS, FILES |
502 |
|
|
503 |
|
def get_downstream_from_upstream(upstream, version): |
504 |
|
# Determine the package name |
505 |
|
downstream, downstream_files = get_downstream_names() |
506 |
|
|
507 |
|
if upstream not in downstream: |
508 |
|
raise ValueError("No packages for upstream name: %s" % upstream) |
509 |
|
|
510 |
|
if len(downstream[upstream]) != 1: |
511 |
|
# XXX - Make it more intelligent |
512 |
|
raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream]))) |
513 |
|
|
514 |
|
return list(downstream[upstream]) |
515 |
|
|
516 |
def write_file(path, data): |
def write_file(path, data): |
517 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
531 |
for package in downstream[module]: |
for package in downstream[module]: |
532 |
subprocess.call(['mgarepo', 'co', package], cwd=cwd) |
subprocess.call(['mgarepo', 'co', package], cwd=cwd) |
533 |
|
|
534 |
def cmd_ls(options, parser): |
def join_streams(): |
535 |
upstream = get_upstream_names() |
upstream = get_upstream_names() |
536 |
downstream, downstream_files = get_downstream_names() |
downstream, downstream_files = get_downstream_names() |
537 |
|
|
538 |
matches = upstream & set(downstream.keys()) |
matches = upstream & set(downstream.keys()) |
539 |
for module in matches: |
for module in matches: |
540 |
print "\n".join(sorted(downstream[module])) |
for package in downstream[module]: |
541 |
|
yield (package, module) |
542 |
|
|
543 |
|
def cmd_ls(options, parser): |
544 |
|
for package, module in sorted(join_streams()): |
545 |
|
print "\t".join((package, module)) if options.upstream else package |
546 |
|
|
547 |
def cmd_patches(options, parser): |
def cmd_patches(options, parser): |
548 |
upstream = get_upstream_names() |
upstream = get_upstream_names() |
574 |
def cmd_package_new_version(options, parser): |
def cmd_package_new_version(options, parser): |
575 |
# Determine the package name |
# Determine the package name |
576 |
if options.upstream: |
if options.upstream: |
577 |
downstream, downstream_files = get_downstream_names() |
try: |
578 |
|
package = get_downstream_from_upstream(options.package, options.version)[0] |
579 |
if options.package not in downstream: |
except ValueError, e: |
580 |
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])) |
|
581 |
sys.exit(1) |
sys.exit(1) |
|
|
|
|
package = list(downstream[options.package])[0] |
|
582 |
else: |
else: |
583 |
package = options.package |
package = options.package |
584 |
|
|
598 |
if not s.update(options.version): |
if not s.update(options.version): |
599 |
sys.exit(1) |
sys.exit(1) |
600 |
|
|
601 |
|
# Check hash, if given |
602 |
|
if options.hexdigest is not None: |
603 |
|
sources = [name for name, origname in s.sources.iteritems() if '://' in origname] |
604 |
|
if not len(sources): |
605 |
|
print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!" |
606 |
|
sys.stderr(1) |
607 |
|
|
608 |
|
for filename in sources: |
609 |
|
if not is_valid_hash(os.path.join(cwd, "SOURCES", filename), options.algo, options.hexdigest): |
610 |
|
print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path |
611 |
|
print >>sys.stderr, "ERROR: Reverting changes!" |
612 |
|
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd) |
613 |
|
sys.exit(1) |
614 |
|
|
615 |
# We can even checkin and submit :-) |
# We can even checkin and submit :-) |
616 |
if options.submit: |
if options.submit: |
617 |
try: |
try: |
622 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
623 |
sys.exit(1) |
sys.exit(1) |
624 |
|
|
625 |
|
def cmd_parse_ftp_release_list(options, parser): |
626 |
|
# XXX - not working yet |
627 |
|
def _send_reply_mail(contents, orig_msg, to, error=False): |
628 |
|
"""Send an reply email""" |
629 |
|
contents.seek(0) |
630 |
|
msg = MIMEText(contents.read(), _charset='utf-8') |
631 |
|
if error: |
632 |
|
# XXX - ugly |
633 |
|
contents.seek(0) |
634 |
|
lastline = contents.read().splitlines()[-1] |
635 |
|
# Remove things like "ERROR: " and so on from the last line |
636 |
|
lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline) |
637 |
|
subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)" |
638 |
|
else: |
639 |
|
subjecterror = "" |
640 |
|
msg['Subject'] = "Re: %s%s" % (orig_msg['Subject'], subjecterror) |
641 |
|
msg['To'] = to |
642 |
|
msg["In-Reply-To"] = orig_msg["Message-ID"] |
643 |
|
msg["References"] = orig_msg["Message-ID"] |
644 |
|
|
645 |
|
# Call sendmail program directly so it doesn't matter if the service is running |
646 |
|
cmd = ['/usr/sbin/sendmail', '-oi', '--'] |
647 |
|
cmd.extend([to]) |
648 |
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE) |
649 |
|
p.stdin.write(msg.as_string()) |
650 |
|
p.stdin.flush() |
651 |
|
p.stdin.close() |
652 |
|
p.wait() |
653 |
|
|
654 |
|
|
655 |
|
msg = email.email.message_from_file(sys.stdin) |
656 |
|
|
657 |
|
if options.mail: |
658 |
|
stdout = tempfile.TemporaryFile() |
659 |
|
stderr = stdout |
660 |
|
else: |
661 |
|
stdout = sys.stdout |
662 |
|
stderr = sys.stderr |
663 |
|
|
664 |
|
try: |
665 |
|
module = msg['X-Module-Name'] |
666 |
|
version = msg['X-Module-Version'] |
667 |
|
hexdigest = msg['X-Module-SHA256-tar.xz'] |
668 |
|
except KeyError, e: |
669 |
|
print >>stderr, "ERROR: %s" % e |
670 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
671 |
|
sys.exit(1) |
672 |
|
|
673 |
|
try: |
674 |
|
packages = get_downstream_from_upstream(module, version) |
675 |
|
except ValueError, e: |
676 |
|
print >>stderr, "ERROR: %s" % e |
677 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
678 |
|
sys.exit(1) |
679 |
|
|
680 |
|
if options.wait: |
681 |
|
# maildrop aborts and will try to deliver after 5min |
682 |
|
# fork to avoid this |
683 |
|
if os.fork() != 0: sys.exit(0) |
684 |
|
time.sleep(SLEEP_INITIAL) |
685 |
|
|
686 |
|
error = False |
687 |
|
for package in packages: |
688 |
|
if subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr): |
689 |
|
error = True |
690 |
|
|
691 |
|
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=error) |
692 |
|
|
693 |
def main(): |
def main(): |
694 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
704 |
) |
) |
705 |
|
|
706 |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
707 |
|
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
708 |
|
help="Show upstream module") |
709 |
subparser.set_defaults( |
subparser.set_defaults( |
710 |
func=cmd_ls |
func=cmd_ls, upstream=False |
711 |
) |
) |
712 |
|
|
713 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
730 |
help="Package name reflects the upstream name") |
help="Package name reflects the upstream name") |
731 |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
732 |
help="Commit changes and submit") |
help="Commit changes and submit") |
733 |
|
subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo", |
734 |
|
help="Hash algorithm") |
735 |
|
subparser.add_argument("--hash", dest="hexdigest", |
736 |
|
help="Hexdigest of the hash") |
737 |
|
subparser.set_defaults( |
738 |
|
func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256" |
739 |
|
) |
740 |
|
|
741 |
|
subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email') |
742 |
|
subparser.add_argument("-m", "--mail", help="Email address to send the progress to") |
743 |
|
subparser.add_argument("-w", "--wait", action="store_true", |
744 |
|
help="Wait before trying to retrieve the new version") |
745 |
subparser.set_defaults( |
subparser.set_defaults( |
746 |
func=cmd_package_new_version, submit=False, upstream=False |
func=cmd_parse_ftp_release_list |
747 |
) |
) |
748 |
|
|
749 |
if len(sys.argv) == 1: |
if len(sys.argv) == 1: |