diff options
author | Sebastian Pipping <sebastian@pipping.org> | 2012-04-03 23:52:03 +0200 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2012-04-03 23:52:03 +0200 |
commit | 818d518ae65523d18032c4e3082e2ca099ca4d06 (patch) | |
tree | dc7c325d73d1353f7f72a001f54162edf541d95d | |
parent | Move towards print function (diff) | |
download | overlint-0.2.tar.gz overlint-0.2.tar.bz2 overlint-0.2.zip |
Require overlay location parameter (using argparse)v0.2
-rw-r--r-- | overlint/cli.py | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/overlint/cli.py b/overlint/cli.py index f660d94..10a3ef7 100644 --- a/overlint/cli.py +++ b/overlint/cli.py @@ -2,19 +2,29 @@ # Licender under GPL v2 or later from __future__ import print_function + +VERSION_STR = '0.2' + import sys import os import portage import re +try: + import argparse +except ImportError: + print("ERROR: You need Python 2.7+ unless you have module argparse " + "(package dev-python/argparse on Gentoo) installed independently.", file=sys.stderr) + sys.exit(1) + _revision_matcher = re.compile('-r([0-9]+)$') -def find_atoms(repo_folder, category_package): +def find_atoms(repository_path, category_package): versions = list() category, package = category_package.split('/') - for root, dirs, files in os.walk(os.path.join(repo_folder, category_package)): + for root, dirs, files in os.walk(os.path.join(repository_path, category_package)): for f in files: if not f.endswith('.ebuild'): continue @@ -74,7 +84,7 @@ def find_ebuild_changes(category_package, overlay_path, gentoo_versions, overlay ret = os.system(command) if not ret: continue - # print("meld '/usr/portage/%s/%s' '%s/%s/%s'" % (category_package, ebuild_name, overlay_path, category_package, ebuild_name)) + # print("meld '/usr/portage/%s/%s' '%s/%s/%s'" % (category_package, ebuild_name, conf.overlay_path, category_package, ebuild_name)) ebuild_changes.append(version) return ebuild_changes @@ -94,21 +104,42 @@ def dump_tree(tree, title): print() +def parse_command_line(args): + parser = argparse.ArgumentParser(description='Simple tool for static analysis of Gentoo overlays') + parser.add_argument( + '--version', + action='version', version='%(prog)s ' + VERSION_STR) + parser.add_argument('overlay_path', + metavar='PATH', action='store', + help='Path to Gentoo overlay') + conf = parser.parse_args(args=args[1:]) + + return conf + + def main(args): - overlay_path = '/var/lib/layman/pentoo' + conf = parse_command_line(args) + + def sanitize_overlay_path(path): + path = path.rstrip('/') + if path == '': + return '/' + return path + + conf.overlay_path = sanitize_overlay_path(conf.overlay_path) missed_revision_bumps_tree = dict() missed_version_bumps_tree = dict() ebuild_changes_tree = dict() - for root, dirs, files in os.walk(overlay_path): + for root, dirs, files in os.walk(conf.overlay_path): if '.svn' in dirs: dirs[:] = [d for d in dirs if d != '.svn'] for d in dirs: full_path_overlay = os.path.join(root, d) - category_package = full_path_overlay[len(overlay_path + '/'):] + category_package = full_path_overlay[len(conf.overlay_path + '/'):] if len(category_package.split('/')) != 2: continue full_path_gentoo = os.path.join('/usr/portage/', category_package) @@ -116,10 +147,10 @@ def main(args): if not found: continue - overlay_versions = find_atoms(overlay_path, category_package) + overlay_versions = find_atoms(conf.overlay_path, category_package) gentoo_versions = find_atoms('/usr/portage/', category_package) (missed_revision_bumps, missed_version_bumps) = find_missed_bumps(gentoo_versions, overlay_versions) - ebuild_changes = find_ebuild_changes(category_package, overlay_path, gentoo_versions, overlay_versions) + ebuild_changes = find_ebuild_changes(category_package, conf.overlay_path, gentoo_versions, overlay_versions) category, package = category_package.split('/') if missed_revision_bumps: missed_revision_bumps_tree.setdefault(category, dict())[package] = highest_revision_only(missed_revision_bumps) |