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]+)') |
94 |
compare = version_cmp(version_new, version_old) |
compare = version_cmp(version_new, version_old) |
95 |
|
|
96 |
if compare == 0: |
if compare == 0: |
97 |
|
# 1.0.0 -> 1.0.1 |
98 |
return (-2, "Already at version %s!" % (version_old)) |
return (-2, "Already at version %s!" % (version_old)) |
99 |
|
|
100 |
if compare != 1: |
if compare != 1: |
101 |
|
# 1.0.1 -> 1.0.0 |
102 |
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)) |
103 |
|
|
104 |
# 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 |
119 |
# Major+minor the same? Then go ahead and upgrade! |
# Major+minor the same? Then go ahead and upgrade! |
120 |
if majmins[0] == majmins[1]: |
if majmins[0] == majmins[1]: |
121 |
# Majmin of both versions are the same, looks good! |
# Majmin of both versions are the same, looks good! |
122 |
|
# 1.1.x -> 1.1.x or 1.0.x -> 1.0.x |
123 |
return (10, None) |
return (10, None) |
124 |
|
|
125 |
# More detailed analysis needed, so figure out the numbers |
# More detailed analysis needed, so figure out the numbers |
127 |
|
|
128 |
# Check/ensure major version number is the same |
# Check/ensure major version number is the same |
129 |
if majmin_nrs[0][0] != majmin_nrs[1][0]: |
if majmin_nrs[0][0] != majmin_nrs[1][0]: |
130 |
|
# 1.0.x -> 2.0.x |
131 |
return (1, "Major version number increase") |
return (1, "Major version number increase") |
132 |
|
|
133 |
# Minor indicates stable/unstable |
# Minor indicates stable/unstable |
136 |
# Upgrading to unstable is weird |
# Upgrading to unstable is weird |
137 |
if not devstate[1]: |
if not devstate[1]: |
138 |
if devstate[0]: |
if devstate[0]: |
139 |
|
# 1.2.x -> 1.3.x |
140 |
return (1, "Stable to unstable increase") |
return (1, "Stable to unstable increase") |
141 |
|
|
142 |
|
# 1.3.x -> 1.5.x |
143 |
return (4, "Unstable to unstable version increase") |
return (4, "Unstable to unstable version increase") |
144 |
|
|
145 |
# Unstable => stable is always ok |
# Unstable => stable is always ok |
146 |
if not devstate[0]: |
if not devstate[0]: |
147 |
|
# 1.1.x -> 1.2.x |
148 |
return (5, "Unstable to stable") |
return (5, "Unstable to stable") |
149 |
|
|
150 |
# Can only be increase of minors from one stable to the next |
# Can only be increase of minors from one stable to the next |
151 |
|
# 1.0.x -> 1.2.x |
152 |
return (6, "Stable version increase") |
return (6, "Stable version increase") |
153 |
|
|
154 |
def line_input (file): |
def line_input (file): |
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, '..')]) != '': |
if subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) != '': |
304 |
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
305 |
return False |
return False |
306 |
|
|
307 |
|
|
308 |
|
# Try to download the new tarball various times and wait between attempts |
309 |
|
tries = 0 |
310 |
|
while tries < SLEEP_TIMES: |
311 |
|
tries += 1 |
312 |
|
if tries > 1: time.sleep(SLEEP_REPEAT) |
313 |
|
try: |
314 |
|
# Download new tarball |
315 |
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
316 |
|
# success, so exit loop |
317 |
|
break |
318 |
|
except subprocess.CalledProcessError, e: |
319 |
|
# mgarepo sync returns 1 if the tarball cannot be downloaded |
320 |
|
if e.returncode != 1: |
321 |
|
return False |
322 |
|
else: |
323 |
|
return False |
324 |
|
|
325 |
|
|
326 |
try: |
try: |
|
# Download new tarball |
|
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
|
327 |
# Check patches still apply |
# Check patches still apply |
328 |
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
329 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
491 |
def get_downstream_names(): |
def get_downstream_names(): |
492 |
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]*)$') |
493 |
|
|
494 |
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() |
495 |
|
|
496 |
FILES = {} |
FILES = {} |
497 |
TARBALLS = {} |
TARBALLS = {} |
498 |
|
|
499 |
for line in contents: |
for line in contents: |
500 |
try: |
try: |
501 |
srpm, filename = line.split(":") |
srpm, version, filename = line.split("|") |
502 |
except ValueError: |
except ValueError: |
503 |
print >>sys.stderr, line |
print >>sys.stderr, line |
504 |
continue |
continue |
510 |
module = fileinfo['module'] |
module = fileinfo['module'] |
511 |
|
|
512 |
if module not in TARBALLS: |
if module not in TARBALLS: |
513 |
TARBALLS[module] = set() |
TARBALLS[module] = {} |
514 |
TARBALLS[module].add(srpm) |
TARBALLS[module][srpm] = version |
515 |
|
|
516 |
if srpm not in FILES: |
if srpm not in FILES: |
517 |
FILES[srpm] = set() |
FILES[srpm] = set() |
528 |
|
|
529 |
if len(downstream[upstream]) != 1: |
if len(downstream[upstream]) != 1: |
530 |
# XXX - Make it more intelligent |
# XXX - Make it more intelligent |
531 |
raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream]))) |
raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream].keys()))) |
532 |
|
|
533 |
return list(downstream[upstream]) |
return downstream[upstream].keys() |
534 |
|
|
535 |
def write_file(path, data): |
def write_file(path, data): |
536 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
539 |
os.rename(fdst.name, path) |
os.rename(fdst.name, path) |
540 |
|
|
541 |
def cmd_co(options, parser): |
def cmd_co(options, parser): |
542 |
upstream = get_upstream_names() |
root = os.path.expanduser(PKGROOT) |
|
downstream, downstream_files = get_downstream_names() |
|
543 |
|
|
544 |
cwd = os.path.expanduser(PKGROOT) |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
545 |
|
print "%s => %s" % (module, package) |
546 |
|
subprocess.call(['mgarepo', 'co', package], cwd=root) |
547 |
|
|
548 |
matches = upstream & set(downstream.keys()) |
def join_streams(show_version=False, only_diff_version=False): |
549 |
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) |
|
550 |
|
|
|
def join_streams(): |
|
551 |
upstream = get_upstream_names() |
upstream = get_upstream_names() |
552 |
downstream, downstream_files = get_downstream_names() |
downstream, downstream_files = get_downstream_names() |
553 |
|
|
554 |
matches = upstream & set(downstream.keys()) |
matches = upstream & set(downstream.keys()) |
555 |
for module in matches: |
for module in matches: |
556 |
for package in downstream[module]: |
for package in downstream[module].keys(): |
557 |
yield (package, module) |
package_version = downstream[module][package] |
558 |
|
spec_version = None |
559 |
|
if show_version or only_diff_version: |
560 |
|
cwd = os.path.join(root, package) |
561 |
|
try: |
562 |
|
spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
563 |
|
except subprocess.CalledProcessError: |
564 |
|
spec_version = 'N/A' |
565 |
|
|
566 |
def cmd_ls(options, parser): |
if only_diff_version and package_version == spec_version: |
567 |
for package, module in sorted(join_streams()): |
continue |
|
print "\t".join((package, module)) if options.upstream else package |
|
568 |
|
|
569 |
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() |
|
570 |
|
|
571 |
path = os.path.expanduser(PKGROOT) |
def cmd_ls(options, parser): |
572 |
|
for package, module, package_version, spec_version, downstream_files in sorted(join_streams(show_version=options.show_version, only_diff_version=options.diff)): |
573 |
|
print package,"\t", |
574 |
|
if options.upstream: print module, "\t", |
575 |
|
if options.show_version: print spec_version, "\t", package_version, "\t", |
576 |
|
print |
577 |
|
|
578 |
import pprint |
def cmd_patches(options, parser): |
579 |
|
root = os.path.expanduser(PKGROOT) |
580 |
|
|
581 |
matches = upstream & set(downstream.keys()) |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
582 |
for module in sorted(matches): |
for filename in downstream_files: |
583 |
for srpm in downstream[module]: |
if '.patch' in filename or '.diff' in filename: |
584 |
for filename in downstream_files[srpm]: |
|
585 |
if '.patch' in filename or '.diff' in filename: |
p = Patch(os.path.join(root, package, "SOURCES", filename), show_path=options.path) |
586 |
|
valid = "" |
587 |
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path) |
forwarded = "" |
588 |
valid = "" |
if p.dep3['headers']: |
589 |
forwarded = "" |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
590 |
if p.dep3['headers']: |
if p.dep3['valid']: |
591 |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
valid="VALID" |
592 |
if p.dep3['valid']: |
print "\t".join((module, package, str(p), forwarded, valid)) |
|
valid="VALID" |
|
|
print "\t".join((module, srpm, str(p), forwarded, valid)) |
|
593 |
|
|
594 |
def cmd_dep3(options, parser): |
def cmd_dep3(options, parser): |
595 |
p = Patch(options.patch) |
p = Patch(options.patch) |
619 |
# SpecFile class handles the actual version+release change |
# SpecFile class handles the actual version+release change |
620 |
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
621 |
print "%s => %s" % (s.version, options.version) |
print "%s => %s" % (s.version, options.version) |
622 |
if not s.update(options.version): |
if not s.update(options.version, force=options.force): |
623 |
sys.exit(1) |
sys.exit(1) |
624 |
|
|
625 |
# Check hash, if given |
# Check hash, if given |
647 |
sys.exit(1) |
sys.exit(1) |
648 |
|
|
649 |
def cmd_parse_ftp_release_list(options, parser): |
def cmd_parse_ftp_release_list(options, parser): |
650 |
# XXX - not working yet |
def _send_reply_mail(contents, orig_msg, to, error=False): |
|
def _send_reply_mail(contents, orig_msg, to): |
|
651 |
"""Send an reply email""" |
"""Send an reply email""" |
652 |
contents.seek(0) |
contents.seek(0) |
653 |
msg = MIMEText(contents.read(), _charset='utf-8') |
msg = MIMEText(contents.read(), _charset='utf-8') |
654 |
msg['Subject'] = "Re: %s" % orig_msg['Subject'] |
if error: |
655 |
|
# XXX - ugly |
656 |
|
contents.seek(0) |
657 |
|
lastline = contents.read().splitlines()[-1] |
658 |
|
# Remove things like "ERROR: " and so on from the last line |
659 |
|
lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline) |
660 |
|
subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)" |
661 |
|
else: |
662 |
|
subjecterror = "" |
663 |
|
msg['Subject'] = "Re: %s%s" % (orig_msg['Subject'], subjecterror) |
664 |
msg['To'] = to |
msg['To'] = to |
665 |
msg["In-Reply-To"] = orig_msg["Message-ID"] |
msg["In-Reply-To"] = orig_msg["Message-ID"] |
666 |
msg["References"] = orig_msg["Message-ID"] |
msg["References"] = orig_msg["Message-ID"] |
678 |
msg = email.email.message_from_file(sys.stdin) |
msg = email.email.message_from_file(sys.stdin) |
679 |
|
|
680 |
if options.mail: |
if options.mail: |
681 |
stdout = tempfile.NamedTemporaryFile() |
stdout = tempfile.TemporaryFile() |
682 |
stderr = stdout |
stderr = stdout |
683 |
else: |
else: |
684 |
stdout = sys.stdout |
stdout = sys.stdout |
690 |
hexdigest = msg['X-Module-SHA256-tar.xz'] |
hexdigest = msg['X-Module-SHA256-tar.xz'] |
691 |
except KeyError, e: |
except KeyError, e: |
692 |
print >>stderr, "ERROR: %s" % e |
print >>stderr, "ERROR: %s" % e |
693 |
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
694 |
sys.exit(1) |
sys.exit(1) |
695 |
|
|
696 |
try: |
try: |
697 |
packages = get_downstream_from_upstream(module, version) |
packages = get_downstream_from_upstream(module, version) |
698 |
except ValueError, e: |
except ValueError, e: |
699 |
print >>stderr, "ERROR: %s" % e |
print >>stderr, "ERROR: %s" % e |
700 |
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
701 |
sys.exit(1) |
sys.exit(1) |
702 |
|
|
703 |
if options.wait: |
if options.wait: |
704 |
# maildrop aborts and will try to deliver after 5min |
# maildrop aborts and will try to deliver after 5min |
705 |
# fork to avoid this |
# fork to avoid this |
706 |
if os.fork() != 0: sys.exit(0) |
if os.fork() != 0: sys.exit(0) |
707 |
time.sleep(SLEEP_INITIAL) |
# wait SLEEP_INITIAL after the message was sent |
708 |
|
secs = SLEEP_INITIAL |
709 |
|
t = email.utils.parsedate_tz(msg['Date']) |
710 |
|
if t is not None: |
711 |
|
msg_time = email.utils.mktime_tz(t) |
712 |
|
secs = SLEEP_INITIAL - (time.time() - msg_time) |
713 |
|
|
714 |
|
if secs > 0: time.sleep(secs) |
715 |
|
|
716 |
|
error = False |
717 |
for package in packages: |
for package in packages: |
718 |
subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr) |
if subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr): |
719 |
|
error = True |
720 |
|
|
721 |
if options.mail: _send_reply_mail(stdout, msg, options.mail) |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=error) |
722 |
|
|
723 |
def main(): |
def main(): |
724 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
736 |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
737 |
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
738 |
help="Show upstream module") |
help="Show upstream module") |
739 |
|
subparser.add_argument( "--version", action="store_true", dest="show_version", |
740 |
|
help="Show version numbers") |
741 |
|
subparser.add_argument( "--diff", action="store_true", dest="diff", |
742 |
|
help="Only show packages with different version") |
743 |
subparser.set_defaults( |
subparser.set_defaults( |
744 |
func=cmd_ls, upstream=False |
func=cmd_ls, upstream=False, show_version=False, diff=False |
745 |
) |
) |
746 |
|
|
747 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
760 |
subparser = subparsers.add_parser('increase', help='Increase version number') |
subparser = subparsers.add_parser('increase', help='Increase version number') |
761 |
subparser.add_argument("package", help="Package name") |
subparser.add_argument("package", help="Package name") |
762 |
subparser.add_argument("version", help="Version number") |
subparser.add_argument("version", help="Version number") |
763 |
|
subparser.add_argument("-f", "--force", action="store_true", dest="force", |
764 |
|
help="Override warnings, just do it") |
765 |
subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream", |
subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream", |
766 |
help="Package name reflects the upstream name") |
help="Package name reflects the upstream name") |
767 |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
771 |
subparser.add_argument("--hash", dest="hexdigest", |
subparser.add_argument("--hash", dest="hexdigest", |
772 |
help="Hexdigest of the hash") |
help="Hexdigest of the hash") |
773 |
subparser.set_defaults( |
subparser.set_defaults( |
774 |
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", |
775 |
|
force=False |
776 |
) |
) |
777 |
|
|
778 |
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') |