diff options
author | Mike Frysinger <vapier@gentoo.org> | 2014-01-20 15:06:15 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2014-01-20 15:06:15 -0500 |
commit | 080519f882c622f4fbd44858801b39aaad4e88ad (patch) | |
tree | 77ce988a573d49a2e7df0faa892ee0d7aecb4137 | |
parent | ekeyword: make quiet/verbose flags a bit more flexible (diff) | |
download | gentoolkit-080519f882c622f4fbd44858801b39aaad4e88ad.tar.gz gentoolkit-080519f882c622f4fbd44858801b39aaad4e88ad.tar.bz2 gentoolkit-080519f882c622f4fbd44858801b39aaad4e88ad.zip |
ekeyword: skip known paths rather than fail
There are commonly files in an ebuild dir that we don't care about.
Issue a warning, but otherwise skip them without aborting. This let's
you do things like:
ekeyword x86 some-package/*
Which is nice when you know there's only one or two ebuilds in there.
-rwxr-xr-x | src/ekeyword/ekeyword.py | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py index 7a6c630..d8e0ed1 100755 --- a/src/ekeyword/ekeyword.py +++ b/src/ekeyword/ekeyword.py @@ -54,6 +54,10 @@ VERSION = '1.0 awesome' Op = collections.namedtuple('Op', ('op', 'arch', 'ref_arch')) +def warning(msg): + print('warning: %s' % msg, file=sys.stderr) + + def keyword_to_arch(keyword): """Given a keyword, strip it down to its arch value @@ -309,8 +313,8 @@ def load_profile_data(portdir=None, repo='gentoo'): if arch_status: arch_status['all'] = None else: - print('warning: could not read profile files: %s' % arch_list, file=sys.stderr) - print('warning: will not be able to verify args are correct', file=sys.stderr) + warning('could not read profile files: %s' % arch_list) + warning('will not be able to verify args are correct') return arch_status @@ -334,7 +338,30 @@ def arg_to_op(arg): return Op(op, arch, refarch) -def args_to_work(args, arch_status=None, repo='gentoo'): +def ignorable_arg(arg, quiet=0): + """Whether it's ok to ignore this argument""" + if os.path.isdir(arg): + if not quiet: + warning('ignoring directory %s' % arg) + return True + + WHITELIST = ( + 'Manifest', + 'metadata.xml', + ) + base = os.path.basename(arg) + if (base.startswith('ChangeLog') or + base in WHITELIST or + base.startswith('.') or + base.endswith('~')): + if not quiet: + warning('ignoring file: %s' % arg) + return True + + return False + + +def args_to_work(args, arch_status=None, repo='gentoo', quiet=0): """Process |args| into a list of work itmes (ebuild/arches to update)""" work = [] todo_arches = [] @@ -353,7 +380,7 @@ def args_to_work(args, arch_status=None, repo='gentoo'): op = arg_to_op(arg) if not arch_status or op.arch in arch_status: todo_arches.append(op) - else: + elif not ignorable_arg(arg, quiet=quiet): raise ValueError('unknown arch/argument: %s' % arg) if todo_arches: @@ -425,7 +452,7 @@ def main(argv): arch_status = load_profile_data() try: - work = args_to_work(work_args, arch_status=arch_status) + work = args_to_work(work_args, arch_status=arch_status, quiet=opts.quiet) except ValueError as e: parser.error(e) |