1 |
commit: 080519f882c622f4fbd44858801b39aaad4e88ad |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Jan 20 20:06:15 2014 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Jan 20 20:06:15 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=080519f8 |
7 |
|
8 |
ekeyword: skip known paths rather than fail |
9 |
|
10 |
There are commonly files in an ebuild dir that we don't care about. |
11 |
Issue a warning, but otherwise skip them without aborting. This let's |
12 |
you do things like: |
13 |
ekeyword x86 some-package/* |
14 |
|
15 |
Which is nice when you know there's only one or two ebuilds in there. |
16 |
|
17 |
--- |
18 |
src/ekeyword/ekeyword.py | 37 ++++++++++++++++++++++++++++++++----- |
19 |
1 file changed, 32 insertions(+), 5 deletions(-) |
20 |
|
21 |
diff --git a/src/ekeyword/ekeyword.py b/src/ekeyword/ekeyword.py |
22 |
index 7a6c630..d8e0ed1 100755 |
23 |
--- a/src/ekeyword/ekeyword.py |
24 |
+++ b/src/ekeyword/ekeyword.py |
25 |
@@ -54,6 +54,10 @@ VERSION = '1.0 awesome' |
26 |
Op = collections.namedtuple('Op', ('op', 'arch', 'ref_arch')) |
27 |
|
28 |
|
29 |
+def warning(msg): |
30 |
+ print('warning: %s' % msg, file=sys.stderr) |
31 |
+ |
32 |
+ |
33 |
def keyword_to_arch(keyword): |
34 |
"""Given a keyword, strip it down to its arch value |
35 |
|
36 |
@@ -309,8 +313,8 @@ def load_profile_data(portdir=None, repo='gentoo'): |
37 |
if arch_status: |
38 |
arch_status['all'] = None |
39 |
else: |
40 |
- print('warning: could not read profile files: %s' % arch_list, file=sys.stderr) |
41 |
- print('warning: will not be able to verify args are correct', file=sys.stderr) |
42 |
+ warning('could not read profile files: %s' % arch_list) |
43 |
+ warning('will not be able to verify args are correct') |
44 |
|
45 |
return arch_status |
46 |
|
47 |
@@ -334,7 +338,30 @@ def arg_to_op(arg): |
48 |
return Op(op, arch, refarch) |
49 |
|
50 |
|
51 |
-def args_to_work(args, arch_status=None, repo='gentoo'): |
52 |
+def ignorable_arg(arg, quiet=0): |
53 |
+ """Whether it's ok to ignore this argument""" |
54 |
+ if os.path.isdir(arg): |
55 |
+ if not quiet: |
56 |
+ warning('ignoring directory %s' % arg) |
57 |
+ return True |
58 |
+ |
59 |
+ WHITELIST = ( |
60 |
+ 'Manifest', |
61 |
+ 'metadata.xml', |
62 |
+ ) |
63 |
+ base = os.path.basename(arg) |
64 |
+ if (base.startswith('ChangeLog') or |
65 |
+ base in WHITELIST or |
66 |
+ base.startswith('.') or |
67 |
+ base.endswith('~')): |
68 |
+ if not quiet: |
69 |
+ warning('ignoring file: %s' % arg) |
70 |
+ return True |
71 |
+ |
72 |
+ return False |
73 |
+ |
74 |
+ |
75 |
+def args_to_work(args, arch_status=None, repo='gentoo', quiet=0): |
76 |
"""Process |args| into a list of work itmes (ebuild/arches to update)""" |
77 |
work = [] |
78 |
todo_arches = [] |
79 |
@@ -353,7 +380,7 @@ def args_to_work(args, arch_status=None, repo='gentoo'): |
80 |
op = arg_to_op(arg) |
81 |
if not arch_status or op.arch in arch_status: |
82 |
todo_arches.append(op) |
83 |
- else: |
84 |
+ elif not ignorable_arg(arg, quiet=quiet): |
85 |
raise ValueError('unknown arch/argument: %s' % arg) |
86 |
|
87 |
if todo_arches: |
88 |
@@ -425,7 +452,7 @@ def main(argv): |
89 |
|
90 |
arch_status = load_profile_data() |
91 |
try: |
92 |
- work = args_to_work(work_args, arch_status=arch_status) |
93 |
+ work = args_to_work(work_args, arch_status=arch_status, quiet=opts.quiet) |
94 |
except ValueError as e: |
95 |
parser.error(e) |