| OLD | NEW |
| 1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. | 1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
| 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr | 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
| 3 # | 3 # |
| 4 # This file is part of logilab-common. | 4 # This file is part of logilab-common. |
| 5 # | 5 # |
| 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r | 6 # logilab-common is free software: you can redistribute it and/or modify it unde
r |
| 7 # the terms of the GNU Lesser General Public License as published by the Free | 7 # the terms of the GNU Lesser General Public License as published by the Free |
| 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y | 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
| 9 # later version. | 9 # later version. |
| 10 # | 10 # |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 else: | 402 else: |
| 403 value = _encode(value, encoding).strip() | 403 value = _encode(value, encoding).strip() |
| 404 print('%s=%s' % (optname, value), file=stream) | 404 print('%s=%s' % (optname, value), file=stream) |
| 405 | 405 |
| 406 format_section = ini_format_section | 406 format_section = ini_format_section |
| 407 | 407 |
| 408 def rest_format_section(stream, section, options, encoding=None, doc=None): | 408 def rest_format_section(stream, section, options, encoding=None, doc=None): |
| 409 """format an options section using as ReST formatted output""" | 409 """format an options section using as ReST formatted output""" |
| 410 encoding = _get_encoding(encoding, stream) | 410 encoding = _get_encoding(encoding, stream) |
| 411 if section: | 411 if section: |
| 412 print >> stream, '%s\n%s' % (section, "'"*len(section)) | 412 print('%s\n%s' % (section, "'"*len(section)), file=stream) |
| 413 if doc: | 413 if doc: |
| 414 print >> stream, _encode(normalize_text(doc, line_len=79, indent=''), | 414 print(_encode(normalize_text(doc, line_len=79, indent=''), encoding), fi
le=stream) |
| 415 encoding) | 415 print(file=stream) |
| 416 print >> stream | |
| 417 for optname, optdict, value in options: | 416 for optname, optdict, value in options: |
| 418 help = optdict.get('help') | 417 help = optdict.get('help') |
| 419 print >> stream, ':%s:' % optname | 418 print(':%s:' % optname, file=stream) |
| 420 if help: | 419 if help: |
| 421 help = normalize_text(help, line_len=79, indent=' ') | 420 help = normalize_text(help, line_len=79, indent=' ') |
| 422 print >> stream, _encode(help, encoding) | 421 print(_encode(help, encoding), file=stream) |
| 423 if value: | 422 if value: |
| 424 value = _encode(format_option_value(optdict, value), encoding) | 423 value = _encode(format_option_value(optdict, value), encoding) |
| 425 print >> stream, '' | 424 print(file=stream) |
| 426 print >> stream, ' Default: ``%s``' % value.replace("`` ", "```` ``
") | 425 print(' Default: ``%s``' % value.replace("`` ", "```` ``"), file=st
ream) |
| 427 | 426 |
| 428 # Options Manager ############################################################## | 427 # Options Manager ############################################################## |
| 429 | 428 |
| 430 class OptionsManagerMixIn(object): | 429 class OptionsManagerMixIn(object): |
| 431 """MixIn to handle a configuration from both a configuration file and | 430 """MixIn to handle a configuration from both a configuration file and |
| 432 command line options | 431 command line options |
| 433 """ | 432 """ |
| 434 | 433 |
| 435 def __init__(self, usage, config_file=None, version=None, quiet=0): | 434 def __init__(self, usage, config_file=None, version=None, quiet=0): |
| 436 self.config_file = config_file | 435 self.config_file = config_file |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 if optname in alloptions: | 1096 if optname in alloptions: |
| 1098 options.pop(i) | 1097 options.pop(i) |
| 1099 alloptions[optname].update(optdict) | 1098 alloptions[optname].update(optdict) |
| 1100 else: | 1099 else: |
| 1101 optdict = optdict.copy() | 1100 optdict = optdict.copy() |
| 1102 options[i] = (optname, optdict) | 1101 options[i] = (optname, optdict) |
| 1103 alloptions[optname] = optdict | 1102 alloptions[optname] = optdict |
| 1104 if optgroup is not None: | 1103 if optgroup is not None: |
| 1105 alloptions[optname]['group'] = optgroup | 1104 alloptions[optname]['group'] = optgroup |
| 1106 return tuple(options) | 1105 return tuple(options) |
| OLD | NEW |