1 |
commit: a79acc064e4bf9ba97e33b6fd66329f2fee9014d |
2 |
Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
3 |
AuthorDate: Sat Feb 19 18:08:14 2011 +0000 |
4 |
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> |
5 |
CommitDate: Thu Feb 24 06:49:46 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=a79acc06 |
7 |
|
8 |
separate out ArgsParser to it's own file and subclass BareConfig |
9 |
|
10 |
--- |
11 |
bin/layman | 2 +- |
12 |
layman/argsparser.py | 333 +++++++++++++++++++++++++++++++++++++++++ |
13 |
layman/config.py | 404 ++++++-------------------------------------------- |
14 |
3 files changed, 383 insertions(+), 356 deletions(-) |
15 |
|
16 |
diff --git a/bin/layman b/bin/layman |
17 |
index 965d89b..5723a58 100755 |
18 |
--- a/bin/layman |
19 |
+++ b/bin/layman |
20 |
@@ -24,7 +24,7 @@ __version__ = "$Id$" |
21 |
# |
22 |
#------------------------------------------------------------------------------- |
23 |
|
24 |
-from layman.config import ArgsParser |
25 |
+from layman.argsparser import ArgsParser |
26 |
from layman.cli import Main |
27 |
|
28 |
#=============================================================================== |
29 |
|
30 |
diff --git a/layman/argsparser.py b/layman/argsparser.py |
31 |
new file mode 100644 |
32 |
index 0000000..ff7f8f7 |
33 |
--- /dev/null |
34 |
+++ b/layman/argsparser.py |
35 |
@@ -0,0 +1,333 @@ |
36 |
+#!/usr/bin/python |
37 |
+# -*- coding: utf-8 -*- |
38 |
+################################################################################# |
39 |
+# LAYMAN CONFIGURATION |
40 |
+################################################################################# |
41 |
+# File: argsparser.py |
42 |
+# |
43 |
+# Handles layman command line interface configuration |
44 |
+# |
45 |
+# Copyright: |
46 |
+# (c) 2005 - 2009 Gunnar Wrobel |
47 |
+# (c) 2009 Sebastian Pipping |
48 |
+# (c) 2010 - 2011 Brian Dolbec |
49 |
+# Distributed under the terms of the GNU General Public License v2 |
50 |
+# |
51 |
+# Author(s): |
52 |
+# Gunnar Wrobel <wrobel@g.o> |
53 |
+# Sebastian Pipping <sebastian@×××××××.org> |
54 |
+# Brian Dolbec <brian.dolbec@×××××.com> |
55 |
+# |
56 |
+'''Defines the configuration options and provides parsing functionality.''' |
57 |
+ |
58 |
+__version__ = "$Id: config.py 286 2007-01-09 17:48:23Z wrobel $" |
59 |
+ |
60 |
+#=============================================================================== |
61 |
+# |
62 |
+# Dependencies |
63 |
+# |
64 |
+#------------------------------------------------------------------------------- |
65 |
+ |
66 |
+import sys |
67 |
+ |
68 |
+from optparse import OptionParser, OptionGroup |
69 |
+ |
70 |
+from layman.config import BareConfig |
71 |
+from layman.constants import OFF |
72 |
+from layman.version import VERSION |
73 |
+ |
74 |
+ |
75 |
+_USAGE = """ |
76 |
+ layman (-a|-d|-s|-i) (OVERLAY|ALL) |
77 |
+ layman -f [-o URL] |
78 |
+ layman (-l|-L|-S)""" |
79 |
+ |
80 |
+ |
81 |
+class ArgsParser(BareConfig): |
82 |
+ '''Handles the configuration and option parser.''' |
83 |
+ |
84 |
+ def __init__(self, args=None, stdout=None, stdin=None, stderr=None): |
85 |
+ ''' |
86 |
+ Creates and describes all possible polymeraZe options and creates |
87 |
+ a debugging object. |
88 |
+ |
89 |
+ >>> import os.path |
90 |
+ >>> here = os.path.dirname(os.path.realpath(__file__)) |
91 |
+ >>> sys.argv.append('--config') |
92 |
+ >>> sys.argv.append(here + '/../etc/layman.cfg') |
93 |
+ >>> a = ArgsParser() |
94 |
+ >>> a['overlays'] |
95 |
+ '\\nhttp://www.gentoo.org/proj/en/overlays/repositories.xml' |
96 |
+ >>> sorted(a.keys()) |
97 |
+ ['bzr_command', 'cache', 'config', 'cvs_command', 'darcs_command', |
98 |
+ 'git_command', 'local_list', 'make_conf', 'mercurial_command', |
99 |
+ 'nocheck', 'overlays', 'proxy', 'quietness', 'rsync_command', 'storage', |
100 |
+ 'svn_command', 'tar_command', 'umask', 'width'] |
101 |
+ ''' |
102 |
+ |
103 |
+ BareConfig.__init__(self, stdout=stdout, stderr=stderr, stdin=stdin) |
104 |
+ if args == None: |
105 |
+ args = sys.argv |
106 |
+ |
107 |
+ # get a couple BareConfig items |
108 |
+ self.defaults = self.get_defaults() |
109 |
+ self.output = self.get_option('output') |
110 |
+ |
111 |
+ self.parser = OptionParser( |
112 |
+ usage = _USAGE, |
113 |
+ version = VERSION) |
114 |
+ |
115 |
+ #----------------------------------------------------------------- |
116 |
+ # Main Options |
117 |
+ |
118 |
+ group = OptionGroup(self.parser, |
119 |
+ '<Actions>') |
120 |
+ |
121 |
+ group.add_option('-a', |
122 |
+ '--add', |
123 |
+ action = 'append', |
124 |
+ help = 'Add the given overlay from the cached remote li' |
125 |
+ 'st to your locally installed overlays.. Specify "ALL" ' |
126 |
+ 'to add all overlays from the remote list.') |
127 |
+ |
128 |
+ group.add_option('-d', |
129 |
+ '--delete', |
130 |
+ action = 'append', |
131 |
+ help = 'Remove the given overlay from your locally inst' |
132 |
+ 'alled overlays. Specify "ALL" to remove all overlays') |
133 |
+ |
134 |
+ group.add_option('-s', |
135 |
+ '--sync', |
136 |
+ action = 'append', |
137 |
+ help = 'Update the specified overlay. Use "ALL" as para' |
138 |
+ 'meter to synchronize all overlays') |
139 |
+ |
140 |
+ group.add_option('-i', |
141 |
+ '--info', |
142 |
+ action = 'append', |
143 |
+ help = 'Display information about the specified overlay' |
144 |
+ '.') |
145 |
+ |
146 |
+ group.add_option('-S', |
147 |
+ '--sync-all', |
148 |
+ action = 'store_true', |
149 |
+ help = 'Update all overlays.') |
150 |
+ |
151 |
+ group.add_option('-L', |
152 |
+ '--list', |
153 |
+ action = 'store_true', |
154 |
+ help = 'List the contents of the remote list.') |
155 |
+ |
156 |
+ group.add_option('-l', |
157 |
+ '--list-local', |
158 |
+ action = 'store_true', |
159 |
+ help = 'List the locally installed overlays.') |
160 |
+ |
161 |
+ group.add_option('-f', |
162 |
+ '--fetch', |
163 |
+ action = 'store_true', |
164 |
+ help = 'Fetch a remote list of overlays. This option is' |
165 |
+ ' deprecated. The fetch operation will be performed by ' |
166 |
+ 'default when you run sync, sync-all, or list.') |
167 |
+ |
168 |
+ group.add_option('-n', |
169 |
+ '--nofetch', |
170 |
+ action = 'store_true', |
171 |
+ help = 'Do not fetch a remote list of overlays.') |
172 |
+ |
173 |
+ group.add_option('-p', |
174 |
+ '--priority', |
175 |
+ action = 'store', |
176 |
+ help = 'Use this with the --add switch to set the prior' |
177 |
+ 'ity of the added overlay. This will influence the sort' |
178 |
+ 'ing order of the overlays in the PORTDIR_OVERLAY varia' |
179 |
+ 'ble.') |
180 |
+ |
181 |
+ self.parser.add_option_group(group) |
182 |
+ |
183 |
+ #----------------------------------------------------------------- |
184 |
+ # Additional Options |
185 |
+ |
186 |
+ group = OptionGroup(self.parser, |
187 |
+ '<Path options>') |
188 |
+ |
189 |
+ group.add_option('-c', |
190 |
+ '--config', |
191 |
+ action = 'store', |
192 |
+ help = 'Path to the config file [default: ' \ |
193 |
+ + self.defaults['config'] + '].') |
194 |
+ |
195 |
+ group.add_option('-o', |
196 |
+ '--overlays', |
197 |
+ action = 'append', |
198 |
+ help = 'The list of overlays [default: ' \ |
199 |
+ + self.defaults['overlays'] + '].') |
200 |
+ |
201 |
+ self.parser.add_option_group(group) |
202 |
+ |
203 |
+ #----------------------------------------------------------------- |
204 |
+ # Output Options |
205 |
+ |
206 |
+ group = OptionGroup(self.parser, |
207 |
+ '<Output options>') |
208 |
+ |
209 |
+ group.add_option('-v', |
210 |
+ '--verbose', |
211 |
+ action = 'store_true', |
212 |
+ help = 'Increase the amount of output and describe the ' |
213 |
+ 'overlays.') |
214 |
+ |
215 |
+ group.add_option('-q', |
216 |
+ '--quiet', |
217 |
+ action = 'store_true', |
218 |
+ help = 'Yield no output. Please be careful with this op' |
219 |
+ 'tion: If the processes spawned by layman when adding o' |
220 |
+ 'r synchronizing overlays require any input layman will' |
221 |
+ ' hang without telling you why. This might happen for e' |
222 |
+ 'xample if your overlay resides in subversion and the S' |
223 |
+ 'SL certificate of the server needs acceptance.') |
224 |
+ |
225 |
+ group.add_option('-N', |
226 |
+ '--nocolor', |
227 |
+ action = 'store_true', |
228 |
+ help = 'Remove color codes from the layman output.') |
229 |
+ |
230 |
+ group.add_option('-Q', |
231 |
+ '--quietness', |
232 |
+ action = 'store', |
233 |
+ type = 'int', |
234 |
+ default = '4', |
235 |
+ help = 'Set the level of output (0-4). Default: 4. Once' |
236 |
+ ' you set this below 2 the same warning as given for --' |
237 |
+ 'quiet applies! ') |
238 |
+ |
239 |
+ group.add_option('-W', |
240 |
+ '--width', |
241 |
+ action = 'store', |
242 |
+ type = 'int', |
243 |
+ default = '0', |
244 |
+ help = 'Sets the screen width. This setting is usually ' |
245 |
+ 'not required as layman is capable of detecting the ' |
246 |
+ 'available number of columns automatically.') |
247 |
+ |
248 |
+ group.add_option('-k', |
249 |
+ '--nocheck', |
250 |
+ action = 'store_true', |
251 |
+ help = 'Do not check overlay definitions and do not i' |
252 |
+ 'ssue a warning if description or contact information' |
253 |
+ ' are missing.') |
254 |
+ |
255 |
+ self.parser.add_option_group(group) |
256 |
+ |
257 |
+ #----------------------------------------------------------------- |
258 |
+ # Debug Options |
259 |
+ |
260 |
+ #self.output.cli_opts(self.parser) |
261 |
+ |
262 |
+ # Parse the command line first since we need to get the config |
263 |
+ # file option. |
264 |
+ if len(args) == 1: |
265 |
+ print 'Usage:%s' % _USAGE |
266 |
+ sys.exit(0) |
267 |
+ |
268 |
+ (self.options, remain_args) = self.parser.parse_args(args) |
269 |
+ # remain_args starts with something like "bin/layman" ... |
270 |
+ if len(remain_args) > 1: |
271 |
+ self.parser.error("Unhandled parameters: %s" |
272 |
+ % ', '.join(('"%s"' % e) for e in remain_args[1:])) |
273 |
+ |
274 |
+ # handle debugging |
275 |
+ #self.output.cli_handle(self.options) |
276 |
+ |
277 |
+ if self.options.__dict__['nocolor']: |
278 |
+ self.output.set_colorize(OFF) |
279 |
+ |
280 |
+ # Fetch only an alternate config setting from the options |
281 |
+ #if not self.options.__dict__['config'] is None: |
282 |
+ # self._defaults['config'] = self.options.__dict__['config'] |
283 |
+ |
284 |
+ #self.output.debug('Got config file at ' + self.defaults['config'], 8) |
285 |
+ |
286 |
+ # Now parse the config file |
287 |
+ self.read_config(self._defaults) |
288 |
+ |
289 |
+ # handle quietness |
290 |
+ if self['quiet']: |
291 |
+ self.set_option('quiet', True) |
292 |
+ elif self.options.__dict__['quietness']: |
293 |
+ self.set_option('quietness', self.options.__dict__['quietness']) |
294 |
+ |
295 |
+ #self.output.debug('Reading config file at ' + self.defaults['config'], 8) |
296 |
+ |
297 |
+ self.read_config(self.defaults) |
298 |
+ |
299 |
+ def __getitem__(self, key): |
300 |
+ |
301 |
+ if key == 'overlays': |
302 |
+ overlays = '' |
303 |
+ if (key in self.options.__dict__.keys() |
304 |
+ and not self.options.__dict__[key] is None): |
305 |
+ overlays = '\n'.join(self.options.__dict__[key]) |
306 |
+ if self.config.has_option('MAIN', 'overlays'): |
307 |
+ overlays += '\n' + self.config.get('MAIN', 'overlays') |
308 |
+ if overlays: |
309 |
+ return overlays |
310 |
+ |
311 |
+ self.output.debug('Retrieving option', 8) |
312 |
+ |
313 |
+ if (key in self.options.__dict__.keys() |
314 |
+ and not self.options.__dict__[key] is None): |
315 |
+ return self.options.__dict__[key] |
316 |
+ |
317 |
+ self.output.debug('Retrieving option', 8) |
318 |
+ |
319 |
+ if self.config.has_option('MAIN', key): |
320 |
+ if key in self._defaults['T/F_options']: |
321 |
+ return self.t_f_check(self.config.get('MAIN', key)) |
322 |
+ return self.config.get('MAIN', key) |
323 |
+ |
324 |
+ self.output.debug('Retrieving option', 8) |
325 |
+ |
326 |
+ if key in self._options.keys(): |
327 |
+ return self._options[key] |
328 |
+ |
329 |
+ if key in self.defaults.keys(): |
330 |
+ return self.defaults[key] |
331 |
+ |
332 |
+ self.output.debug('Retrieving option', 8) |
333 |
+ |
334 |
+ return None |
335 |
+ |
336 |
+ |
337 |
+ def keys(self): |
338 |
+ '''Special handler for the configuration keys.''' |
339 |
+ |
340 |
+ self.output.debug('Retrieving keys', 8) |
341 |
+ |
342 |
+ keys = [i for i in self.options.__dict__.keys() |
343 |
+ if not self.options.__dict__[i] is None] |
344 |
+ |
345 |
+ self.output.debug('Retrieving keys', 8) |
346 |
+ |
347 |
+ keys += [name for name, _ in self.config.items('MAIN') |
348 |
+ if not name in keys] |
349 |
+ |
350 |
+ self.output.debug('Retrieving keys', 8) |
351 |
+ |
352 |
+ keys += [i for i in self.defaults.keys() |
353 |
+ if not i in keys] |
354 |
+ |
355 |
+ self.output.debug('Retrieving keys', 8) |
356 |
+ |
357 |
+ return keys |
358 |
+ |
359 |
+ |
360 |
+#=============================================================================== |
361 |
+# |
362 |
+# Testing |
363 |
+# |
364 |
+#------------------------------------------------------------------------------- |
365 |
+ |
366 |
+if __name__ == '__main__': |
367 |
+ import doctest |
368 |
+ doctest.testmod(sys.modules[__name__]) |
369 |
|
370 |
diff --git a/layman/config.py b/layman/config.py |
371 |
index e8736ed..58e222a 100644 |
372 |
--- a/layman/config.py |
373 |
+++ b/layman/config.py |
374 |
@@ -1,52 +1,38 @@ |
375 |
#!/usr/bin/python |
376 |
# -*- coding: utf-8 -*- |
377 |
-################################################################################# |
378 |
-# LAYMAN CONFIGURATION |
379 |
-################################################################################# |
380 |
-# File: config.py |
381 |
-# |
382 |
-# Handles layman configuration |
383 |
-# |
384 |
-# Copyright: |
385 |
-# (c) 2005 - 2009 Gunnar Wrobel |
386 |
-# (c) 2009 Sebastian Pipping |
387 |
-# (c) 2010 - 2011 Brian Dolbec |
388 |
-# Distributed under the terms of the GNU General Public License v2 |
389 |
-# |
390 |
-# Author(s): |
391 |
-# Gunnar Wrobel <wrobel@g.o> |
392 |
-# Sebastian Pipping <sebastian@×××××××.org> |
393 |
-# Brian Dolbec <brian.dolbec@×××××.com> |
394 |
-# |
395 |
-'''Defines the configuration options and provides parsing functionality.''' |
396 |
- |
397 |
-__version__ = "$Id: config.py 286 2007-01-09 17:48:23Z wrobel $" |
398 |
- |
399 |
-#=============================================================================== |
400 |
-# |
401 |
-# Dependencies |
402 |
-# |
403 |
-#------------------------------------------------------------------------------- |
404 |
- |
405 |
-import sys, ConfigParser |
406 |
-import os |
407 |
|
408 |
-from optparse import OptionParser, OptionGroup |
409 |
+""" |
410 |
+ LAYMAN CONFIGURATION |
411 |
|
412 |
-#from layman.debug import OUT |
413 |
-from layman.output import Message |
414 |
+ File: config.py |
415 |
+ |
416 |
+ Handles Basic layman configuration |
417 |
+ |
418 |
+ Copyright: |
419 |
+ (c) 2005 - 2009 Gunnar Wrobel |
420 |
+ (c) 2009 Sebastian Pipping |
421 |
+ (c) 2010 - 2011 Brian Dolbec |
422 |
+ Distributed under the terms of the GNU General Public License v2 |
423 |
|
424 |
-from layman.constants import OFF |
425 |
-from layman.version import VERSION |
426 |
+ Author(s): |
427 |
+ Gunnar Wrobel <wrobel@g.o> |
428 |
+ Sebastian Pipping <sebastian@×××××××.org> |
429 |
+ Brian Dolbec <brian.dolbec@×××××.com> |
430 |
+""" |
431 |
|
432 |
+'''Defines the configuration options.''' |
433 |
+ |
434 |
+__version__ = "0.2" |
435 |
+ |
436 |
+ |
437 |
+import sys |
438 |
+import os |
439 |
+import ConfigParser |
440 |
|
441 |
-_USAGE = """ |
442 |
- layman (-a|-d|-s|-i) (OVERLAY|ALL) |
443 |
- layman -f [-o URL] |
444 |
- layman (-l|-L|-S)""" |
445 |
+from layman.output import Message |
446 |
|
447 |
|
448 |
-def read_config(config=None, defaults=None): |
449 |
+def read_layman_config(config=None, defaults=None): |
450 |
"""reads the config file defined in defaults['config'] |
451 |
and updates the config |
452 |
|
453 |
@@ -68,11 +54,6 @@ def read_config(config=None, defaults=None): |
454 |
overlays.update(["file://" + path]) |
455 |
config.set('MAIN', 'overlays', '\n'.join(overlays)) |
456 |
|
457 |
-def t_f_check(option): |
458 |
- """evaluates the option and returns |
459 |
- True or False |
460 |
- """ |
461 |
- return option.lower() in ['yes', 'true', 'y', 't'] |
462 |
|
463 |
|
464 |
class BareConfig(object): |
465 |
@@ -130,9 +111,13 @@ class BareConfig(object): |
466 |
} |
467 |
self.config = None |
468 |
if read_configfile: |
469 |
- self.config = ConfigParser.ConfigParser(self._defaults) |
470 |
+ self.read_config(self.get_defaults()) |
471 |
+ |
472 |
+ |
473 |
+ def read_config(self, defaults): |
474 |
+ self.config = ConfigParser.ConfigParser(defaults) |
475 |
self.config.add_section('MAIN') |
476 |
- read_config(self.config, self._defaults) |
477 |
+ read_layman_config(self.config, defaults) |
478 |
|
479 |
|
480 |
def keys(self): |
481 |
@@ -149,12 +134,14 @@ class BareConfig(object): |
482 |
|
483 |
def get_defaults(self): |
484 |
"""returns our defaults dictionary""" |
485 |
- return self._defaults |
486 |
+ _defaults = self._defaults.copy() |
487 |
+ _defaults['config'] = self._options['config'] |
488 |
+ return _defaults |
489 |
|
490 |
|
491 |
def get_option(self, key): |
492 |
"""returns the current option's value""" |
493 |
- return self.__getitem__(key) |
494 |
+ return self._get_(key) |
495 |
|
496 |
|
497 |
def set_option(self, option, value): |
498 |
@@ -164,18 +151,22 @@ class BareConfig(object): |
499 |
if option == 'quiet': |
500 |
if self._options['quiet']: |
501 |
self._set_quietness(1) |
502 |
+ self._options['quietness'] = 0 |
503 |
else: |
504 |
self._set_quietness(4) |
505 |
if option == 'quietness': |
506 |
- self._set_quietness() |
507 |
+ self._set_quietness(value) |
508 |
|
509 |
def _set_quietness(self, value): |
510 |
self._options['output'].set_info_level(int(self['quietness'])) |
511 |
self._options['output'].set_warn_level(int(self['quietness'])) |
512 |
|
513 |
- |
514 |
def __getitem__(self, key): |
515 |
- self._options['output'].debug('Retrieving BareConfig option', 8) |
516 |
+ return self._get_(key) |
517 |
+ |
518 |
+ def _get_(self, key): |
519 |
+ self._options['output'].debug( |
520 |
+ 'Retrieving BareConfig option: %s' % key, 8) |
521 |
if key == 'overlays': |
522 |
overlays = '' |
523 |
if (key in self._options |
524 |
@@ -199,307 +190,10 @@ class BareConfig(object): |
525 |
return self._defaults[key] |
526 |
return None |
527 |
|
528 |
+ @staticmethod |
529 |
+ def t_f_check(option): |
530 |
+ """evaluates the option and returns |
531 |
+ True or False |
532 |
+ """ |
533 |
+ return option.lower() in ['yes', 'true', 'y', 't'] |
534 |
|
535 |
-class ArgsParser(object): |
536 |
- '''Handles the configuration and option parser.''' |
537 |
- |
538 |
- def __init__(self, args=None, output=None, |
539 |
- stdout=None, stdin=None, stderr=None): |
540 |
- ''' |
541 |
- Creates and describes all possible polymeraZe options and creates |
542 |
- a debugging object. |
543 |
- |
544 |
- >>> import os.path |
545 |
- >>> here = os.path.dirname(os.path.realpath(__file__)) |
546 |
- >>> sys.argv.append('--config') |
547 |
- >>> sys.argv.append(here + '/../etc/layman.cfg') |
548 |
- >>> a = ArgsParser() |
549 |
- >>> a['overlays'] |
550 |
- '\\nhttp://www.gentoo.org/proj/en/overlays/repositories.xml' |
551 |
- >>> sorted(a.keys()) |
552 |
- ['bzr_command', 'cache', 'config', 'cvs_command', 'darcs_command', |
553 |
- 'git_command', 'local_list', 'make_conf', 'mercurial_command', |
554 |
- 'nocheck', 'overlays', 'proxy', 'quietness', 'rsync_command', 'storage', |
555 |
- 'svn_command', 'tar_command', 'umask', 'width'] |
556 |
- ''' |
557 |
- if args == None: |
558 |
- args = sys.argv |
559 |
- |
560 |
- self.stdout = stdout if stdout else sys.stdout |
561 |
- self.stderr = stderr if stderr else sys.stderr |
562 |
- self.stdin = stdin if stdin else sys.stdin |
563 |
- self.output = output if output else Message() |
564 |
- |
565 |
- bare_config = BareConfig(self.output, self.stdout, |
566 |
- self.stdin, self.stderr) |
567 |
- self.defaults = bare_config.get_defaults() |
568 |
- #print self.defaults |
569 |
- |
570 |
- self.parser = OptionParser( |
571 |
- usage = _USAGE, |
572 |
- version = VERSION) |
573 |
- |
574 |
- #----------------------------------------------------------------- |
575 |
- # Main Options |
576 |
- |
577 |
- group = OptionGroup(self.parser, |
578 |
- '<Actions>') |
579 |
- |
580 |
- group.add_option('-a', |
581 |
- '--add', |
582 |
- action = 'append', |
583 |
- help = 'Add the given overlay from the cached remote li' |
584 |
- 'st to your locally installed overlays.. Specify "ALL" ' |
585 |
- 'to add all overlays from the remote list.') |
586 |
- |
587 |
- group.add_option('-d', |
588 |
- '--delete', |
589 |
- action = 'append', |
590 |
- help = 'Remove the given overlay from your locally inst' |
591 |
- 'alled overlays. Specify "ALL" to remove all overlays') |
592 |
- |
593 |
- group.add_option('-s', |
594 |
- '--sync', |
595 |
- action = 'append', |
596 |
- help = 'Update the specified overlay. Use "ALL" as para' |
597 |
- 'meter to synchronize all overlays') |
598 |
- |
599 |
- group.add_option('-i', |
600 |
- '--info', |
601 |
- action = 'append', |
602 |
- help = 'Display information about the specified overlay' |
603 |
- '.') |
604 |
- |
605 |
- group.add_option('-S', |
606 |
- '--sync-all', |
607 |
- action = 'store_true', |
608 |
- help = 'Update all overlays.') |
609 |
- |
610 |
- group.add_option('-L', |
611 |
- '--list', |
612 |
- action = 'store_true', |
613 |
- help = 'List the contents of the remote list.') |
614 |
- |
615 |
- group.add_option('-l', |
616 |
- '--list-local', |
617 |
- action = 'store_true', |
618 |
- help = 'List the locally installed overlays.') |
619 |
- |
620 |
- group.add_option('-f', |
621 |
- '--fetch', |
622 |
- action = 'store_true', |
623 |
- help = 'Fetch a remote list of overlays. This option is' |
624 |
- ' deprecated. The fetch operation will be performed by ' |
625 |
- 'default when you run sync, sync-all, or list.') |
626 |
- |
627 |
- group.add_option('-n', |
628 |
- '--nofetch', |
629 |
- action = 'store_true', |
630 |
- help = 'Do not fetch a remote list of overlays.') |
631 |
- |
632 |
- group.add_option('-p', |
633 |
- '--priority', |
634 |
- action = 'store', |
635 |
- help = 'Use this with the --add switch to set the prior' |
636 |
- 'ity of the added overlay. This will influence the sort' |
637 |
- 'ing order of the overlays in the PORTDIR_OVERLAY varia' |
638 |
- 'ble.') |
639 |
- |
640 |
- self.parser.add_option_group(group) |
641 |
- |
642 |
- #----------------------------------------------------------------- |
643 |
- # Additional Options |
644 |
- |
645 |
- group = OptionGroup(self.parser, |
646 |
- '<Path options>') |
647 |
- |
648 |
- group.add_option('-c', |
649 |
- '--config', |
650 |
- action = 'store', |
651 |
- help = 'Path to the config file [default: ' \ |
652 |
- + self.defaults['config'] + '].') |
653 |
- |
654 |
- group.add_option('-o', |
655 |
- '--overlays', |
656 |
- action = 'append', |
657 |
- help = 'The list of overlays [default: ' \ |
658 |
- + self.defaults['overlays'] + '].') |
659 |
- |
660 |
- self.parser.add_option_group(group) |
661 |
- |
662 |
- #----------------------------------------------------------------- |
663 |
- # Output Options |
664 |
- |
665 |
- group = OptionGroup(self.parser, |
666 |
- '<Output options>') |
667 |
- |
668 |
- group.add_option('-v', |
669 |
- '--verbose', |
670 |
- action = 'store_true', |
671 |
- help = 'Increase the amount of output and describe the ' |
672 |
- 'overlays.') |
673 |
- |
674 |
- group.add_option('-q', |
675 |
- '--quiet', |
676 |
- action = 'store_true', |
677 |
- help = 'Yield no output. Please be careful with this op' |
678 |
- 'tion: If the processes spawned by layman when adding o' |
679 |
- 'r synchronizing overlays require any input layman will' |
680 |
- ' hang without telling you why. This might happen for e' |
681 |
- 'xample if your overlay resides in subversion and the S' |
682 |
- 'SL certificate of the server needs acceptance.') |
683 |
- |
684 |
- group.add_option('-N', |
685 |
- '--nocolor', |
686 |
- action = 'store_true', |
687 |
- help = 'Remove color codes from the layman output.') |
688 |
- |
689 |
- group.add_option('-Q', |
690 |
- '--quietness', |
691 |
- action = 'store', |
692 |
- type = 'int', |
693 |
- default = '4', |
694 |
- help = 'Set the level of output (0-4). Default: 4. Once' |
695 |
- ' you set this below 2 the same warning as given for --' |
696 |
- 'quiet applies! ') |
697 |
- |
698 |
- group.add_option('-W', |
699 |
- '--width', |
700 |
- action = 'store', |
701 |
- type = 'int', |
702 |
- default = '0', |
703 |
- help = 'Sets the screen width. This setting is usually ' |
704 |
- 'not required as layman is capable of detecting the ' |
705 |
- 'available number of columns automatically.') |
706 |
- |
707 |
- group.add_option('-k', |
708 |
- '--nocheck', |
709 |
- action = 'store_true', |
710 |
- help = 'Do not check overlay definitions and do not i' |
711 |
- 'ssue a warning if description or contact information' |
712 |
- ' are missing.') |
713 |
- |
714 |
- self.parser.add_option_group(group) |
715 |
- |
716 |
- #----------------------------------------------------------------- |
717 |
- # Debug Options |
718 |
- |
719 |
- #self.output.cli_opts(self.parser) |
720 |
- |
721 |
- # Parse the command line first since we need to get the config |
722 |
- # file option. |
723 |
- if len(args) == 1: |
724 |
- print 'Usage:%s' % _USAGE |
725 |
- sys.exit(0) |
726 |
- |
727 |
- (self.options, remain_args) = self.parser.parse_args(args) |
728 |
- # remain_args starts with something like "bin/layman" ... |
729 |
- if len(remain_args) > 1: |
730 |
- self.parser.error("Unhandled parameters: %s" |
731 |
- % ', '.join(('"%s"' % e) for e in remain_args[1:])) |
732 |
- |
733 |
- # handle debugging |
734 |
- #self.output.cli_handle(self.options) |
735 |
- |
736 |
- # add output to the options |
737 |
- self.options.__dict__['output'] = self.output |
738 |
- |
739 |
- # add the std in/out/err to the options |
740 |
- self.options.__dict__['stdout'] = self.stdout |
741 |
- self.options.__dict__['stdin'] = self.stdin |
742 |
- self.options.__dict__['stderr'] = self.stderr |
743 |
- |
744 |
- |
745 |
- if self.options.__dict__['nocolor']: |
746 |
- self.output.set_colorize(OFF) |
747 |
- |
748 |
- # Fetch only an alternate config setting from the options |
749 |
- if not self.options.__dict__['config'] is None: |
750 |
- self.defaults['config'] = self.options.__dict__['config'] |
751 |
- |
752 |
- #self.output.debug('Got config file at ' + self.defaults['config'], 8) |
753 |
- |
754 |
- # Now parse the config file |
755 |
- self.config = ConfigParser.ConfigParser(self.defaults) |
756 |
- self.config.add_section('MAIN') |
757 |
- |
758 |
- # handle quietness |
759 |
- if self['quiet']: |
760 |
- self.output.set_info_level(1) |
761 |
- self.output.set_warn_level(1) |
762 |
- self.defaults['quietness'] = 0 |
763 |
- elif 'quietness' in self.keys(): |
764 |
- self.output.set_info_level(int(self['quietness'])) |
765 |
- self.output.set_warn_level(int(self['quietness'])) |
766 |
- |
767 |
- #self.output.debug('Reading config file at ' + self.defaults['config'], 8) |
768 |
- |
769 |
- read_config(self.config, self.defaults) |
770 |
- |
771 |
- def __getitem__(self, key): |
772 |
- |
773 |
- if key == 'overlays': |
774 |
- overlays = '' |
775 |
- if (key in self.options.__dict__.keys() |
776 |
- and not self.options.__dict__[key] is None): |
777 |
- overlays = '\n'.join(self.options.__dict__[key]) |
778 |
- if self.config.has_option('MAIN', 'overlays'): |
779 |
- overlays += '\n' + self.config.get('MAIN', 'overlays') |
780 |
- if overlays: |
781 |
- return overlays |
782 |
- |
783 |
- self.output.debug('Retrieving option', 8) |
784 |
- |
785 |
- if (key in self.options.__dict__.keys() |
786 |
- and not self.options.__dict__[key] is None): |
787 |
- return self.options.__dict__[key] |
788 |
- |
789 |
- self.output.debug('Retrieving option', 8) |
790 |
- |
791 |
- if self.config.has_option('MAIN', key): |
792 |
- if key in self.defaults['T/F_options']: |
793 |
- return t_f_check(self.config.get('MAIN', key)) |
794 |
- return self.config.get('MAIN', key) |
795 |
- |
796 |
- self.output.debug('Retrieving option', 8) |
797 |
- |
798 |
- if key in self.defaults.keys(): |
799 |
- return self.defaults[key] |
800 |
- |
801 |
- self.output.debug('Retrieving option', 8) |
802 |
- |
803 |
- return None |
804 |
- |
805 |
- |
806 |
- def keys(self): |
807 |
- '''Special handler for the configuration keys.''' |
808 |
- |
809 |
- self.output.debug('Retrieving keys', 8) |
810 |
- |
811 |
- keys = [i for i in self.options.__dict__.keys() |
812 |
- if not self.options.__dict__[i] is None] |
813 |
- |
814 |
- self.output.debug('Retrieving keys', 8) |
815 |
- |
816 |
- keys += [name for name, _ in self.config.items('MAIN') |
817 |
- if not name in keys] |
818 |
- |
819 |
- self.output.debug('Retrieving keys', 8) |
820 |
- |
821 |
- keys += [i for i in self.defaults.keys() |
822 |
- if not i in keys] |
823 |
- |
824 |
- self.output.debug('Retrieving keys', 8) |
825 |
- |
826 |
- return keys |
827 |
- |
828 |
- |
829 |
-#=============================================================================== |
830 |
-# |
831 |
-# Testing |
832 |
-# |
833 |
-#------------------------------------------------------------------------------- |
834 |
- |
835 |
-if __name__ == '__main__': |
836 |
- import doctest |
837 |
- doctest.testmod(sys.modules[__name__]) |