Loading src/bin/archversion +32 −12 Original line number Diff line number Diff line Loading @@ -50,6 +50,13 @@ def parse_argv(): help="sort listing") p_conf.add_argument("packages", nargs='*', help="only check these packages") p_conf.set_defaults(func=command_config) # sync parser p_sync = sp_main.add_parser("sync", help="retrieve upstream and dowstream versions") p_sync.add_argument("-s", "--sort", action="store_true", help="sort syncing") p_sync.add_argument("packages", nargs='*', help="only sync these packages") p_sync.set_defaults(func=command_sync) # cache parser p_cache = sp_main.add_parser("cache", aliases=["ca"], help="list cached verions") Loading @@ -63,20 +70,22 @@ def parse_argv(): p_modes = sp_main.add_parser("modes", aliases=["mo"], help="list check against modes") p_modes.set_defaults(func=command_modes) # check parser p_check = sp_main.add_parser("check", aliases=["ck", "ch"], help="check packages versions") p_check.add_argument("-c", "--diff-cache", action="store_true", # report parser p_report = sp_main.add_parser("report", aliases=["ck", "ch"], help="report packages versions") p_report.add_argument("-o", "--offline", action="store_true", help="use cached version as upstream. no network required") p_report.add_argument("-c", "--diff-cache", action="store_true", help="doesn't display cached versions") p_check.add_argument("-n", "--diff-new", action="store_true", p_report.add_argument("-n", "--diff-new", action="store_true", help="only display new versions") p_check.add_argument("-s", "--sort", action="store_true", p_report.add_argument("-s", "--sort", action="store_true", help="sort packages by name") p_check.add_argument("-S", "--no-save", dest="save", action="store_false", p_report.add_argument("-S", "--no-save", dest="save", action="store_false", help="don't save version updates in cache") p_check.add_argument("packages", nargs='*', help="only check these packages") p_check.set_defaults(func=command_check) p_report.add_argument("packages", nargs='*', help="only report these packages") p_report.set_defaults(func=command_report) # update parser p_update = sp_main.add_parser("update", aliases=["up"], help="update a PKGBUILD with the latest version") Loading Loading @@ -117,8 +126,19 @@ def command_modes(args, vctrl): '''list checking against modes''' vctrl.print_modes() def command_check(args, vctrl): '''Handle check command call''' def command_sync(args, vctrl): '''Handle sync command call''' # reduce the package list if len(args.packages) > 0: vctrl.reduce_packages(args.packages) # sort packages if asked if args.sort: vctrl.sort_packages() # start syncing vctrl.sync_packages() def command_report(args, vctrl): '''Handle report command call''' # reduce the package list if len(args.packages) > 0: vctrl.reduce_packages(args.packages) Loading src/lib/archversion/version.py +61 −23 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ from archversion.pacman import parse_pkgbuild, Pacman from archversion.error import InvalidConfigFile, VersionNotFound from collections import OrderedDict from urllib.request import urlopen, Request from time import time import fnmatch import json import logging Loading @@ -41,17 +42,13 @@ class VersionController(object): def __init__(self, packages, cache): self.packages = packages # set cache if cache is None: cache = {} if set(cache.keys()) != set(("downstream", "report", "upstream")): logging.debug("Invalid cache, purging it") cache.clear() cache["upstream"] = {} cache["downstream"] = {} cache["report"] = {} self.cache = cache # populate compare table self.compare_table = {} for mode in fnmatch.filter(dir(self), "get_version_*"): # we ignore get_version_upstream # because we get mode to check against it if mode == "get_version_upstream": continue self.compare_table[mode[12:]] = getattr(self, mode) def reduce_packages(self, packages): '''Keep only the give packages list''' Loading Loading @@ -122,7 +119,15 @@ class VersionController(object): assert(False) @staticmethod def get_version_pacman(name, value): def get_version_downstream(name, value, mode): '''Return dowstream version''' try: return getattr(VersionController, "get_version_downstream_%s" % mode)(name, value) except AttributeError: raise InvalidConfigFile("Invalid dowstream mode") @staticmethod def get_version_downstream_pacman(name, value): '''Return pacman version''' logging.debug("Get pacman version") # Load pacman Loading @@ -139,7 +144,7 @@ class VersionController(object): raise VersionNotFound("No pacman package found") @staticmethod def get_version_archweb(name, value): def get_version_downstream_archweb(name, value): '''Return archweb version''' logging.debug("Get archweb version") # if arch is specified Loading Loading @@ -168,7 +173,7 @@ class VersionController(object): raise VersionNotFound("No Archweb package found") @staticmethod def get_version_aur(name, value): def get_version_downstream_aur(name, value): '''Return archlinux user repository version''' logging.debug("Get AUR version") try: Loading @@ -188,7 +193,7 @@ class VersionController(object): assert(False) @staticmethod def get_version_abs(name, value): def get_version_downstream_abs(name, value): '''Return abs version''' logging.debug("Get ABS version") # Get ABS tree path Loading Loading @@ -219,16 +224,49 @@ class VersionController(object): return v raise VersionNotFound("No ABS package found") def get_version_cache(self, name, value): '''Return cache version''' v_cache = self.cache.get(name, None) logging.debug("Cache version is : %s" % v_cache) return v_cache @staticmethod def get_version_none(name, value): '''Return cache version''' return None def get_version_downstream_none(name, value): '''Return none version''' return "" def sync_packages(self): ''' Retrieve upstream and downstream versions and store them in cache ''' try: for name, value in self.packages.items(): logging.debug("Syncing versions of package %s" % name) # get upstream version v_upstream = self.get_version_upstream(name, value) # apply eval to upstream e_upstream = value.get("eval_upstream", None) if e_upstream is not None: v_upstream = eval(e_upstream, {}, {"version": v_upstream}) logging.debug("eval_upstream produce version: %s" % v_upstream) # save upstream version if v_upstream is not None: self.cache["upstream"][name] = {"version": v_upstream, "epoch": int(time())} else: logging.warning("%s: Upstream version not found." % name) # get downstream mode mode = value.get("downstream", None) if mode is None: logging.warning("%s: Invalid downstream mode: %s." % (name, mode)) continue # get downstream version v_downstream = self.get_version_downstream(name, value, mode) # apply eval to downstream e_compare = value.get("eval_downstream", None) if e_compare is not None: v_compare = eval(e_compare, {}, {"version": v_compare}) logging.debug("eval_downstream produce version: %s" % v_downstream) # save downstream version if v_downstream is not None: self.cache["downstream"][name] = {"version": v_downstream, "epoch": int(time())} else: logging.warning("%s: Downstream version not found." % name) finally: self.cache.save() def check_versions(self, only_new=False, not_in_cache=False): ''' Loading Loading
src/bin/archversion +32 −12 Original line number Diff line number Diff line Loading @@ -50,6 +50,13 @@ def parse_argv(): help="sort listing") p_conf.add_argument("packages", nargs='*', help="only check these packages") p_conf.set_defaults(func=command_config) # sync parser p_sync = sp_main.add_parser("sync", help="retrieve upstream and dowstream versions") p_sync.add_argument("-s", "--sort", action="store_true", help="sort syncing") p_sync.add_argument("packages", nargs='*', help="only sync these packages") p_sync.set_defaults(func=command_sync) # cache parser p_cache = sp_main.add_parser("cache", aliases=["ca"], help="list cached verions") Loading @@ -63,20 +70,22 @@ def parse_argv(): p_modes = sp_main.add_parser("modes", aliases=["mo"], help="list check against modes") p_modes.set_defaults(func=command_modes) # check parser p_check = sp_main.add_parser("check", aliases=["ck", "ch"], help="check packages versions") p_check.add_argument("-c", "--diff-cache", action="store_true", # report parser p_report = sp_main.add_parser("report", aliases=["ck", "ch"], help="report packages versions") p_report.add_argument("-o", "--offline", action="store_true", help="use cached version as upstream. no network required") p_report.add_argument("-c", "--diff-cache", action="store_true", help="doesn't display cached versions") p_check.add_argument("-n", "--diff-new", action="store_true", p_report.add_argument("-n", "--diff-new", action="store_true", help="only display new versions") p_check.add_argument("-s", "--sort", action="store_true", p_report.add_argument("-s", "--sort", action="store_true", help="sort packages by name") p_check.add_argument("-S", "--no-save", dest="save", action="store_false", p_report.add_argument("-S", "--no-save", dest="save", action="store_false", help="don't save version updates in cache") p_check.add_argument("packages", nargs='*', help="only check these packages") p_check.set_defaults(func=command_check) p_report.add_argument("packages", nargs='*', help="only report these packages") p_report.set_defaults(func=command_report) # update parser p_update = sp_main.add_parser("update", aliases=["up"], help="update a PKGBUILD with the latest version") Loading Loading @@ -117,8 +126,19 @@ def command_modes(args, vctrl): '''list checking against modes''' vctrl.print_modes() def command_check(args, vctrl): '''Handle check command call''' def command_sync(args, vctrl): '''Handle sync command call''' # reduce the package list if len(args.packages) > 0: vctrl.reduce_packages(args.packages) # sort packages if asked if args.sort: vctrl.sort_packages() # start syncing vctrl.sync_packages() def command_report(args, vctrl): '''Handle report command call''' # reduce the package list if len(args.packages) > 0: vctrl.reduce_packages(args.packages) Loading
src/lib/archversion/version.py +61 −23 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ from archversion.pacman import parse_pkgbuild, Pacman from archversion.error import InvalidConfigFile, VersionNotFound from collections import OrderedDict from urllib.request import urlopen, Request from time import time import fnmatch import json import logging Loading @@ -41,17 +42,13 @@ class VersionController(object): def __init__(self, packages, cache): self.packages = packages # set cache if cache is None: cache = {} if set(cache.keys()) != set(("downstream", "report", "upstream")): logging.debug("Invalid cache, purging it") cache.clear() cache["upstream"] = {} cache["downstream"] = {} cache["report"] = {} self.cache = cache # populate compare table self.compare_table = {} for mode in fnmatch.filter(dir(self), "get_version_*"): # we ignore get_version_upstream # because we get mode to check against it if mode == "get_version_upstream": continue self.compare_table[mode[12:]] = getattr(self, mode) def reduce_packages(self, packages): '''Keep only the give packages list''' Loading Loading @@ -122,7 +119,15 @@ class VersionController(object): assert(False) @staticmethod def get_version_pacman(name, value): def get_version_downstream(name, value, mode): '''Return dowstream version''' try: return getattr(VersionController, "get_version_downstream_%s" % mode)(name, value) except AttributeError: raise InvalidConfigFile("Invalid dowstream mode") @staticmethod def get_version_downstream_pacman(name, value): '''Return pacman version''' logging.debug("Get pacman version") # Load pacman Loading @@ -139,7 +144,7 @@ class VersionController(object): raise VersionNotFound("No pacman package found") @staticmethod def get_version_archweb(name, value): def get_version_downstream_archweb(name, value): '''Return archweb version''' logging.debug("Get archweb version") # if arch is specified Loading Loading @@ -168,7 +173,7 @@ class VersionController(object): raise VersionNotFound("No Archweb package found") @staticmethod def get_version_aur(name, value): def get_version_downstream_aur(name, value): '''Return archlinux user repository version''' logging.debug("Get AUR version") try: Loading @@ -188,7 +193,7 @@ class VersionController(object): assert(False) @staticmethod def get_version_abs(name, value): def get_version_downstream_abs(name, value): '''Return abs version''' logging.debug("Get ABS version") # Get ABS tree path Loading Loading @@ -219,16 +224,49 @@ class VersionController(object): return v raise VersionNotFound("No ABS package found") def get_version_cache(self, name, value): '''Return cache version''' v_cache = self.cache.get(name, None) logging.debug("Cache version is : %s" % v_cache) return v_cache @staticmethod def get_version_none(name, value): '''Return cache version''' return None def get_version_downstream_none(name, value): '''Return none version''' return "" def sync_packages(self): ''' Retrieve upstream and downstream versions and store them in cache ''' try: for name, value in self.packages.items(): logging.debug("Syncing versions of package %s" % name) # get upstream version v_upstream = self.get_version_upstream(name, value) # apply eval to upstream e_upstream = value.get("eval_upstream", None) if e_upstream is not None: v_upstream = eval(e_upstream, {}, {"version": v_upstream}) logging.debug("eval_upstream produce version: %s" % v_upstream) # save upstream version if v_upstream is not None: self.cache["upstream"][name] = {"version": v_upstream, "epoch": int(time())} else: logging.warning("%s: Upstream version not found." % name) # get downstream mode mode = value.get("downstream", None) if mode is None: logging.warning("%s: Invalid downstream mode: %s." % (name, mode)) continue # get downstream version v_downstream = self.get_version_downstream(name, value, mode) # apply eval to downstream e_compare = value.get("eval_downstream", None) if e_compare is not None: v_compare = eval(e_compare, {}, {"version": v_compare}) logging.debug("eval_downstream produce version: %s" % v_downstream) # save downstream version if v_downstream is not None: self.cache["downstream"][name] = {"version": v_downstream, "epoch": int(time())} else: logging.warning("%s: Downstream version not found." % name) finally: self.cache.save() def check_versions(self, only_new=False, not_in_cache=False): ''' Loading