49 |
# packages --sort |
# packages --sort |
50 |
import itertools |
import itertools |
51 |
|
|
52 |
MEDIA="Core Release Source" |
# check-latest |
53 |
URL="http://download.gnome.org/sources/" |
import requests |
54 |
PKGROOT='~/pkgs' |
|
55 |
SLEEP_INITIAL=180 |
SLEEP_INITIAL=180 |
56 |
SLEEP_REPEAT=30 |
SLEEP_REPEAT=30 |
57 |
SLEEP_TIMES=20 |
SLEEP_TIMES=20 |
82 |
latest = version |
latest = version |
83 |
return latest |
return latest |
84 |
|
|
85 |
|
def get_safe_max_version(version): |
86 |
|
if not re_majmin.match(version): |
87 |
|
return None |
88 |
|
|
89 |
|
majmin_nr = map(long, re_majmin.sub(r'\1', version).split('.')) |
90 |
|
|
91 |
|
if majmin_nr[1] % 2 == 0: |
92 |
|
return "%d.%d" % (majmin_nr[0], majmin_nr[1] + 1) |
93 |
|
else: |
94 |
|
return "%d.%d" % (majmin_nr[0], majmin_nr[1] + 2) |
95 |
|
|
96 |
def judge_version_increase(version_old, version_new): |
def judge_version_increase(version_old, version_new): |
97 |
"""Judge quality of version increase: |
"""Judge quality of version increase: |
98 |
|
|
501 |
|
|
502 |
class Upstream(object): |
class Upstream(object): |
503 |
|
|
504 |
|
URL="http://download.gnome.org/sources/" |
505 |
limit = None |
limit = None |
506 |
|
_cache_versions = {} |
507 |
|
|
508 |
def __init__(self): |
def __init__(self): |
509 |
urlopen = urllib2.build_opener() |
urlopen = urllib2.build_opener() |
511 |
good_dir = re.compile('^[-A-Za-z0-9_+.]+/$') |
good_dir = re.compile('^[-A-Za-z0-9_+.]+/$') |
512 |
|
|
513 |
# Get the files |
# Get the files |
514 |
usock = urlopen.open(URL) |
usock = urlopen.open(self.URL) |
515 |
parser = urllister() |
parser = urllister() |
516 |
parser.feed(usock.read()) |
parser.feed(usock.read()) |
517 |
usock.close() |
usock.close() |
524 |
|
|
525 |
self.names = tarballs |
self.names = tarballs |
526 |
|
|
527 |
|
@classmethod |
528 |
|
def versions(cls, module): |
529 |
|
# XXX - ugly |
530 |
|
if module not in cls._cache_versions: |
531 |
|
versions = None |
532 |
|
|
533 |
|
url = '%s%s/cache.json' % (cls.URL, module) |
534 |
|
r = requests.get(url) |
535 |
|
j = r.json |
536 |
|
if j is not None and len(j) > 2 and module in j[2]: |
537 |
|
versions = j[2][module] |
538 |
|
|
539 |
|
cls._cache_versions[module] = versions |
540 |
|
|
541 |
|
return cls._cache_versions[module] |
542 |
|
|
543 |
class Downstream(object): |
class Downstream(object): |
544 |
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]*)$') |
545 |
|
|
546 |
|
MEDIA="Core Release Source" |
547 |
|
PKGROOT='~/pkgs' |
548 |
|
DISTRO=None |
549 |
|
|
550 |
def __init__(self): |
def __init__(self): |
551 |
contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines() |
contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", self.MEDIA], close_fds=True).strip("\n").splitlines() |
552 |
|
|
553 |
FILES = {} |
FILES = {} |
554 |
TARBALLS = {} |
TARBALLS = {} |
577 |
self.tarballs = TARBALLS |
self.tarballs = TARBALLS |
578 |
self.files = FILES |
self.files = FILES |
579 |
|
|
580 |
|
@classmethod |
581 |
|
def co(cls, package, cwd=None): |
582 |
|
if cwd is None: |
583 |
|
cwd = os.path.expanduser(cls.PKGROOT) |
584 |
|
|
585 |
|
cmd = ['mgarepo', 'co'] |
586 |
|
if cls.DISTRO: |
587 |
|
cmd.extend(('-d', cls.DISTRO)) |
588 |
|
cmd.append(package) |
589 |
|
return subprocess.check_call(cmd, cwd=cwd) |
590 |
|
|
591 |
def get_downstream_from_upstream(self, upstream, version): |
def get_downstream_from_upstream(self, upstream, version): |
592 |
if upstream not in self.tarballs: |
if upstream not in self.tarballs: |
593 |
raise ValueError("No packages for upstream name: %s" % upstream) |
raise ValueError("No packages for upstream name: %s" % upstream) |
596 |
return self.tarballs[upstream].keys() |
return self.tarballs[upstream].keys() |
597 |
|
|
598 |
# Directories packages are located in |
# Directories packages are located in |
599 |
root = os.path.expanduser(PKGROOT) |
root = os.path.expanduser(self.PKGROOT) |
600 |
|
|
601 |
packages = {} |
packages = {} |
602 |
for package in self.tarballs[upstream].keys(): |
for package in self.tarballs[upstream].keys(): |
604 |
|
|
605 |
# Checkout package to ensure the checkout reflects the latest changes |
# Checkout package to ensure the checkout reflects the latest changes |
606 |
try: |
try: |
607 |
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
self.co(package, cwd=root) |
608 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
609 |
raise ValueError("Multiple packages found and cannot checkout %s" % package) |
raise ValueError("Multiple packages found and cannot checkout %s" % package) |
610 |
|
|
635 |
os.rename(fdst.name, path) |
os.rename(fdst.name, path) |
636 |
|
|
637 |
def cmd_co(options, parser): |
def cmd_co(options, parser): |
|
root = os.path.expanduser(PKGROOT) |
|
|
|
|
638 |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
639 |
print "%s => %s" % (module, package) |
print "%s => %s" % (module, package) |
640 |
subprocess.call(['mgarepo', 'co', package], cwd=root) |
try: |
641 |
|
Downstream.co(package) |
642 |
|
except subprocess.CalledProcessError: |
643 |
|
pass |
644 |
|
|
645 |
def join_streams(show_version=False, only_diff_version=False): |
def join_streams(show_version=False, only_diff_version=False): |
646 |
root = os.path.expanduser(PKGROOT) |
root = os.path.expanduser(Downstream.PKGROOT) |
647 |
|
|
648 |
upstream = Upstream().names |
upstream = Upstream().names |
649 |
downstream = Downstream() |
downstream = Downstream() |
680 |
if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version)) |
if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version)) |
681 |
print |
print |
682 |
|
|
683 |
|
def cmd_check_latest(options, parser): |
684 |
|
streams = join_streams(show_version=True) |
685 |
|
|
686 |
|
for package, module, package_version, spec_version, downstream_files in streams: |
687 |
|
sys.stdout.write(package) |
688 |
|
sys.stdout.write("\t%s\t%s" % (spec_version, package_version)) |
689 |
|
|
690 |
|
safe_max_version = get_safe_max_version(spec_version) |
691 |
|
|
692 |
|
versions = Upstream.versions(module) |
693 |
|
if versions: |
694 |
|
latest_version = get_latest_version(versions) |
695 |
|
safe_version = get_latest_version(versions, safe_max_version) |
696 |
|
|
697 |
|
if version_cmp(latest_version, spec_version) < 0: latest_version = 'N/A' |
698 |
|
if version_cmp(safe_version, spec_version) < 0: safe_version = 'N/A' |
699 |
|
|
700 |
|
sys.stdout.write("\t%s" % latest_version) |
701 |
|
sys.stdout.write("\t%s" % safe_version) |
702 |
|
print |
703 |
|
|
704 |
def cmd_patches(options, parser): |
def cmd_patches(options, parser): |
705 |
root = os.path.expanduser(PKGROOT) |
root = os.path.expanduser(Downstream.PKGROOT) |
706 |
|
|
707 |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
708 |
for filename in downstream_files: |
for filename in downstream_files: |
733 |
package = options.package |
package = options.package |
734 |
|
|
735 |
# Directories packages are located in |
# Directories packages are located in |
736 |
root = os.path.expanduser(PKGROOT) |
root = os.path.expanduser(Downstream.PKGROOT) |
737 |
cwd = os.path.join(root, package) |
cwd = os.path.join(root, package) |
738 |
|
|
739 |
# Checkout package to ensure the checkout reflects the latest changes |
# Checkout package to ensure the checkout reflects the latest changes |
740 |
try: |
try: |
741 |
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
Downstream.co(package, cwd=root) |
742 |
except subprocess.CalledProcessError: |
except subprocess.CalledProcessError: |
743 |
sys.exit(1) |
sys.exit(1) |
744 |
|
|
869 |
parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0), |
parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0), |
870 |
dest="limit_upstream", metavar="FILE", |
dest="limit_upstream", metavar="FILE", |
871 |
help="File containing upstream names") |
help="File containing upstream names") |
872 |
|
parser.add_argument("-d", "--distro", action="store", dest="distro", |
873 |
|
help="Distribution release") |
874 |
|
|
875 |
# SUBPARSERS |
# SUBPARSERS |
876 |
subparsers = parser.add_subparsers(title='subcommands') |
subparsers = parser.add_subparsers(title='subcommands') |
895 |
func=cmd_ls, upstream=False, show_version=False, diff=False |
func=cmd_ls, upstream=False, show_version=False, diff=False |
896 |
) |
) |
897 |
|
|
898 |
|
subparser = subparsers.add_parser('check-latest', help='check for latest version of packages') |
899 |
|
subparser.set_defaults( |
900 |
|
func=cmd_check_latest |
901 |
|
) |
902 |
|
|
903 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
904 |
subparser.add_argument("-p", "--path", action="store_true", dest="path", |
subparser.add_argument("-p", "--path", action="store_true", dest="path", |
905 |
help="Show full path to patch") |
help="Show full path to patch") |
927 |
subparser.add_argument("--hash", dest="hexdigest", |
subparser.add_argument("--hash", dest="hexdigest", |
928 |
help="Hexdigest of the hash") |
help="Hexdigest of the hash") |
929 |
subparser.set_defaults( |
subparser.set_defaults( |
930 |
func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256", |
func=cmd_package_new_version, submit=True, upstream=False, hexdigest=None, algo="sha256", |
931 |
force=False |
force=False |
932 |
) |
) |
933 |
|
|
951 |
if options.limit_upstream: |
if options.limit_upstream: |
952 |
Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines()) |
Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines()) |
953 |
|
|
954 |
|
if options.distro: |
955 |
|
Downstream.PKGROOT = os.path.join('~/pkgs', options.distro) |
956 |
|
Downstream.MEDIA = "Core Release %s Source" % options.distro |
957 |
|
Downstream.DISTRO = options.distro |
958 |
|
|
959 |
try: |
try: |
960 |
options.func(options, parser) |
options.func(options, parser) |
961 |
except KeyboardInterrupt: |
except KeyboardInterrupt: |