1 |
commit: 39c99972049624c2504358c8455680da6acaee08 |
2 |
Author: Slawek Lis <slis <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Mar 24 06:32:53 2014 +0000 |
4 |
Commit: Slawek Lis <slis <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Mar 24 06:32:53 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=39c99972 |
7 |
|
8 |
Moved option and config parsing into settings module |
9 |
|
10 |
--- |
11 |
pym/gentoolkit/revdep_rebuild/collect.py | 34 +-------- |
12 |
pym/gentoolkit/revdep_rebuild/rebuild.py | 83 +------------------- |
13 |
pym/gentoolkit/revdep_rebuild/settings.py | 121 ++++++++++++++++++++++++++++++ |
14 |
3 files changed, 123 insertions(+), 115 deletions(-) |
15 |
|
16 |
diff --git a/pym/gentoolkit/revdep_rebuild/collect.py b/pym/gentoolkit/revdep_rebuild/collect.py |
17 |
index 039dc76..2a431cb 100644 |
18 |
--- a/pym/gentoolkit/revdep_rebuild/collect.py |
19 |
+++ b/pym/gentoolkit/revdep_rebuild/collect.py |
20 |
@@ -12,6 +12,7 @@ import sys |
21 |
|
22 |
import portage |
23 |
from portage.output import blue, yellow |
24 |
+from .settings import parse_revdep_config |
25 |
|
26 |
|
27 |
if sys.hexversion < 0x3000000: |
28 |
@@ -87,39 +88,6 @@ def prepare_search_dirs(logger, settings): |
29 |
return (bin_dirs, lib_dirs) |
30 |
|
31 |
|
32 |
-def parse_revdep_config(revdep_confdir): |
33 |
- ''' Parses all files under and returns |
34 |
- tuple of: (masked_dirs, masked_files, search_dirs)''' |
35 |
- |
36 |
- search_dirs = set() |
37 |
- masked_dirs = set() |
38 |
- masked_files = set() |
39 |
- |
40 |
- for _file in os.listdir(revdep_confdir): |
41 |
- for line in open(os.path.join(revdep_confdir, _file)): |
42 |
- line = line.strip() |
43 |
- #first check for comment, we do not want to regex all lines |
44 |
- if not line.startswith('#'): |
45 |
- match = re.match('LD_LIBRARY_MASK=\\"([^"]+)\\"', line) |
46 |
- if match is not None: |
47 |
- masks = match.group(1).split(' ') |
48 |
- masked_files.update(masks) |
49 |
- continue |
50 |
- match = re.match('SEARCH_DIRS_MASK=\\"([^"]+)\\"', line) |
51 |
- if match is not None: |
52 |
- searches = match.group(1).split(' ') |
53 |
- for search in searches: |
54 |
- masked_dirs.update(glob.glob(search)) |
55 |
- continue |
56 |
- match = re.match('SEARCH_DIRS=\\"([^"]+)\\"', line) |
57 |
- if match is not None: |
58 |
- searches = match.group(1).split() |
59 |
- for search in searches: |
60 |
- search_dirs.update(glob.glob(search)) |
61 |
- continue |
62 |
- |
63 |
- return (masked_dirs, masked_files, search_dirs) |
64 |
- |
65 |
|
66 |
def collect_libraries_from_dir(dirs, mask, logger): |
67 |
''' Collects all libraries from specified list of directories. |
68 |
|
69 |
diff --git a/pym/gentoolkit/revdep_rebuild/rebuild.py b/pym/gentoolkit/revdep_rebuild/rebuild.py |
70 |
index 314fb1f..9d5bf9b 100644 |
71 |
--- a/pym/gentoolkit/revdep_rebuild/rebuild.py |
72 |
+++ b/pym/gentoolkit/revdep_rebuild/rebuild.py |
73 |
@@ -18,7 +18,6 @@ from __future__ import print_function |
74 |
|
75 |
import os |
76 |
import sys |
77 |
-import getopt |
78 |
import logging |
79 |
import subprocess |
80 |
import time |
81 |
@@ -30,7 +29,7 @@ from portage.output import bold, red, blue, yellow, nocolor |
82 |
from .analyse import analyse |
83 |
from .cache import check_temp_files, read_cache |
84 |
from .assign import get_slotted_cps |
85 |
-from .settings import DEFAULTS |
86 |
+from .settings import DEFAULTS, parse_options |
87 |
from .stuff import filter_masked |
88 |
from . import __version__ |
89 |
|
90 |
@@ -43,39 +42,6 @@ __productname__ = "revdep-ng" |
91 |
|
92 |
# functions |
93 |
|
94 |
-def print_usage(): |
95 |
- """Outputs the help message""" |
96 |
- print( APP_NAME + ': (' + VERSION +')') |
97 |
- print() |
98 |
- print('This is free software; see the source for copying conditions.') |
99 |
- print() |
100 |
- print('Usage: ' + APP_NAME + ' [OPTIONS] [--] [EMERGE_OPTIONS]') |
101 |
- print() |
102 |
- print('Broken reverse dependency rebuilder, python implementation.') |
103 |
- print() |
104 |
- print('Available options:') |
105 |
- print(''' |
106 |
- -C, --nocolor Turn off colored output |
107 |
- -d, --debug Print debug informations |
108 |
- -e, --exact Emerge based on exact package version |
109 |
- -h, --help Print this usage |
110 |
- -i, --ignore Ignore temporary files from previous runs |
111 |
- (also won't create any) |
112 |
- -L, --library NAME Unconditionally emerge existing packages that use |
113 |
- --library=NAME the library with NAME. NAME can be a full or partial |
114 |
- library name |
115 |
- -l, --no-ld-path Do not set LD_LIBRARY_PATH |
116 |
- -o, --no-order Do not check the build order |
117 |
- (Saves time, but may cause breakage.) |
118 |
- -p, --pretend Do a trial run without actually emerging anything |
119 |
- (also passed to emerge command) |
120 |
- -q, --quiet Be less verbose (also passed to emerge command) |
121 |
- -v, --verbose Be more verbose (also passed to emerge command) |
122 |
-''') |
123 |
- print( 'Calls emerge, options after -- are ignored by ' + APP_NAME) |
124 |
- print('and passed directly to emerge.') |
125 |
- |
126 |
- |
127 |
def init_logger(settings): |
128 |
"""Creates and iitializes our logger according to the settings""" |
129 |
logger = logging.getLogger() |
130 |
@@ -94,53 +60,6 @@ def init_logger(settings): |
131 |
return logger |
132 |
|
133 |
|
134 |
-def parse_options(): |
135 |
- """Parses the command line options an sets settings accordingly""" |
136 |
- |
137 |
- # TODO: Verify: options: no-ld-path, no-order, no-progress |
138 |
- #are not appliable |
139 |
- |
140 |
- settings = DEFAULTS.copy() |
141 |
- try: |
142 |
- opts, args = getopt.getopt(sys.argv[1:], |
143 |
- 'dehiklopqvCL:P', |
144 |
- ['nocolor', 'debug', 'exact', 'help', 'ignore', |
145 |
- 'keep-temp', 'library=', 'no-ld-path', 'no-order', |
146 |
- 'pretend', 'no-pretend', 'no-progress', 'quiet', 'verbose']) |
147 |
- |
148 |
- for key, val in opts: |
149 |
- if key in ('-h', '--help'): |
150 |
- print_usage() |
151 |
- sys.exit(0) |
152 |
- elif key in ('-q', '--quiet'): |
153 |
- settings['quiet'] = True |
154 |
- settings['VERBOSITY'] = 0 |
155 |
- elif key in ('-v', '--verbose'): |
156 |
- settings['VERBOSITY'] = 2 |
157 |
- elif key in ('-d', '--debug'): |
158 |
- settings['debug'] = True |
159 |
- settings['VERBOSITY'] = 3 |
160 |
- elif key in ('-p', '--pretend'): |
161 |
- settings['PRETEND'] = True |
162 |
- elif key == '--no-pretend': |
163 |
- settings['NO_PRETEND'] = True |
164 |
- elif key in ('-e', '--exact'): |
165 |
- settings['EXACT'] = True |
166 |
- elif key in ('-C', '--nocolor', '--no-color'): |
167 |
- settings['nocolor'] = True |
168 |
- elif key in ('-L', '--library', '--library='): |
169 |
- settings['library'].update(val.split(',')) |
170 |
- elif key in ('-i', '--ignore'): |
171 |
- settings['USE_TMP_FILES'] = False |
172 |
- |
173 |
- settings['pass_through_options'] = " " + " ".join(args) |
174 |
- except getopt.GetoptError: |
175 |
- #logging.info(red('Unrecognized option\n')) |
176 |
- print(red('Unrecognized option\n')) |
177 |
- print_usage() |
178 |
- sys.exit(2) |
179 |
- |
180 |
- return settings |
181 |
|
182 |
|
183 |
def rebuild(logger, assigned, settings): |
184 |
|
185 |
diff --git a/pym/gentoolkit/revdep_rebuild/settings.py b/pym/gentoolkit/revdep_rebuild/settings.py |
186 |
index 2d6046f..057147c 100644 |
187 |
--- a/pym/gentoolkit/revdep_rebuild/settings.py |
188 |
+++ b/pym/gentoolkit/revdep_rebuild/settings.py |
189 |
@@ -4,8 +4,11 @@ |
190 |
|
191 |
from __future__ import print_function |
192 |
|
193 |
+import getopt |
194 |
import os |
195 |
import sys |
196 |
+import re |
197 |
+import glob |
198 |
|
199 |
import portage |
200 |
|
201 |
@@ -43,3 +46,121 @@ DEFAULTS = { |
202 |
'stdin': sys.stdin, |
203 |
'stderr': sys.stderr |
204 |
} |
205 |
+ |
206 |
+ |
207 |
+def print_usage(): |
208 |
+ """Outputs the help message""" |
209 |
+ print( APP_NAME + ': (' + VERSION +')') |
210 |
+ print() |
211 |
+ print('This is free software; see the source for copying conditions.') |
212 |
+ print() |
213 |
+ print('Usage: ' + APP_NAME + ' [OPTIONS] [--] [EMERGE_OPTIONS]') |
214 |
+ print() |
215 |
+ print('Broken reverse dependency rebuilder, python implementation.') |
216 |
+ print() |
217 |
+ print('Available options:') |
218 |
+ print(''' |
219 |
+ -C, --nocolor Turn off colored output |
220 |
+ -d, --debug Print debug informations |
221 |
+ -e, --exact Emerge based on exact package version |
222 |
+ -h, --help Print this usage |
223 |
+ -i, --ignore Ignore temporary files from previous runs |
224 |
+ (also won't create any) |
225 |
+ -L, --library NAME Unconditionally emerge existing packages that use |
226 |
+ --library=NAME the library with NAME. NAME can be a full or partial |
227 |
+ library name |
228 |
+ -l, --no-ld-path Do not set LD_LIBRARY_PATH |
229 |
+ -o, --no-order Do not check the build order |
230 |
+ (Saves time, but may cause breakage.) |
231 |
+ -p, --pretend Do a trial run without actually emerging anything |
232 |
+ (also passed to emerge command) |
233 |
+ -q, --quiet Be less verbose (also passed to emerge command) |
234 |
+ -v, --verbose Be more verbose (also passed to emerge command) |
235 |
+''') |
236 |
+ print( 'Calls emerge, options after -- are ignored by ' + APP_NAME) |
237 |
+ print('and passed directly to emerge.') |
238 |
+ |
239 |
+ |
240 |
+def parse_options(): |
241 |
+ """Parses the command line options an sets settings accordingly""" |
242 |
+ |
243 |
+ # TODO: Verify: options: no-ld-path, no-order, no-progress |
244 |
+ #are not appliable |
245 |
+ |
246 |
+ settings = DEFAULTS.copy() |
247 |
+ try: |
248 |
+ opts, args = getopt.getopt(sys.argv[1:], |
249 |
+ 'dehiklopqvCL:P', |
250 |
+ ['nocolor', 'debug', 'exact', 'help', 'ignore', |
251 |
+ 'keep-temp', 'library=', 'no-ld-path', 'no-order', |
252 |
+ 'pretend', 'no-pretend', 'no-progress', 'quiet', 'verbose']) |
253 |
+ |
254 |
+ for key, val in opts: |
255 |
+ if key in ('-h', '--help'): |
256 |
+ print_usage() |
257 |
+ sys.exit(0) |
258 |
+ elif key in ('-q', '--quiet'): |
259 |
+ settings['quiet'] = True |
260 |
+ settings['VERBOSITY'] = 0 |
261 |
+ elif key in ('-v', '--verbose'): |
262 |
+ settings['VERBOSITY'] = 2 |
263 |
+ elif key in ('-d', '--debug'): |
264 |
+ settings['debug'] = True |
265 |
+ settings['VERBOSITY'] = 3 |
266 |
+ elif key in ('-p', '--pretend'): |
267 |
+ settings['PRETEND'] = True |
268 |
+ elif key == '--no-pretend': |
269 |
+ settings['NO_PRETEND'] = True |
270 |
+ elif key in ('-e', '--exact'): |
271 |
+ settings['EXACT'] = True |
272 |
+ elif key in ('-C', '--nocolor', '--no-color'): |
273 |
+ settings['nocolor'] = True |
274 |
+ elif key in ('-L', '--library', '--library='): |
275 |
+ settings['library'].update(val.split(',')) |
276 |
+ elif key in ('-i', '--ignore'): |
277 |
+ settings['USE_TMP_FILES'] = False |
278 |
+ |
279 |
+ settings['pass_through_options'] = " " + " ".join(args) |
280 |
+ except getopt.GetoptError: |
281 |
+ #logging.info(red('Unrecognized option\n')) |
282 |
+ print(red('Unrecognized option\n')) |
283 |
+ print_usage() |
284 |
+ sys.exit(2) |
285 |
+ |
286 |
+ return settings |
287 |
+ |
288 |
+ |
289 |
+def parse_revdep_config(revdep_confdir): |
290 |
+ ''' Parses all files under and returns |
291 |
+ tuple of: (masked_dirs, masked_files, search_dirs)''' |
292 |
+ |
293 |
+ search_dirs = set() |
294 |
+ masked_dirs = set() |
295 |
+ masked_files = set() |
296 |
+ |
297 |
+ for _file in os.listdir(revdep_confdir): |
298 |
+ for line in open(os.path.join(revdep_confdir, _file)): |
299 |
+ line = line.strip() |
300 |
+ #first check for comment, we do not want to regex all lines |
301 |
+ if not line.startswith('#'): |
302 |
+ match = re.match('LD_LIBRARY_MASK=\\"([^"]+)\\"', line) |
303 |
+ if match is not None: |
304 |
+ masks = match.group(1).split(' ') |
305 |
+ masked_files.update(masks) |
306 |
+ continue |
307 |
+ match = re.match('SEARCH_DIRS_MASK=\\"([^"]+)\\"', line) |
308 |
+ if match is not None: |
309 |
+ searches = match.group(1).split(' ') |
310 |
+ for search in searches: |
311 |
+ masked_dirs.update(glob.glob(search)) |
312 |
+ continue |
313 |
+ match = re.match('SEARCH_DIRS=\\"([^"]+)\\"', line) |
314 |
+ if match is not None: |
315 |
+ searches = match.group(1).split() |
316 |
+ for search in searches: |
317 |
+ search_dirs.update(glob.glob(search)) |
318 |
+ continue |
319 |
+ |
320 |
+ print (masked_dirs, masked_files, search_dirs) |
321 |
+ return (masked_dirs, masked_files, search_dirs) |
322 |
+ |