1 |
commit: 1d48ee7cff391940940520cee4135648f93e16f2 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu May 26 07:20:11 2011 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu May 26 07:20:11 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=1d48ee7c |
7 |
|
8 |
ebuild-generator: support option parsing. |
9 |
|
10 |
--- |
11 |
README | 4 ++-- |
12 |
ebuild-generator | 46 ++++++++++++++++++++++++++++++++++------------ |
13 |
2 files changed, 36 insertions(+), 14 deletions(-) |
14 |
|
15 |
diff --git a/README b/README |
16 |
index 2e916bf..82351ca 100644 |
17 |
--- a/README |
18 |
+++ b/README |
19 |
@@ -29,10 +29,10 @@ First you need to clone the two necessary git repos: |
20 |
git clone git://git.overlays.gentoo.org/proj/pms-test-suite-overlay.git |
21 |
|
22 |
Then run the `ebuild-generator` script, passing the path to the overlay as its |
23 |
-only argument: |
24 |
+-R option: |
25 |
|
26 |
cd pms-test-suite |
27 |
- ./ebuild-generator ../pms-test-suite-overlay |
28 |
+ ./ebuild-generator -R ../pms-test-suite-overlay |
29 |
|
30 |
|
31 |
<!-- vim:se syn=markdown :--> |
32 |
|
33 |
diff --git a/ebuild-generator b/ebuild-generator |
34 |
index a868aa4..4394a0e 100755 |
35 |
--- a/ebuild-generator |
36 |
+++ b/ebuild-generator |
37 |
@@ -3,35 +3,57 @@ |
38 |
# (c) 2011 Michał Górny <mgorny@g.o> |
39 |
# Released under the terms of the 2-clause BSD license. |
40 |
|
41 |
-import sys |
42 |
+import os.path, sys |
43 |
|
44 |
+from optparse import OptionParser |
45 |
+ |
46 |
+import PMSTestSuite |
47 |
from PMSTestSuite.library import load_library |
48 |
from PMSTestSuite.repository import EbuildRepository |
49 |
from PMSTestSuite.pm import get_package_managers |
50 |
|
51 |
-def main(*argv): |
52 |
- # XXX: optparse/argparse |
53 |
- if len(argv) < 2: |
54 |
- print('%s <repo-path>' % argv[0]) |
55 |
- return 1 |
56 |
+def main(prog, *args): |
57 |
+ opt = OptionParser( |
58 |
+ prog = os.path.basename(prog), |
59 |
+ version = PMSTestSuite.PV, |
60 |
+ description = 'Generate the ebuilds for a test library.' |
61 |
+ ) |
62 |
+ |
63 |
+ # XXX: -r for getting through PM's repo_name |
64 |
+ opt.add_option('-R', '--repository-path', dest='repo_path', |
65 |
+ help='Path to the repository to store ebuilds in') |
66 |
+ opt.add_option('-l', '--library', dest='library_name', |
67 |
+ help='Test library to use (default: standard)', |
68 |
+ default='standard') |
69 |
+ # XXX: get list, autodetect, more magic |
70 |
+ opt.add_option('-p', '--package-manager', dest='pm', |
71 |
+ help='Package manager to use', |
72 |
+ default='portage') |
73 |
|
74 |
- repo_path = argv[1] |
75 |
- library_name = 'standard' |
76 |
+ (opts, args) = opt.parse_args(list(args)) |
77 |
+ |
78 |
+ if not opts.repo_path: |
79 |
+ opt.error('--repository-path must be specified') |
80 |
+ |
81 |
+ for x in get_package_managers(): |
82 |
+ if x.name == opts.pm: |
83 |
+ pm = x.inst() |
84 |
+ break |
85 |
+ else: |
86 |
+ opt.error('Package manager not supported: %s' % opts.pm) |
87 |
|
88 |
try: |
89 |
- repo = EbuildRepository(repo_path) |
90 |
+ repo = EbuildRepository(opts.repo_path) |
91 |
except (OSError, IOError, ValueError) as e: |
92 |
print('Repository open failed: %s' % e) |
93 |
return 1 |
94 |
|
95 |
try: |
96 |
- lib = load_library(library_name) |
97 |
+ lib = load_library(opts.library_name) |
98 |
except (ImportError, TypeError) as e: |
99 |
print('Test library load failed: %s' % e) |
100 |
return 1 |
101 |
|
102 |
- pm = get_package_managers()[0].inst() |
103 |
- |
104 |
files = {} |
105 |
for t in lib: |
106 |
files.update(t.get_output_files()) |