1 |
commit: f4b0e82bb93cc782f1aaf54748244c1f994e19e9 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun May 29 17:13:04 2011 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun May 29 17:13:04 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=f4b0e82b |
7 |
|
8 |
Move common CLI code to PMSTestSuite.cli. |
9 |
|
10 |
--- |
11 |
PMSTestSuite/cli.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 |
ebuild-generator | 60 ++++------------------------------- |
13 |
2 files changed, 92 insertions(+), 53 deletions(-) |
14 |
|
15 |
diff --git a/PMSTestSuite/cli.py b/PMSTestSuite/cli.py |
16 |
new file mode 100644 |
17 |
index 0000000..7e73fdd |
18 |
--- /dev/null |
19 |
+++ b/PMSTestSuite/cli.py |
20 |
@@ -0,0 +1,85 @@ |
21 |
+# vim:fileencoding=utf-8 |
22 |
+# (c) 2011 Michał Górny <mgorny@g.o> |
23 |
+# Released under the terms of the 2-clause BSD license. |
24 |
+ |
25 |
+import os.path |
26 |
+ |
27 |
+from optparse import OptionParser |
28 |
+ |
29 |
+from PMSTestSuite import PV |
30 |
+from PMSTestSuite.library import load_library |
31 |
+from PMSTestSuite.repository import EbuildRepository |
32 |
+from PMSTestSuite.pm import get_package_managers |
33 |
+ |
34 |
+class PMSTestSuiteCLI(object): |
35 |
+ """ |
36 |
+ A class encapsulating common CLI routines used by PMS Test Suite |
37 |
+ scripts. |
38 |
+ |
39 |
+ Properties: |
40 |
+ 1) set during __init__(): |
41 |
+ - optparser (OptionParser); |
42 |
+ 2) set during start(): |
43 |
+ - library (TestLibrary), |
44 |
+ - pm (PackageManager), |
45 |
+ - repository (EbuildRepository). |
46 |
+ """ |
47 |
+ |
48 |
+ def __init__(self, prog): |
49 |
+ """ |
50 |
+ Initialize the class. Set the option parser up. |
51 |
+ |
52 |
+ <prog> - program name for optparse output (argv[0]) |
53 |
+ """ |
54 |
+ opt = OptionParser( |
55 |
+ prog = os.path.basename(prog), |
56 |
+ version = PV |
57 |
+ ) |
58 |
+ |
59 |
+ # XXX: -r for getting through PM's repo_name |
60 |
+ opt.add_option('-R', '--repository-path', dest='repo_path', |
61 |
+ help='Path to the repository to store ebuilds in') |
62 |
+ opt.add_option('-l', '--library', dest='library_name', |
63 |
+ help='Test library to use (default: standard)', |
64 |
+ default='standard') |
65 |
+ # XXX: get list, autodetect, more magic |
66 |
+ opt.add_option('-p', '--package-manager', dest='pm', |
67 |
+ help='Package manager to use', |
68 |
+ default='portage') |
69 |
+ |
70 |
+ self.optparser = opt |
71 |
+ |
72 |
+ def start(self, args): |
73 |
+ """ |
74 |
+ Initialize the program. Parse command-line args. Instantiate classes |
75 |
+ encapsulating the Package Manager, test library and repository. |
76 |
+ |
77 |
+ <args> - command line args (argv[1:]) |
78 |
+ """ |
79 |
+ opt = self.optparser |
80 |
+ (opts, args) = opt.parse_args(list(args)) |
81 |
+ |
82 |
+ if not opts.repo_path: |
83 |
+ opt.error('--repository-path must be specified') |
84 |
+ |
85 |
+ for x in get_package_managers(): |
86 |
+ if x.name == opts.pm: |
87 |
+ try: |
88 |
+ self.pm = x.inst() |
89 |
+ except Exception as e: |
90 |
+ opt.error(e) |
91 |
+ break |
92 |
+ else: |
93 |
+ opt.error('Package manager not supported: %s' % opts.pm) |
94 |
+ |
95 |
+ try: |
96 |
+ self.repository = EbuildRepository(opts.repo_path) |
97 |
+ except (OSError, IOError, ValueError) as e: |
98 |
+ print('Repository open failed: %s' % e) |
99 |
+ return 1 |
100 |
+ |
101 |
+ try: |
102 |
+ self.test_library = load_library(opts.library_name) |
103 |
+ except (ImportError, TypeError) as e: |
104 |
+ print('Test library load failed: %s' % e) |
105 |
+ return 1 |
106 |
|
107 |
diff --git a/ebuild-generator b/ebuild-generator |
108 |
index 1db83ea..dd66b9f 100755 |
109 |
--- a/ebuild-generator |
110 |
+++ b/ebuild-generator |
111 |
@@ -3,66 +3,20 @@ |
112 |
# (c) 2011 Michał Górny <mgorny@g.o> |
113 |
# Released under the terms of the 2-clause BSD license. |
114 |
|
115 |
-import os.path, sys |
116 |
+import sys |
117 |
|
118 |
-from optparse import OptionParser |
119 |
- |
120 |
-import PMSTestSuite |
121 |
-from PMSTestSuite.library import load_library |
122 |
-from PMSTestSuite.repository import EbuildRepository |
123 |
-from PMSTestSuite.pm import get_package_managers |
124 |
+from PMSTestSuite.cli import PMSTestSuiteCLI |
125 |
|
126 |
def main(prog, *args): |
127 |
- opt = OptionParser( |
128 |
- prog = os.path.basename(prog), |
129 |
- version = PMSTestSuite.PV, |
130 |
- description = 'Generate the ebuilds for a test library.' |
131 |
- ) |
132 |
- |
133 |
- # XXX: -r for getting through PM's repo_name |
134 |
- opt.add_option('-R', '--repository-path', dest='repo_path', |
135 |
- help='Path to the repository to store ebuilds in') |
136 |
- opt.add_option('-l', '--library', dest='library_name', |
137 |
- help='Test library to use (default: standard)', |
138 |
- default='standard') |
139 |
- # XXX: get list, autodetect, more magic |
140 |
- opt.add_option('-p', '--package-manager', dest='pm', |
141 |
- help='Package manager to use', |
142 |
- default='portage') |
143 |
- |
144 |
- (opts, args) = opt.parse_args(list(args)) |
145 |
- |
146 |
- if not opts.repo_path: |
147 |
- opt.error('--repository-path must be specified') |
148 |
- |
149 |
- for x in get_package_managers(): |
150 |
- if x.name == opts.pm: |
151 |
- try: |
152 |
- pm = x.inst() |
153 |
- except Exception as e: |
154 |
- opt.error(e) |
155 |
- break |
156 |
- else: |
157 |
- opt.error('Package manager not supported: %s' % opts.pm) |
158 |
- |
159 |
- try: |
160 |
- repo = EbuildRepository(opts.repo_path) |
161 |
- except (OSError, IOError, ValueError) as e: |
162 |
- print('Repository open failed: %s' % e) |
163 |
- return 1 |
164 |
- |
165 |
- try: |
166 |
- lib = load_library(opts.library_name) |
167 |
- except (ImportError, TypeError) as e: |
168 |
- print('Test library load failed: %s' % e) |
169 |
- return 1 |
170 |
+ cli = PMSTestSuiteCLI(prog) |
171 |
+ cli.start(args) |
172 |
|
173 |
files = {} |
174 |
- for t in lib: |
175 |
+ for t in cli.test_library: |
176 |
files.update(t.get_output_files()) |
177 |
|
178 |
- repo.write_files(files) |
179 |
- repo.remanifest(files, pm) |
180 |
+ cli.repository.write_files(files) |
181 |
+ cli.repository.remanifest(files, cli.pm) |
182 |
|
183 |
if __name__ == '__main__': |
184 |
sys.exit(main(*sys.argv)) |