From 3f909add8d4943b2334a2943d8c7817fed3692cc Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 30 May 2002 02:12:05 +0000 Subject: Support for front-end scripts. Option specifications may be augmented by components. Requires Optik (http://optik.sf.net/) for option processing. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@150 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 docutils/frontend.py (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py new file mode 100644 index 000000000..727db95d0 --- /dev/null +++ b/docutils/frontend.py @@ -0,0 +1,122 @@ +#! /usr/bin/env python + +""" +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +Command-line and common processing for Docutils front-ends. +""" + +__docformat__ = 'reStructuredText' + +import optik + + +class OptionParser(optik.OptionParser): + + """ + Parser for command-line and library use. The `cmdline_options` specification here and in other Docutils components are merged + """ + + standard_option_list = [] + """We supply our own help option.""" + + cmdline_options = ( + # Unimplemented or unused options are commented out. + #('Include a "Generated by Docutils" credit with a link, at the end ' + # 'of the document.', + # ['--generator', '-g'], {'action': 'store_true', 'default': 0}), + #('Include the date at the end of the document (UTC).', + # ['--date', '-d'], {'action': 'store_const', 'const': '%Y-%m-%d', + # 'dest': 'datestamp', 'default': ''}), + #('Include the time & date at the end of the document (UTC).', + # ['--time', '-t'], {'action': 'store_const', + # 'const': '%Y-%m-%d %H:%M:%S UTC', + # 'dest': 'datestamp', 'default': ''}), + #('Include a "(View document source)" link.', + # ['--source-link', '-s'], {'action': 'store_true', 'default': 0}), + ('Set verbosity threshold; report system messages at or higher than ' + ' (by name or number: "info" or "1", warning/2, error/3, ' + 'severe/4; also, "none" or 5+). Default is 2 (warning).', + ['--report', '-r'], {'dest': 'report_level', 'default': 2, + 'metavar': ''}), + ('Report all system messages, info-level and higher. (Same as ' + '"--report=info".)', + ['--verbose', '-v'], {'action': 'store_const', 'const': 'info', + 'dest': 'report_level'}), + ('Set the threshold () at or above which system messages are ' + 'converted to exceptions, halting execution immediately. Levels as ' + 'in --report. Default is 4 (severe).', + ['--halt'], {'dest': 'halt_level', 'default': 4, + 'metavar': ''}), + ('Same as "--halt=info": halt processing at the slightest problem.', + ['--strict'], {'action': 'store_const', 'const': 'info', + 'dest': 'halt_level'}), + ('Report debug-level system messages.', + ['--debug'], {'action': 'store_true', 'default': 0}), + ('Send the output of system messages (warnings) to .', + ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), + # @@@ Take default encoding & language from locale? + #('Specify the encoding of input text. Default is "utf-8".', + # ['--encoding', '-e'], {'default': 'utf-8', 'metavar': ''}), + ('Specify the language of input text (ISO 639 2-letter identifier. ' + 'Default is "en" (English).', + ['--language', '-l'], {'dest': 'language_code', 'default': 'en', + 'metavar': ''}), + ('Show this help message and exit.', + ['--help', '-h'], {'action': 'help'}),) + """Command-line option specifications, common to all Docutils front-ends. + A list/tuple of tuples: ``('help text', [list of option strings], {keyword + arguments})``. Option specs from Docutils components are also used (see + `build_option_parser()`).""" + + thresholds = {'info': 1, 'warning': 2, 'error': 3, 'severe': 4, 'none': 5} + """Lookup table for --report and --halt threshold values.""" + + def __init__(self, components=(), defaults={}, *args, **kwargs): + """ + `components` is a list of Docutils components each containing a + ``.cmdline_options`` attribute. `defaults` is a + """ + optik.OptionParser.__init__(self, *args, **kwargs) + self.populate_from_components((self,) + tuple(components)) + self.set_defaults(**defaults) + + def populate_from_components(self, components): + for component in components: + if component is not None: + for (help_text, option_strings, kwargs) \ + in component.cmdline_options: + self.add_option(help=help_text, *option_strings, + **kwargs) + + def check_values(self, values, args): + values.report_level = self.check_threshold(values.report_level) + values.halt_level = self.check_threshold(values.halt_level) + source, destination = self.check_args(args) + return values, source, destination + + def check_threshold(self, level): + try: + return int(level) + except ValueError: + try: + return self.thresholds[level.lower()] + except (KeyError, AttributeError): + self.error('Unknown threshold: %r.' % level) + + def check_args(self, args): + source = destination = None + if args: + source = args.pop(0) + if args: + destination = args.pop(0) + if args: + self.error('Maximum 2 arguments allowed.') + return source, destination + + def get_default_values(self): + return optik.option_parser.Values(self.defaults) -- cgit v1.2.1 From 83de8a45d6e3ca1567ee955f9d557c8f0c75e2c2 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 1 Jun 2002 01:41:33 +0000 Subject: Enabled a bunch of command-line options relating to the document footer. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@170 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 727db95d0..6f158e862 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -26,18 +26,26 @@ class OptionParser(optik.OptionParser): cmdline_options = ( # Unimplemented or unused options are commented out. - #('Include a "Generated by Docutils" credit with a link, at the end ' - # 'of the document.', - # ['--generator', '-g'], {'action': 'store_true', 'default': 0}), - #('Include the date at the end of the document (UTC).', - # ['--date', '-d'], {'action': 'store_const', 'const': '%Y-%m-%d', - # 'dest': 'datestamp', 'default': ''}), - #('Include the time & date at the end of the document (UTC).', - # ['--time', '-t'], {'action': 'store_const', - # 'const': '%Y-%m-%d %H:%M:%S UTC', - # 'dest': 'datestamp', 'default': ''}), - #('Include a "(View document source)" link.', - # ['--source-link', '-s'], {'action': 'store_true', 'default': 0}), + ('Include a "Generated by Docutils" credit with a link, at the end ' + 'of the document.', + ['--generator', '-g'], {'action': 'store_true'}), + ('Do not include a generator credit.', + ['--no-generator'], {'action': 'store_false', 'dest': 'generator'}), + ('Include the date at the end of the document (UTC).', + ['--date', '-d'], {'action': 'store_const', 'const': '%Y-%m-%d', + 'dest': 'datestamp'}), + ('Include the time & date at the end of the document (UTC).', + ['--time', '-t'], {'action': 'store_const', + 'const': '%Y-%m-%d %H:%M UTC', + 'dest': 'datestamp'}), + ('Do not include a datestamp of any kind.', + ['--no-datestamp'], {'action': 'store_const', 'const': None, + 'dest': 'datestamp'}), + ('Include a "View document source." link.', + ['--source-link', '-s'], {'action': 'store_true'}), + ('Do not include a "(View document source)" link.', + ['--no-source-link'], {'action': 'store_false', + 'dest': 'source_link'}), ('Set verbosity threshold; report system messages at or higher than ' ' (by name or number: "info" or "1", warning/2, error/3, ' 'severe/4; also, "none" or 5+). Default is 2 (warning).', @@ -56,7 +64,9 @@ class OptionParser(optik.OptionParser): ['--strict'], {'action': 'store_const', 'const': 'info', 'dest': 'halt_level'}), ('Report debug-level system messages.', - ['--debug'], {'action': 'store_true', 'default': 0}), + ['--debug'], {'action': 'store_true'}), + ('Do not report debug-level system messages.', + ['--no-debug'], {'action': 'store_false', 'dest': 'debug'}), ('Send the output of system messages (warnings) to .', ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), # @@@ Take default encoding & language from locale? -- cgit v1.2.1 From 361fcaa4671d334ee92294de947ad99546469bd5 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 13 Jun 2002 03:25:41 +0000 Subject: Updated for new Optik option group functionality. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@180 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 146 +++++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 70 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 6f158e862..01b0ed489 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -12,7 +12,8 @@ Command-line and common processing for Docutils front-ends. __docformat__ = 'reStructuredText' -import optik +import docutils +from docutils import optik class OptionParser(optik.OptionParser): @@ -21,87 +22,95 @@ class OptionParser(optik.OptionParser): Parser for command-line and library use. The `cmdline_options` specification here and in other Docutils components are merged """ - standard_option_list = [] - """We supply our own help option.""" - cmdline_options = ( - # Unimplemented or unused options are commented out. - ('Include a "Generated by Docutils" credit with a link, at the end ' - 'of the document.', - ['--generator', '-g'], {'action': 'store_true'}), - ('Do not include a generator credit.', - ['--no-generator'], {'action': 'store_false', 'dest': 'generator'}), - ('Include the date at the end of the document (UTC).', - ['--date', '-d'], {'action': 'store_const', 'const': '%Y-%m-%d', - 'dest': 'datestamp'}), - ('Include the time & date at the end of the document (UTC).', - ['--time', '-t'], {'action': 'store_const', - 'const': '%Y-%m-%d %H:%M UTC', - 'dest': 'datestamp'}), - ('Do not include a datestamp of any kind.', - ['--no-datestamp'], {'action': 'store_const', 'const': None, - 'dest': 'datestamp'}), - ('Include a "View document source." link.', - ['--source-link', '-s'], {'action': 'store_true'}), - ('Do not include a "(View document source)" link.', - ['--no-source-link'], {'action': 'store_false', - 'dest': 'source_link'}), - ('Set verbosity threshold; report system messages at or higher than ' - ' (by name or number: "info" or "1", warning/2, error/3, ' - 'severe/4; also, "none" or 5+). Default is 2 (warning).', - ['--report', '-r'], {'dest': 'report_level', 'default': 2, - 'metavar': ''}), - ('Report all system messages, info-level and higher. (Same as ' - '"--report=info".)', - ['--verbose', '-v'], {'action': 'store_const', 'const': 'info', - 'dest': 'report_level'}), - ('Set the threshold () at or above which system messages are ' - 'converted to exceptions, halting execution immediately. Levels as ' - 'in --report. Default is 4 (severe).', - ['--halt'], {'dest': 'halt_level', 'default': 4, - 'metavar': ''}), - ('Same as "--halt=info": halt processing at the slightest problem.', - ['--strict'], {'action': 'store_const', 'const': 'info', - 'dest': 'halt_level'}), - ('Report debug-level system messages.', - ['--debug'], {'action': 'store_true'}), - ('Do not report debug-level system messages.', - ['--no-debug'], {'action': 'store_false', 'dest': 'debug'}), - ('Send the output of system messages (warnings) to .', - ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), - # @@@ Take default encoding & language from locale? - #('Specify the encoding of input text. Default is "utf-8".', - # ['--encoding', '-e'], {'default': 'utf-8', 'metavar': ''}), - ('Specify the language of input text (ISO 639 2-letter identifier. ' - 'Default is "en" (English).', - ['--language', '-l'], {'dest': 'language_code', 'default': 'en', - 'metavar': ''}), - ('Show this help message and exit.', - ['--help', '-h'], {'action': 'help'}),) + 'General Options', + None, + (('Include a "Generated by Docutils" credit with a link, at the end ' + 'of the document.', + ['--generator', '-g'], {'action': 'store_true'}), + ('Do not include a generator credit.', + ['--no-generator'], {'action': 'store_false', 'dest': 'generator'}), + ('Include the date at the end of the document (UTC).', + ['--date', '-d'], {'action': 'store_const', 'const': '%Y-%m-%d', + 'dest': 'datestamp'}), + ('Include the time & date at the end of the document (UTC).', + ['--time', '-t'], {'action': 'store_const', + 'const': '%Y-%m-%d %H:%M UTC', + 'dest': 'datestamp'}), + ('Do not include a datestamp of any kind.', + ['--no-datestamp'], {'action': 'store_const', 'const': None, + 'dest': 'datestamp'}), + ('Include a "View document source." link.', + ['--source-link', '-s'], {'action': 'store_true'}), + ('Do not include a "(View document source)" link.', + ['--no-source-link'], {'action': 'store_false', + 'dest': 'source_link'}), + ('Set verbosity threshold; report system messages at or higher than ' + ' (by name or number: "info" or "1", warning/2, error/3, ' + 'severe/4; also, "none" or 5+). Default is 2 (warning).', + ['--report', '-r'], {'dest': 'report_level', 'default': 2, + 'metavar': ''}), + ('Report all system messages, info-level and higher. (Same as ' + '"--report=info".)', + ['--verbose', '-v'], {'action': 'store_const', 'const': 'info', + 'dest': 'report_level'}), + ('Set the threshold () at or above which system messages are ' + 'converted to exceptions, halting execution immediately. Levels ' + 'as in --report. Default is 4 (severe).', + ['--halt'], {'dest': 'halt_level', 'default': 4, + 'metavar': ''}), + ('Same as "--halt=info": halt processing at the slightest problem.', + ['--strict'], {'action': 'store_const', 'const': 'info', + 'dest': 'halt_level'}), + ('Report debug-level system messages.', + ['--debug'], {'action': 'store_true'}), + ('Do not report debug-level system messages.', + ['--no-debug'], {'action': 'store_false', 'dest': 'debug'}), + ('Send the output of system messages (warnings) to .', + ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), + # @@@ Take default encoding & language from locale? + #('Specify the encoding of input text. Default is "utf-8".', + # ['--encoding', '-e'], {'default': 'utf-8', 'metavar': ''}), + ('Specify the language of input text (ISO 639 2-letter identifier. ' + 'Default is "en" (English).', + ['--language', '-l'], {'dest': 'language_code', 'default': 'en', + 'metavar': ''}), + ("Show this program's version number and exit.", + ['--version'], {'action': 'version'}), + ('Show this help message and exit.', + ['--help', '-h'], {'action': 'help'}),)) """Command-line option specifications, common to all Docutils front-ends. - A list/tuple of tuples: ``('help text', [list of option strings], {keyword - arguments})``. Option specs from Docutils components are also used (see - `build_option_parser()`).""" + Option group title, description, and a list/tuple of tuples: ``('help + text', [list of option strings], {keyword arguments})``. Option specs + from Docutils components are also used (see + `populate_from_components()`).""" thresholds = {'info': 1, 'warning': 2, 'error': 3, 'severe': 4, 'none': 5} """Lookup table for --report and --halt threshold values.""" + version_template = '%%prog (Docutils %s)' % docutils.__version__ + def __init__(self, components=(), defaults={}, *args, **kwargs): """ `components` is a list of Docutils components each containing a ``.cmdline_options`` attribute. `defaults` is a """ - optik.OptionParser.__init__(self, *args, **kwargs) - self.populate_from_components((self,) + tuple(components)) + optik.OptionParser.__init__(self, help=None, format=optik.Titled(), + *args, **kwargs) + if not self.version: + self.version = self.version_template + self.populate_from_components(tuple(components) + (self,)) self.set_defaults(**defaults) def populate_from_components(self, components): for component in components: - if component is not None: - for (help_text, option_strings, kwargs) \ - in component.cmdline_options: - self.add_option(help=help_text, *option_strings, - **kwargs) + if component is not None and component.cmdline_options: + title, description, option_spec = component.cmdline_options + group = optik.OptionGroup(self, title, description) + self.add_option_group(group) + for (help_text, option_strings, kwargs) in option_spec: + group.add_option(help=help_text, *option_strings, + **kwargs) def check_values(self, values, args): values.report_level = self.check_threshold(values.report_level) @@ -127,6 +136,3 @@ class OptionParser(optik.OptionParser): if args: self.error('Maximum 2 arguments allowed.') return source, destination - - def get_default_values(self): - return optik.option_parser.Values(self.defaults) -- cgit v1.2.1 From c68e44ec4f2b29042e1ea2ae425ed982c00162c6 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 13 Jun 2002 22:32:07 +0000 Subject: minor git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@187 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 01b0ed489..275137a9c 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -23,7 +23,7 @@ class OptionParser(optik.OptionParser): """ cmdline_options = ( - 'General Options', + 'General Docutils Options', None, (('Include a "Generated by Docutils" credit with a link, at the end ' 'of the document.', @@ -93,7 +93,8 @@ class OptionParser(optik.OptionParser): def __init__(self, components=(), defaults={}, *args, **kwargs): """ `components` is a list of Docutils components each containing a - ``.cmdline_options`` attribute. `defaults` is a + ``.cmdline_options`` attribute. `defaults` is a mapping of option + default overrides. """ optik.OptionParser.__init__(self, help=None, format=optik.Titled(), *args, **kwargs) -- cgit v1.2.1 From f7261b75de49dbcd0da320ac34cd549425e9dac2 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 27 Jun 2002 01:17:24 +0000 Subject: - Enabled "--encoding" option (but not implemented yet). - Added "--dump-internal-document-attributes". - Support for non-grouped options. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@205 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 275137a9c..c833940b4 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -68,9 +68,8 @@ class OptionParser(optik.OptionParser): ['--no-debug'], {'action': 'store_false', 'dest': 'debug'}), ('Send the output of system messages (warnings) to .', ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), - # @@@ Take default encoding & language from locale? - #('Specify the encoding of input text. Default is "utf-8".', - # ['--encoding', '-e'], {'default': 'utf-8', 'metavar': ''}), + ('Specify the encoding of input text. Default is locale-dependent.', + ['--encoding', '-e'], {'metavar': ''}), ('Specify the language of input text (ISO 639 2-letter identifier. ' 'Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', @@ -78,12 +77,17 @@ class OptionParser(optik.OptionParser): ("Show this program's version number and exit.", ['--version'], {'action': 'version'}), ('Show this help message and exit.', - ['--help', '-h'], {'action': 'help'}),)) + ['--help', '-h'], {'action': 'help'}), + # Hidden options, for development use only: + (optik.SUPPRESS_HELP, ['--dump-internal-document-attributes'], + {'action': 'store_true'}),)) + """Command-line option specifications, common to all Docutils front-ends. Option group title, description, and a list/tuple of tuples: ``('help - text', [list of option strings], {keyword arguments})``. Option specs - from Docutils components are also used (see - `populate_from_components()`).""" + text', [list of option strings], {keyword arguments})``. Group title + and/or description may be `None`; no group title implies no group, just a + list of single options. Option specs from Docutils components are also + used (see `populate_from_components()`).""" thresholds = {'info': 1, 'warning': 2, 'error': 3, 'severe': 4, 'none': 5} """Lookup table for --report and --halt threshold values.""" @@ -107,8 +111,11 @@ class OptionParser(optik.OptionParser): for component in components: if component is not None and component.cmdline_options: title, description, option_spec = component.cmdline_options - group = optik.OptionGroup(self, title, description) - self.add_option_group(group) + if title: + group = optik.OptionGroup(self, title, description) + self.add_option_group(group) + else: + group = self # single options for (help_text, option_strings, kwargs) in option_spec: group.add_option(help=help_text, *option_strings, **kwargs) -- cgit v1.2.1 From 01e6d2ca28acbc89879acefd8e0baa3e6ca8c457 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 28 Jun 2002 04:13:57 +0000 Subject: - Added support for the ``docutils.io.IO`` class & subclasses. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@218 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index c833940b4..cb0a11681 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -69,9 +69,12 @@ class OptionParser(optik.OptionParser): ('Send the output of system messages (warnings) to .', ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), ('Specify the encoding of input text. Default is locale-dependent.', - ['--encoding', '-e'], {'metavar': ''}), - ('Specify the language of input text (ISO 639 2-letter identifier. ' - 'Default is "en" (English).', + ['--input-encoding', '-i'], {'metavar': ''}), + ('Specify the encoding for output. Default is UTF-8.', + ['--output-encoding', '-o'], + {'metavar': '', 'default': 'utf-8'}), + ('Specify the language of input text (ISO 639 2-letter identifier).' + ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', 'metavar': ''}), ("Show this program's version number and exit.", -- cgit v1.2.1 From 9a98f9a98ee1aec3a1e67a6e84bc5286814501f8 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 6 Jul 2002 03:01:17 +0000 Subject: Changed "--report" and "--halt" options to "choice" type. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@256 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index cb0a11681..0e1158024 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -22,6 +22,12 @@ class OptionParser(optik.OptionParser): Parser for command-line and library use. The `cmdline_options` specification here and in other Docutils components are merged """ + threshold_choices = 'info 1 warning 2 error 3 severe 4 none 5'.split() + """Possible inputs for for --report and --halt threshold values.""" + + thresholds = {'info': 1, 'warning': 2, 'error': 3, 'severe': 4, 'none': 5} + """Lookup table for --report and --halt threshold values.""" + cmdline_options = ( 'General Docutils Options', None, @@ -47,9 +53,9 @@ class OptionParser(optik.OptionParser): 'dest': 'source_link'}), ('Set verbosity threshold; report system messages at or higher than ' ' (by name or number: "info" or "1", warning/2, error/3, ' - 'severe/4; also, "none" or 5+). Default is 2 (warning).', - ['--report', '-r'], {'dest': 'report_level', 'default': 2, - 'metavar': ''}), + 'severe/4; also, "none" or "5"). Default is 2 (warning).', + ['--report', '-r'], {'choices': threshold_choices, 'default': 2, + 'dest': 'report_level', 'metavar': ''}), ('Report all system messages, info-level and higher. (Same as ' '"--report=info".)', ['--verbose', '-v'], {'action': 'store_const', 'const': 'info', @@ -57,8 +63,8 @@ class OptionParser(optik.OptionParser): ('Set the threshold () at or above which system messages are ' 'converted to exceptions, halting execution immediately. Levels ' 'as in --report. Default is 4 (severe).', - ['--halt'], {'dest': 'halt_level', 'default': 4, - 'metavar': ''}), + ['--halt'], {'choices': threshold_choices, 'dest': 'halt_level', + 'default': 4, 'metavar': ''}), ('Same as "--halt=info": halt processing at the slightest problem.', ['--strict'], {'action': 'store_const', 'const': 'info', 'dest': 'halt_level'}), @@ -92,9 +98,6 @@ class OptionParser(optik.OptionParser): list of single options. Option specs from Docutils components are also used (see `populate_from_components()`).""" - thresholds = {'info': 1, 'warning': 2, 'error': 3, 'severe': 4, 'none': 5} - """Lookup table for --report and --halt threshold values.""" - version_template = '%%prog (Docutils %s)' % docutils.__version__ def __init__(self, components=(), defaults={}, *args, **kwargs): -- cgit v1.2.1 From d55f974593d719d4a2be200f6cf2ac73bb44334a Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 18 Jul 2002 00:50:18 +0000 Subject: ws git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@298 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 1 - 1 file changed, 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 0e1158024..d7dbf914f 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -90,7 +90,6 @@ class OptionParser(optik.OptionParser): # Hidden options, for development use only: (optik.SUPPRESS_HELP, ['--dump-internal-document-attributes'], {'action': 'store_true'}),)) - """Command-line option specifications, common to all Docutils front-ends. Option group title, description, and a list/tuple of tuples: ``('help text', [list of option strings], {keyword arguments})``. Group title -- cgit v1.2.1 From 43f13c2ca5dfb0f9862044b1bcb84c1ca864fcc9 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 19 Jul 2002 02:25:33 +0000 Subject: Simplified ``OptionParser.__init__()``. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@320 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index d7dbf914f..d056dbce5 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -88,7 +88,8 @@ class OptionParser(optik.OptionParser): ('Show this help message and exit.', ['--help', '-h'], {'action': 'help'}), # Hidden options, for development use only: - (optik.SUPPRESS_HELP, ['--dump-internal-document-attributes'], + (optik.SUPPRESS_HELP, + ['--dump-internal-document-attributes'], {'action': 'store_true'}),)) """Command-line option specifications, common to all Docutils front-ends. Option group title, description, and a list/tuple of tuples: ``('help @@ -99,7 +100,7 @@ class OptionParser(optik.OptionParser): version_template = '%%prog (Docutils %s)' % docutils.__version__ - def __init__(self, components=(), defaults={}, *args, **kwargs): + def __init__(self, components=(), *args, **kwargs): """ `components` is a list of Docutils components each containing a ``.cmdline_options`` attribute. `defaults` is a mapping of option @@ -110,7 +111,6 @@ class OptionParser(optik.OptionParser): if not self.version: self.version = self.version_template self.populate_from_components(tuple(components) + (self,)) - self.set_defaults(**defaults) def populate_from_components(self, components): for component in components: -- cgit v1.2.1 From d6cdc2f926410ac99acdcfe9415b486b0baed8b5 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 20 Jul 2002 03:18:30 +0000 Subject: Support for ConfigParser. Support for multiple option groups per ``cmdline_options``. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@336 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index d056dbce5..f0a4f8974 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -12,6 +12,7 @@ Command-line and common processing for Docutils front-ends. __docformat__ = 'reStructuredText' +import ConfigParser as CP import docutils from docutils import optik @@ -92,11 +93,12 @@ class OptionParser(optik.OptionParser): ['--dump-internal-document-attributes'], {'action': 'store_true'}),)) """Command-line option specifications, common to all Docutils front-ends. - Option group title, description, and a list/tuple of tuples: ``('help - text', [list of option strings], {keyword arguments})``. Group title - and/or description may be `None`; no group title implies no group, just a - list of single options. Option specs from Docutils components are also - used (see `populate_from_components()`).""" + One or more sets of option group title, description, and a + list/tuple of tuples: ``('help text', [list of option strings], + {keyword arguments})``. Group title and/or description may be + `None`; no group title implies no group, just a list of single + options. Option specs from Docutils components are also used (see + `populate_from_components()`).""" version_template = '%%prog (Docutils %s)' % docutils.__version__ @@ -114,16 +116,20 @@ class OptionParser(optik.OptionParser): def populate_from_components(self, components): for component in components: - if component is not None and component.cmdline_options: - title, description, option_spec = component.cmdline_options - if title: - group = optik.OptionGroup(self, title, description) - self.add_option_group(group) - else: - group = self # single options - for (help_text, option_strings, kwargs) in option_spec: - group.add_option(help=help_text, *option_strings, - **kwargs) + if component is not None: + i = 0 + cmdline_options = component.cmdline_options + while i < len(cmdline_options): + title, description, option_spec = cmdline_options[i:i+3] + if title: + group = optik.OptionGroup(self, title, description) + self.add_option_group(group) + else: + group = self # single options + for (help_text, option_strings, kwargs) in option_spec: + group.add_option(help=help_text, *option_strings, + **kwargs) + i += 3 def check_values(self, values, args): values.report_level = self.check_threshold(values.report_level) @@ -149,3 +155,12 @@ class OptionParser(optik.OptionParser): if args: self.error('Maximum 2 arguments allowed.') return source, destination + + +class ConfigParser(CP.ConfigParser): + + def optionxform(self, optionstr): + """ + Transform '-' to '_' so the cmdline form of option names can be used. + """ + return optionstr.lower().replace('-', '_') -- cgit v1.2.1 From e2befb2363ac2b741e4ef450d7cd20ba2e2f38e4 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 24 Jul 2002 01:35:21 +0000 Subject: Added options to control backlinks from footnotes/citations and section headers (back to TOC). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@353 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index f0a4f8974..d6025e4a4 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -52,6 +52,25 @@ class OptionParser(optik.OptionParser): ('Do not include a "(View document source)" link.', ['--no-source-link'], {'action': 'store_false', 'dest': 'source_link'}), + ('Enable backlinks from section headers to table of contents ' + 'entries. This is the default.', + ['--toc-entry-backlinks'], + {'dest': 'toc_backlinks', 'action': 'store_const', 'const': 'entry', + 'default': 'entry'}), + ('Enable backlinks from section headers to the top of the table of ' + 'contents.', + ['--toc-top-backlinks'], + {'dest': 'toc_backlinks', 'action': 'store_const', 'const': 'top'}), + ('Disable backlinks to the table of contents.', + ['--no-toc-backlinks'], + {'dest': 'toc_backlinks', 'action': 'store_false'}), + ('Enable backlinks from footnotes and citations to their ' + 'references. This is the default.', + ['--footnote-backlinks'], + {'action': 'store_true', 'default': 1}), + ('Disable backlinks from footnotes and citations.', + ['--no-footnote-backlinks'], + {'dest': 'footnote_backlinks', 'action': 'store_false'}), ('Set verbosity threshold; report system messages at or higher than ' ' (by name or number: "info" or "1", warning/2, error/3, ' 'severe/4; also, "none" or "5"). Default is 2 (warning).', -- cgit v1.2.1 From 8773019e39e7199f06b0bd263b778a74ffb86a61 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 25 Jul 2002 01:47:58 +0000 Subject: docstrings & option descriptions git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@367 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index d6025e4a4..759e11472 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -7,7 +7,7 @@ :Date: $Date$ :Copyright: This module has been placed in the public domain. -Command-line and common processing for Docutils front-ends. +Command-line and common processing for Docutils front-end tools. """ __docformat__ = 'reStructuredText' @@ -32,7 +32,7 @@ class OptionParser(optik.OptionParser): cmdline_options = ( 'General Docutils Options', None, - (('Include a "Generated by Docutils" credit with a link, at the end ' + (('Include a "Generated by Docutils" credit and link at the end ' 'of the document.', ['--generator', '-g'], {'action': 'store_true'}), ('Do not include a generator credit.', @@ -47,9 +47,9 @@ class OptionParser(optik.OptionParser): ('Do not include a datestamp of any kind.', ['--no-datestamp'], {'action': 'store_const', 'const': None, 'dest': 'datestamp'}), - ('Include a "View document source." link.', + ('Include a "View document source" link.', ['--source-link', '-s'], {'action': 'store_true'}), - ('Do not include a "(View document source)" link.', + ('Do not include a "View document source" link.', ['--no-source-link'], {'action': 'store_false', 'dest': 'source_link'}), ('Enable backlinks from section headers to table of contents ' @@ -109,15 +109,14 @@ class OptionParser(optik.OptionParser): ['--help', '-h'], {'action': 'help'}), # Hidden options, for development use only: (optik.SUPPRESS_HELP, - ['--dump-internal-document-attributes'], + ['--dump-internals'], {'action': 'store_true'}),)) - """Command-line option specifications, common to all Docutils front-ends. - One or more sets of option group title, description, and a - list/tuple of tuples: ``('help text', [list of option strings], - {keyword arguments})``. Group title and/or description may be - `None`; no group title implies no group, just a list of single - options. Option specs from Docutils components are also used (see - `populate_from_components()`).""" + """Command-line option specifications, common to all Docutils front ends. + One or more sets of option group title, description, and a list/tuple of + tuples: ``('help text', [list of option strings], {keyword arguments})``. + Group title and/or description may be `None`; no group title implies no + group, just a list of single options. Option specs from Docutils + components are also used (see `populate_from_components()`).""" version_template = '%%prog (Docutils %s)' % docutils.__version__ -- cgit v1.2.1 From 087383956c0c5aba2337ab961e66b3ef18e2445f Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 27 Jul 2002 15:49:37 +0000 Subject: docstring git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@393 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 759e11472..f9e2b7880 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -20,7 +20,13 @@ from docutils import optik class OptionParser(optik.OptionParser): """ - Parser for command-line and library use. The `cmdline_options` specification here and in other Docutils components are merged + Parser for command-line and library use. The `cmdline_options` + specification here and in other Docutils components are merged to + build the set of command-line options for this process. + + Common options (defined below) and component-specific options must + not conflict. Short options are reserved for common options, and + components are restrict to using long options. """ threshold_choices = 'info 1 warning 2 error 3 severe 4 none 5'.split() -- cgit v1.2.1 From 00721f31c013181f753ed200b3fa0414f143f780 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 28 Jul 2002 17:38:04 +0000 Subject: - Added ``store_multiple()`` option callback. - Added "--source-url" option. - Return source & destination path in option values object. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@398 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index f9e2b7880..f2be2d46a 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -17,6 +17,19 @@ import docutils from docutils import optik +def store_multiple(option, opt, value, parser, *args, **kwargs): + """ + Store multiple values in `parser.values`. (Option callback.) + + Store `None` for each attribute named in `args`, and store the value for + each key (attribute name) in `kwargs`. + """ + for attribute in args: + setattr(parser.values, attribute, None) + for key, value in kwargs.items(): + setattr(parser.values, key, value) + + class OptionParser(optik.OptionParser): """ @@ -53,11 +66,15 @@ class OptionParser(optik.OptionParser): ('Do not include a datestamp of any kind.', ['--no-datestamp'], {'action': 'store_const', 'const': None, 'dest': 'datestamp'}), - ('Include a "View document source" link.', + ('Include a "View document source" link (relative to destination).', ['--source-link', '-s'], {'action': 'store_true'}), + ('Use the supplied for a "View document source" link; ' + 'implies --source-link.', + ['--source-url'], {'metavar': ''}), ('Do not include a "View document source" link.', - ['--no-source-link'], {'action': 'store_false', - 'dest': 'source_link'}), + ['--no-source-link'], + {'action': 'callback', 'callback': store_multiple, + 'callback_args': ('source_link', 'source_url')}), ('Enable backlinks from section headers to table of contents ' 'entries. This is the default.', ['--toc-entry-backlinks'], @@ -158,8 +175,8 @@ class OptionParser(optik.OptionParser): def check_values(self, values, args): values.report_level = self.check_threshold(values.report_level) values.halt_level = self.check_threshold(values.halt_level) - source, destination = self.check_args(args) - return values, source, destination + values.source, values.destination = self.check_args(args) + return values def check_threshold(self, level): try: -- cgit v1.2.1 From 0e1aadf8cc6ace83cb42ca97d89fa9d1649ad396 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 28 Jul 2002 19:37:58 +0000 Subject: Added ``read_config_file()`` option callback & "--config" option. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@408 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index f2be2d46a..100027497 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -29,6 +29,16 @@ def store_multiple(option, opt, value, parser, *args, **kwargs): for key, value in kwargs.items(): setattr(parser.values, key, value) +def read_config_file(option, opt, value, parser): + """ + Read a configuration file during option processing. (Option callback.) + """ + config = ConfigParser() + config.read(value) + if config.has_section('options'): + for entry in config.options('options'): + setattr(parser.values, entry, config.get('options', entry)) + class OptionParser(optik.OptionParser): @@ -126,6 +136,9 @@ class OptionParser(optik.OptionParser): ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', 'metavar': ''}), + ('Read this configuration .', + ['--config'], {'metavar': '', 'type': 'string', + 'action': 'callback', 'callback': read_config_file}) ("Show this program's version number and exit.", ['--version'], {'action': 'version'}), ('Show this help message and exit.', -- cgit v1.2.1 From fad349b8d9dac2aea4e20397ff4ff74143247622 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 28 Jul 2002 19:58:29 +0000 Subject: comma git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@411 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 100027497..d841a3774 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -138,7 +138,7 @@ class OptionParser(optik.OptionParser): 'metavar': ''}), ('Read this configuration .', ['--config'], {'metavar': '', 'type': 'string', - 'action': 'callback', 'callback': read_config_file}) + 'action': 'callback', 'callback': read_config_file}), ("Show this program's version number and exit.", ['--version'], {'action': 'version'}), ('Show this help message and exit.', -- cgit v1.2.1 From 3442dc02845bbf4569ddfa838bf1ea13449346fc Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 31 Jul 2002 01:38:04 +0000 Subject: Added "--quiet" option. Path-related settings now made absolute, improving batch flexibility. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@420 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 101 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 92 insertions(+), 9 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index d841a3774..be31637de 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -8,13 +8,22 @@ :Copyright: This module has been placed in the public domain. Command-line and common processing for Docutils front-end tools. + +Exports the following classes: + +- `OptionParser`: Standard Docutils command-line processing. +- `Values`: Option values; objects are simple structs (``object.attribute``). +- `ConfigParser`: Standard Docutils config file processing. """ __docformat__ = 'reStructuredText' +import os +import os.path import ConfigParser as CP import docutils from docutils import optik +from docutils.optik import Values def store_multiple(option, opt, value, parser, *args, **kwargs): @@ -33,11 +42,25 @@ def read_config_file(option, opt, value, parser): """ Read a configuration file during option processing. (Option callback.) """ - config = ConfigParser() - config.read(value) - if config.has_section('options'): - for entry in config.options('options'): - setattr(parser.values, entry, config.get('options', entry)) + config_parser = ConfigParser() + config_parser.read(value) + settings = config_parser.get_section('options') + make_paths_absolute(settings, os.path.dirname(value)) + parser.values.__dict__.update(settings) + +relative_path_options = ('warning_stream', 'stylesheet', 'pep_stylesheet', + 'pep_template') + +def make_paths_absolute(dictionary, base_path=None): + """ + Interpret filesystem path settings relative to the `base_path` given. + """ + if base_path is None: + base_path = os.getcwd() + for option in relative_path_options: + if dictionary.has_key(option) and dictionary[option]: + dictionary[option] = os.path.normpath( + os.path.join(base_path, dictionary[option])) class OptionParser(optik.OptionParser): @@ -113,6 +136,9 @@ class OptionParser(optik.OptionParser): '"--report=info".)', ['--verbose', '-v'], {'action': 'store_const', 'const': 'info', 'dest': 'report_level'}), + ('Don't report any system messages. (Same as "--report=none".)', + ['--quiet', '-q'], {'action': 'store_const', 'const': 'none', + 'dest': 'report_level'}), ('Set the threshold () at or above which system messages are ' 'converted to exceptions, halting execution immediately. Levels ' 'as in --report. Default is 4 (severe).', @@ -136,7 +162,7 @@ class OptionParser(optik.OptionParser): ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', 'metavar': ''}), - ('Read this configuration .', + ('Read configuration options from , if it exists.', ['--config'], {'metavar': '', 'type': 'string', 'action': 'callback', 'callback': read_config_file}), ("Show this program's version number and exit.", @@ -186,9 +212,12 @@ class OptionParser(optik.OptionParser): i += 3 def check_values(self, values, args): - values.report_level = self.check_threshold(values.report_level) - values.halt_level = self.check_threshold(values.halt_level) - values.source, values.destination = self.check_args(args) + if hasattr(values, 'report_level'): + values.report_level = self.check_threshold(values.report_level) + if hasattr(values, 'halt_level'): + values.halt_level = self.check_threshold(values.halt_level) + values._source, values._destination = self.check_args(args) + make_paths_absolute(values.__dict__, os.getcwd()) return values def check_threshold(self, level): @@ -213,8 +242,62 @@ class OptionParser(optik.OptionParser): class ConfigParser(CP.ConfigParser): + standard_config_files = ( + '/etc/docutils.conf', # system-wide + './docutils.conf', # project-specific + os.path.expanduser('~/.docutils')) # user-specific + """Docutils configuration files, using ConfigParser syntax (section + 'options'). Later files override earlier ones.""" + + def read_standard_files(self): + self.read(self.standard_config_files) + def optionxform(self, optionstr): """ Transform '-' to '_' so the cmdline form of option names can be used. """ return optionstr.lower().replace('-', '_') + + def get_section(self, section, raw=0, vars=None): + """ + Return a given section as a dictionary (empty if the section + doesn't exist). + + All % interpolations are expanded in the return values, based on the + defaults passed into the constructor, unless the optional argument + `raw` is true. Additional substitutions may be provided using the + `vars` argument, which must be a dictionary whose contents overrides + any pre-existing defaults. + + The section DEFAULT is special. + """ + try: + sectdict = self._ConfigParser__sections[section].copy() + except KeyError: + sectdict = {} + d = self._ConfigParser__defaults.copy() + d.update(sectdict) + # Update with the entry specific variables + if vars: + d.update(vars) + if raw: + return sectdict + # do the string interpolation + for option in sectdict.keys(): + rawval = sectdict[option] + value = rawval # Make it a pretty variable name + depth = 0 + while depth < 10: # Loop through this until it's done + depth += 1 + if value.find("%(") >= 0: + try: + value = value % d + except KeyError, key: + raise CP.InterpolationError(key, option, section, + rawval) + else: + break + if value.find("%(") >= 0: + raise CP.InterpolationDepthError(option, section, rawval) + sectdict[option] = value + return sectdict -- cgit v1.2.1 From e07795fb06abccd594d7553cc8d7c6daf7f199c4 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 31 Jul 2002 02:13:22 +0000 Subject: bugfix git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@428 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index be31637de..148a3b894 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -136,7 +136,7 @@ class OptionParser(optik.OptionParser): '"--report=info".)', ['--verbose', '-v'], {'action': 'store_const', 'const': 'info', 'dest': 'report_level'}), - ('Don't report any system messages. (Same as "--report=none".)', + ('Do not report any system messages. (Same as "--report=none".)', ['--quiet', '-q'], {'action': 'store_const', 'const': 'none', 'dest': 'report_level'}), ('Set the threshold () at or above which system messages are ' -- cgit v1.2.1 From d23a7aba7c10024f062506f8c548b3f66f3e66c6 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 8 Aug 2002 00:24:11 +0000 Subject: - Check for & exit on identical source & destination paths. - Fixed bug with absolute paths & ``--config``. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@479 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 148a3b894..c03634634 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -60,7 +60,7 @@ def make_paths_absolute(dictionary, base_path=None): for option in relative_path_options: if dictionary.has_key(option) and dictionary[option]: dictionary[option] = os.path.normpath( - os.path.join(base_path, dictionary[option])) + os.path.abspath(os.path.join(base_path, dictionary[option]))) class OptionParser(optik.OptionParser): @@ -237,6 +237,9 @@ class OptionParser(optik.OptionParser): destination = args.pop(0) if args: self.error('Maximum 2 arguments allowed.') + if source and source == destination: + self.error('Do not specify the same file for both source and ' + 'destination. It will clobber the source file.') return source, destination -- cgit v1.2.1 From 80ac56e2e5e8dda1b76a70b68f1ab63969cb88a3 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 24 Aug 2002 01:20:30 +0000 Subject: - Set non-command-line defaults in ``OptionParser.__init__()``: ``_source`` & ``_destination``. - Distributed ``relative_path_options`` to components; updated ``OptionParser.populate_from_components()`` to combine it all. - Require list of keys in ``make_paths_absolute`` (was implicit in global ``relative_path_options``). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@588 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 86 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 36 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index c03634634..1e4003b9e 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -45,25 +45,26 @@ def read_config_file(option, opt, value, parser): config_parser = ConfigParser() config_parser.read(value) settings = config_parser.get_section('options') - make_paths_absolute(settings, os.path.dirname(value)) + make_paths_absolute(settings, parser.relative_path_options, + os.path.dirname(value)) parser.values.__dict__.update(settings) -relative_path_options = ('warning_stream', 'stylesheet', 'pep_stylesheet', - 'pep_template') - -def make_paths_absolute(dictionary, base_path=None): +def make_paths_absolute(pathdict, keys, base_path=None): """ Interpret filesystem path settings relative to the `base_path` given. + + Paths are values in `pathdict` whose keys are in `keys`. Get `keys` from + `OptionParser.relative_path_options`. """ if base_path is None: base_path = os.getcwd() - for option in relative_path_options: - if dictionary.has_key(option) and dictionary[option]: - dictionary[option] = os.path.normpath( - os.path.abspath(os.path.join(base_path, dictionary[option]))) + for key in keys: + if pathdict.has_key(key) and pathdict[key]: + pathdict[key] = os.path.normpath( + os.path.abspath(os.path.join(base_path, pathdict[key]))) -class OptionParser(optik.OptionParser): +class OptionParser(optik.OptionParser, docutils.OptionSpec): """ Parser for command-line and library use. The `cmdline_options` @@ -101,9 +102,9 @@ class OptionParser(optik.OptionParser): 'dest': 'datestamp'}), ('Include a "View document source" link (relative to destination).', ['--source-link', '-s'], {'action': 'store_true'}), - ('Use the supplied for a "View document source" link; ' - 'implies --source-link.', - ['--source-url'], {'metavar': ''}), + ('Use the supplied verbatim for a "View document source" ' + 'link; implies --source-link.', + ['--source-url'], {'metavar': ''}), ('Do not include a "View document source" link.', ['--no-source-link'], {'action': 'callback', 'callback': store_multiple, @@ -173,14 +174,14 @@ class OptionParser(optik.OptionParser): (optik.SUPPRESS_HELP, ['--dump-internals'], {'action': 'store_true'}),)) - """Command-line option specifications, common to all Docutils front ends. - One or more sets of option group title, description, and a list/tuple of - tuples: ``('help text', [list of option strings], {keyword arguments})``. - Group title and/or description may be `None`; no group title implies no - group, just a list of single options. Option specs from Docutils - components are also used (see `populate_from_components()`).""" + """Command-line options common to all Docutils front ends. Option specs + specific to individual Docutils components are also used (see + `populate_from_components()`).""" + + relative_path_options = ('warning_stream',) version_template = '%%prog (Docutils %s)' % docutils.__version__ + """Default version message.""" def __init__(self, components=(), *args, **kwargs): """ @@ -188,28 +189,40 @@ class OptionParser(optik.OptionParser): ``.cmdline_options`` attribute. `defaults` is a mapping of option default overrides. """ - optik.OptionParser.__init__(self, help=None, format=optik.Titled(), - *args, **kwargs) + optik.OptionParser.__init__( + self, help=None, + format=optik.Titled(), + # Needed when Optik is updated (replaces above 2 lines): + #self, add_help=None, + #formatter=optik.TitledHelpFormatter(width=78), + *args, **kwargs) if not self.version: self.version = self.version_template + # Internal settings with no defaults from option specifications; + # initialize manually: + self.set_defaults(_source=None, _destination=None) + # Make an instance copy (it will be modified): + self.relative_path_options = list(self.relative_path_options) self.populate_from_components(tuple(components) + (self,)) def populate_from_components(self, components): for component in components: - if component is not None: - i = 0 - cmdline_options = component.cmdline_options - while i < len(cmdline_options): - title, description, option_spec = cmdline_options[i:i+3] - if title: - group = optik.OptionGroup(self, title, description) - self.add_option_group(group) - else: - group = self # single options - for (help_text, option_strings, kwargs) in option_spec: - group.add_option(help=help_text, *option_strings, - **kwargs) - i += 3 + if component is None: + continue + i = 0 + cmdline_options = component.cmdline_options + self.relative_path_options.extend(component.relative_path_options) + while i < len(cmdline_options): + title, description, option_spec = cmdline_options[i:i+3] + if title: + group = optik.OptionGroup(self, title, description) + self.add_option_group(group) + else: + group = self # single options + for (help_text, option_strings, kwargs) in option_spec: + group.add_option(help=help_text, *option_strings, + **kwargs) + i += 3 def check_values(self, values, args): if hasattr(values, 'report_level'): @@ -217,7 +230,8 @@ class OptionParser(optik.OptionParser): if hasattr(values, 'halt_level'): values.halt_level = self.check_threshold(values.halt_level) values._source, values._destination = self.check_args(args) - make_paths_absolute(values.__dict__, os.getcwd()) + make_paths_absolute(values.__dict__, self.relative_path_options, + os.getcwd()) return values def check_threshold(self, level): -- cgit v1.2.1 From 2b57d30609bb5efa7031d6aa3fdaaa9143c8041e Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 29 Aug 2002 02:49:34 +0000 Subject: Added ``option_default_overrides`` to ``docutils.OptionSpec``. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@609 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 1e4003b9e..36a20cb07 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -223,6 +223,9 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): group.add_option(help=help_text, *option_strings, **kwargs) i += 3 + for component in components: + if component and component.option_default_overrides: + self.set_defaults(component.option_default_overrides) def check_values(self, values, args): if hasattr(values, 'report_level'): -- cgit v1.2.1 From dc42b55883bb75809e9edcec8e6cd8fdbb8480b1 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 29 Aug 2002 02:57:18 +0000 Subject: fix git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@611 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 36a20cb07..9e2088787 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -225,7 +225,7 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): i += 3 for component in components: if component and component.option_default_overrides: - self.set_defaults(component.option_default_overrides) + self.defaults.update(component.option_default_overrides) def check_values(self, values, args): if hasattr(values, 'report_level'): -- cgit v1.2.1 From 2eab694fe746f8a8f99f438220daebdecf9d7893 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 15 Sep 2002 16:31:55 +0000 Subject: Added -V (version) option git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@681 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 9e2088787..155893521 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -167,7 +167,7 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): ['--config'], {'metavar': '', 'type': 'string', 'action': 'callback', 'callback': read_config_file}), ("Show this program's version number and exit.", - ['--version'], {'action': 'version'}), + ['--version', '-V'], {'action': 'version'}), ('Show this help message and exit.', ['--help', '-h'], {'action': 'help'}), # Hidden options, for development use only: -- cgit v1.2.1 From 1a6999bd968058d9eab5203c5d49227de238b093 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 8 Oct 2002 01:20:23 +0000 Subject: Added ``--expose-internal-attribute`` option. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@767 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 155893521..24cf7735c 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -173,7 +173,10 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): # Hidden options, for development use only: (optik.SUPPRESS_HELP, ['--dump-internals'], - {'action': 'store_true'}),)) + {'action': 'store_true'}), + (optik.SUPPRESS_HELP, + ['--expose-internal-attribute'], + {'action': 'append', 'dest': 'expose_internals'}),)) """Command-line options common to all Docutils front ends. Option specs specific to individual Docutils components are also used (see `populate_from_components()`).""" -- cgit v1.2.1 From efdd39867964b92520a58c6796658895e412c441 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 9 Oct 2002 00:51:53 +0000 Subject: changed docstring field lists into comments git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@778 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 24cf7735c..f99c3f667 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -1,12 +1,10 @@ -#! /usr/bin/env python +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. """ -:Author: David Goodger -:Contact: goodger@users.sourceforge.net -:Revision: $Revision$ -:Date: $Date$ -:Copyright: This module has been placed in the public domain. - Command-line and common processing for Docutils front-end tools. Exports the following classes: -- cgit v1.2.1 From afeedfb343c2904e9357997d2a50f8f3cabb2568 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 18 Oct 2002 04:55:21 +0000 Subject: Refactored names (options -> settings; .transform() -> .apply(); etc.); updated. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@825 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 54 +++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index f99c3f667..609926e40 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -10,7 +10,8 @@ Command-line and common processing for Docutils front-end tools. Exports the following classes: - `OptionParser`: Standard Docutils command-line processing. -- `Values`: Option values; objects are simple structs (``object.attribute``). +- `Values`: Runtime settings; objects are simple structs + (``object.attribute``). - `ConfigParser`: Standard Docutils config file processing. """ @@ -43,7 +44,7 @@ def read_config_file(option, opt, value, parser): config_parser = ConfigParser() config_parser.read(value) settings = config_parser.get_section('options') - make_paths_absolute(settings, parser.relative_path_options, + make_paths_absolute(settings, parser.relative_path_settings, os.path.dirname(value)) parser.values.__dict__.update(settings) @@ -52,7 +53,7 @@ def make_paths_absolute(pathdict, keys, base_path=None): Interpret filesystem path settings relative to the `base_path` given. Paths are values in `pathdict` whose keys are in `keys`. Get `keys` from - `OptionParser.relative_path_options`. + `OptionParser.relative_path_settings`. """ if base_path is None: base_path = os.getcwd() @@ -62,16 +63,16 @@ def make_paths_absolute(pathdict, keys, base_path=None): os.path.abspath(os.path.join(base_path, pathdict[key]))) -class OptionParser(optik.OptionParser, docutils.OptionSpec): +class OptionParser(optik.OptionParser, docutils.SettingsSpec): """ - Parser for command-line and library use. The `cmdline_options` - specification here and in other Docutils components are merged to - build the set of command-line options for this process. + Parser for command-line and library use. The `settings_spec` + specification here and in other Docutils components are merged to build + the set of command-line options and runtime settings for this process. - Common options (defined below) and component-specific options must - not conflict. Short options are reserved for common options, and - components are restrict to using long options. + Common settings (defined below) and component-specific settings must not + conflict. Short options are reserved for common settings, and components + are restrict to using long options. """ threshold_choices = 'info 1 warning 2 error 3 severe 4 none 5'.split() @@ -80,7 +81,7 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): thresholds = {'info': 1, 'warning': 2, 'error': 3, 'severe': 4, 'none': 5} """Lookup table for --report and --halt threshold values.""" - cmdline_options = ( + settings_spec = ( 'General Docutils Options', None, (('Include a "Generated by Docutils" credit and link at the end ' @@ -161,7 +162,7 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', 'metavar': ''}), - ('Read configuration options from , if it exists.', + ('Read configuration settings from , if it exists.', ['--config'], {'metavar': '', 'type': 'string', 'action': 'callback', 'callback': read_config_file}), ("Show this program's version number and exit.", @@ -175,11 +176,11 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): (optik.SUPPRESS_HELP, ['--expose-internal-attribute'], {'action': 'append', 'dest': 'expose_internals'}),)) - """Command-line options common to all Docutils front ends. Option specs - specific to individual Docutils components are also used (see - `populate_from_components()`).""" + """Runtime settings and command-line options common to all Docutils front + ends. Setting specs specific to individual Docutils components are also + used (see `populate_from_components()`).""" - relative_path_options = ('warning_stream',) + relative_path_settings = ('warning_stream',) version_template = '%%prog (Docutils %s)' % docutils.__version__ """Default version message.""" @@ -187,7 +188,7 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): def __init__(self, components=(), *args, **kwargs): """ `components` is a list of Docutils components each containing a - ``.cmdline_options`` attribute. `defaults` is a mapping of option + ``.settings_spec`` attribute. `defaults` is a mapping of setting default overrides. """ optik.OptionParser.__init__( @@ -199,11 +200,11 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): *args, **kwargs) if not self.version: self.version = self.version_template - # Internal settings with no defaults from option specifications; + # Internal settings with no defaults from settings specifications; # initialize manually: self.set_defaults(_source=None, _destination=None) # Make an instance copy (it will be modified): - self.relative_path_options = list(self.relative_path_options) + self.relative_path_settings = list(self.relative_path_settings) self.populate_from_components(tuple(components) + (self,)) def populate_from_components(self, components): @@ -211,10 +212,11 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): if component is None: continue i = 0 - cmdline_options = component.cmdline_options - self.relative_path_options.extend(component.relative_path_options) - while i < len(cmdline_options): - title, description, option_spec = cmdline_options[i:i+3] + settings_spec = component.settings_spec + self.relative_path_settings.extend( + component.relative_path_settings) + while i < len(settings_spec): + title, description, option_spec = settings_spec[i:i+3] if title: group = optik.OptionGroup(self, title, description) self.add_option_group(group) @@ -225,8 +227,8 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): **kwargs) i += 3 for component in components: - if component and component.option_default_overrides: - self.defaults.update(component.option_default_overrides) + if component and component.settings_default_overrides: + self.defaults.update(component.settings_default_overrides) def check_values(self, values, args): if hasattr(values, 'report_level'): @@ -234,7 +236,7 @@ class OptionParser(optik.OptionParser, docutils.OptionSpec): if hasattr(values, 'halt_level'): values.halt_level = self.check_threshold(values.halt_level) values._source, values._destination = self.check_args(args) - make_paths_absolute(values.__dict__, self.relative_path_options, + make_paths_absolute(values.__dict__, self.relative_path_settings, os.getcwd()) return values -- cgit v1.2.1 From 99fbfbba88293ef1c07f4b96cc0cf9a75dc28849 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 24 Oct 2002 00:35:43 +0000 Subject: Added "--dump-pseudo-xml", "--dump-settings", and "--dump-transforms" hidden options. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@842 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 609926e40..3c13f094e 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -170,9 +170,18 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): ('Show this help message and exit.', ['--help', '-h'], {'action': 'help'}), # Hidden options, for development use only: + (optik.SUPPRESS_HELP, + ['--dump-settings'], + {'action': 'store_true'}), (optik.SUPPRESS_HELP, ['--dump-internals'], {'action': 'store_true'}), + (optik.SUPPRESS_HELP, + ['--dump-transforms'], + {'action': 'store_true'}), + (optik.SUPPRESS_HELP, + ['--dump-pseudo-xml'], + {'action': 'store_true'}), (optik.SUPPRESS_HELP, ['--expose-internal-attribute'], {'action': 'append', 'dest': 'expose_internals'}),)) -- cgit v1.2.1 From 0fd219662d78c3136a236ea2463b5ebdbbfb441e Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 1 Jan 2003 02:12:14 +0000 Subject: removed nasty internals-fiddling ConfigParser.get_section code git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1047 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 3c13f094e..029f2763a 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -303,33 +303,8 @@ class ConfigParser(CP.ConfigParser): The section DEFAULT is special. """ - try: - sectdict = self._ConfigParser__sections[section].copy() - except KeyError: - sectdict = {} - d = self._ConfigParser__defaults.copy() - d.update(sectdict) - # Update with the entry specific variables - if vars: - d.update(vars) - if raw: - return sectdict - # do the string interpolation - for option in sectdict.keys(): - rawval = sectdict[option] - value = rawval # Make it a pretty variable name - depth = 0 - while depth < 10: # Loop through this until it's done - depth += 1 - if value.find("%(") >= 0: - try: - value = value % d - except KeyError, key: - raise CP.InterpolationError(key, option, section, - rawval) - else: - break - if value.find("%(") >= 0: - raise CP.InterpolationDepthError(option, section, rawval) - sectdict[option] = value - return sectdict + section_dict = {} + if self.has_section(section): + for option in self.options(section): + section_dict[option] = self.get(section, option, raw, vars) + return section_dict -- cgit v1.2.1 From 2d2c70309a0a98df5dd4b397c1b2ba5f40369079 Mon Sep 17 00:00:00 2001 From: grubert Date: Tue, 27 May 2003 06:43:46 +0000 Subject: Option --no-doc-info and --no-doc-title to standalone reader. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1352 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 029f2763a..691c2b565 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -43,10 +43,17 @@ def read_config_file(option, opt, value, parser): """ config_parser = ConfigParser() config_parser.read(value) - settings = config_parser.get_section('options') - make_paths_absolute(settings, parser.relative_path_settings, + + default_section = 'options' + for section_name in config_parser.sections: + if section_name == default_section: + prefix = '' + else: + prefix = section_name + '_' + settings = config_parser.get_section(section_name) + make_paths_absolute(settings, parser.relative_path_settings, os.path.dirname(value)) - parser.values.__dict__.update(settings) + parser.values.__dict__.update(settings) def make_paths_absolute(pathdict, keys, base_path=None): """ -- cgit v1.2.1 From c79fb3e264380201a4ca3c49211abd7b1a002313 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 27 May 2003 13:40:10 +0000 Subject: Revert to 1.28 code. 1.29 had bugs, was incomplete, and was premature. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1354 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 691c2b565..029f2763a 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -43,17 +43,10 @@ def read_config_file(option, opt, value, parser): """ config_parser = ConfigParser() config_parser.read(value) - - default_section = 'options' - for section_name in config_parser.sections: - if section_name == default_section: - prefix = '' - else: - prefix = section_name + '_' - settings = config_parser.get_section(section_name) - make_paths_absolute(settings, parser.relative_path_settings, + settings = config_parser.get_section('options') + make_paths_absolute(settings, parser.relative_path_settings, os.path.dirname(value)) - parser.values.__dict__.update(settings) + parser.values.__dict__.update(settings) def make_paths_absolute(pathdict, keys, base_path=None): """ -- cgit v1.2.1 From 14af1be64f8febc346e00f6e7ce696e0247f4beb Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 3 Jun 2003 02:13:27 +0000 Subject: Added validation functionality for config files. Added "--error-encoding" option/setting, "_disable_config" internal setting. Added encoding validation; updated "--input-encoding" and "--output-encoding". Moved config file processing from docutils/core.py. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1369 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 139 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 128 insertions(+), 11 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 029f2763a..f352f6254 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -19,7 +19,9 @@ __docformat__ = 'reStructuredText' import os import os.path +import types import ConfigParser as CP +import codecs import docutils from docutils import optik from docutils.optik import Values @@ -42,12 +44,62 @@ def read_config_file(option, opt, value, parser): Read a configuration file during option processing. (Option callback.) """ config_parser = ConfigParser() - config_parser.read(value) + config_parser.read(value, parser) settings = config_parser.get_section('options') make_paths_absolute(settings, parser.relative_path_settings, os.path.dirname(value)) parser.values.__dict__.update(settings) +def set_encoding(option, opt, value, parser): + """ + Validate & set the encoding specified. (Option callback.) + """ + try: + value = validate_encoding(value, option.default) + except LookupError, error: + raise optik.OptionValueError('option "%s": %s' % (opt, error)) + setattr(parser.values, option.dest, value) + +def validate_encoding(value, default): + try: + codecs.lookup(value) + except LookupError: + raise LookupError('unknown encoding: "%s"' % value) + return value + +def set_encoding_and_error_handler(option, opt, value, parser): + """ + Validate & set the encoding and error handlers specified. + (Option callback.) + """ + try: + value = validate_encoding_and_error_handler(value, option.default) + except LookupError, error: + raise optik.OptionValueError('option "%s": %s' % (opt, error)) + setattr(parser.values, option.dest, value) + +def validate_encoding_and_error_handler(value, default): + if ':' in value: + encoding, handler = value.split(':') + else: + encoding = value + handler = default.split(':')[1] + validate_encoding(encoding, default) + try: + codecs.lookup_error(handler) + except AttributeError: + if handler not in ('strict', 'ignore', 'replace'): + raise LookupError( + 'unknown encoding error handler: "%s" (choices: ' + '"strict", "ignore", or "replace")' % handler) + except LookupError: + raise LookupError( + 'unknown encoding error handler: "%s" (choices: ' + '"strict", "ignore", "replace", "backslashreplace", ' + '"xmlcharrefreplace", and possibly others; see documentation for ' + 'the Python ``codecs`` module)' % handler) + return encoding + ':' + handler + def make_paths_absolute(pathdict, keys, base_path=None): """ Interpret filesystem path settings relative to the `base_path` given. @@ -81,6 +133,11 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): thresholds = {'info': 1, 'warning': 2, 'error': 3, 'severe': 4, 'none': 5} """Lookup table for --report and --halt threshold values.""" + if hasattr(codecs, 'backslashreplace_errors'): + default_error_encoding_error_handler = 'backslashreplace' + else: + default_error_encoding_error_handler = 'replace' + settings_spec = ( 'General Docutils Options', None, @@ -154,10 +211,26 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): ('Send the output of system messages (warnings) to .', ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), ('Specify the encoding of input text. Default is locale-dependent.', - ['--input-encoding', '-i'], {'metavar': ''}), - ('Specify the encoding for output. Default is UTF-8.', + ['--input-encoding', '-i'], + {'action': 'callback', 'callback': set_encoding, + 'metavar': '', 'type': 'string', 'dest': 'input_encoding'}), + ('Specify the text encoding for output. Default is UTF-8. ' + 'Optionally also specify the encoding error handler for unencodable ' + 'characters (see "--error-encoding"); default is "strict".', ['--output-encoding', '-o'], - {'metavar': '', 'default': 'utf-8'}), + {'action': 'callback', 'callback': set_encoding_and_error_handler, + 'metavar': '', 'type': 'string', + 'dest': 'output_encoding', 'default': 'utf-8:strict'}), + ('Specify the text encoding for error output. Default is ASCII. ' + 'Optionally also specify the encoding error handler for unencodable ' + 'characters, after a colon (":"). Acceptable values are the same ' + 'as for the "error" parameter of Python\'s ``encode`` string ' + 'method. Default is "%s".' % default_error_encoding_error_handler, + ['--error-encoding', '-e'], + {'action': 'callback', 'callback': set_encoding_and_error_handler, + 'metavar': '', 'type': 'string', + 'dest': 'error_encoding', + 'default': 'ascii:%s' % default_error_encoding_error_handler}), ('Specify the language of input text (ISO 639 2-letter identifier).' ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', @@ -189,12 +262,15 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): ends. Setting specs specific to individual Docutils components are also used (see `populate_from_components()`).""" + settings_default_overrides = {'_disable_config': None} + relative_path_settings = ('warning_stream',) version_template = '%%prog (Docutils %s)' % docutils.__version__ """Default version message.""" - def __init__(self, components=(), *args, **kwargs): + def __init__(self, components=(), defaults=None, read_config_files=None, + *args, **kwargs): """ `components` is a list of Docutils components each containing a ``.settings_spec`` attribute. `defaults` is a mapping of setting @@ -209,12 +285,19 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): *args, **kwargs) if not self.version: self.version = self.version_template - # Internal settings with no defaults from settings specifications; - # initialize manually: - self.set_defaults(_source=None, _destination=None) # Make an instance copy (it will be modified): self.relative_path_settings = list(self.relative_path_settings) - self.populate_from_components(tuple(components) + (self,)) + self.populate_from_components((self,) + tuple(components)) + defaults = defaults or {} + if read_config_files and not self.defaults['_disable_config']: + config = ConfigParser() + config.read_standard_files(self) + config_settings = config.get_section('options') + make_paths_absolute(config_settings, self.relative_path_settings) + defaults.update(config_settings) + # Internal settings with no defaults from settings specifications; + # initialize manually: + self.set_defaults(_source=None, _destination=None, **defaults) def populate_from_components(self, components): for component in components: @@ -281,8 +364,42 @@ class ConfigParser(CP.ConfigParser): """Docutils configuration files, using ConfigParser syntax (section 'options'). Later files override earlier ones.""" - def read_standard_files(self): - self.read(self.standard_config_files) + validation = { + 'options': {'input_encoding': validate_encoding, + 'output_encoding': validate_encoding_and_error_handler, + 'error_encoding': validate_encoding_and_error_handler}} + """{section: {option: validation function}} mapping, used by + `validate_options`. Validation functions take two parameters: value and + default. They return a modified value, or raise an exception.""" + + def read_standard_files(self, option_parser): + self.read(self.standard_config_files, option_parser) + + def read(self, filenames, option_parser): + if type(filenames) in types.StringTypes: + filenames = [filenames] + for filename in filenames: + CP.ConfigParser.read(self, filename) + self.validate_options(filename, option_parser) + + def validate_options(self, filename, option_parser): + for section in self.validation.keys(): + if not self.has_section(section): + continue + for option in self.validation[section].keys(): + if self.has_option(section, option): + value = self.get(section, option) + validator = self.validation[section][option] + default = option_parser.defaults[option] + try: + new_value = validator(value, default) + except Exception, error: + raise ValueError( + 'Error in config file "%s", section "[%s]":\n' + ' %s: %s\n %s = %s' + % (filename, section, error.__class__.__name__, + error, option, value)) + self.set(section, option, new_value) def optionxform(self, optionstr): """ -- cgit v1.2.1 From 2d01f588ef96fc5818aa5ab29c704278d83abbc4 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 7 Jun 2003 13:28:03 +0000 Subject: improved exception traceback handling git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1386 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index f352f6254..e3730a5a8 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -19,6 +19,7 @@ __docformat__ = 'reStructuredText' import os import os.path +import sys import types import ConfigParser as CP import codecs @@ -57,14 +58,16 @@ def set_encoding(option, opt, value, parser): try: value = validate_encoding(value, option.default) except LookupError, error: - raise optik.OptionValueError('option "%s": %s' % (opt, error)) + raise (optik.OptionValueError('option "%s": %s' % (opt, error)), + None, sys.exc_info[2]) setattr(parser.values, option.dest, value) def validate_encoding(value, default): try: codecs.lookup(value) except LookupError: - raise LookupError('unknown encoding: "%s"' % value) + raise (LookupError('unknown encoding: "%s"' % value), + None, sys.exc_info[2]) return value def set_encoding_and_error_handler(option, opt, value, parser): @@ -75,7 +78,8 @@ def set_encoding_and_error_handler(option, opt, value, parser): try: value = validate_encoding_and_error_handler(value, option.default) except LookupError, error: - raise optik.OptionValueError('option "%s": %s' % (opt, error)) + raise (optik.OptionValueError('option "%s": %s' % (opt, error)), + None, sys.exc_info[2]) setattr(parser.values, option.dest, value) def validate_encoding_and_error_handler(value, default): @@ -89,15 +93,17 @@ def validate_encoding_and_error_handler(value, default): codecs.lookup_error(handler) except AttributeError: if handler not in ('strict', 'ignore', 'replace'): - raise LookupError( + raise (LookupError( 'unknown encoding error handler: "%s" (choices: ' - '"strict", "ignore", or "replace")' % handler) + '"strict", "ignore", or "replace")' % handler), + None, sys.exc_info[2]) except LookupError: - raise LookupError( + raise (LookupError( 'unknown encoding error handler: "%s" (choices: ' '"strict", "ignore", "replace", "backslashreplace", ' '"xmlcharrefreplace", and possibly others; see documentation for ' - 'the Python ``codecs`` module)' % handler) + 'the Python ``codecs`` module)' % handler), + None, sys.exc_info[2]) return encoding + ':' + handler def make_paths_absolute(pathdict, keys, base_path=None): @@ -394,11 +400,11 @@ class ConfigParser(CP.ConfigParser): try: new_value = validator(value, default) except Exception, error: - raise ValueError( + raise (ValueError( 'Error in config file "%s", section "[%s]":\n' ' %s: %s\n %s = %s' % (filename, section, error.__class__.__name__, - error, option, value)) + error, option, value)), None, sys.exc_info()[2]) self.set(section, option, new_value) def optionxform(self, optionstr): -- cgit v1.2.1 From 67dba3f23a1da81334876b9ee9a429217da8df10 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 7 Jun 2003 13:33:42 +0000 Subject: fallback default encoding error handler git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1388 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index e3730a5a8..dc2169476 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -87,7 +87,9 @@ def validate_encoding_and_error_handler(value, default): encoding, handler = value.split(':') else: encoding = value - handler = default.split(':')[1] + # "strict" is a fallback default encoding error handler if none + # specified by the default value: + handler = (default.split(':') + ['strict'])[1] validate_encoding(encoding, default) try: codecs.lookup_error(handler) -- cgit v1.2.1 From c0da697b15b457a146dc3ea05be145ac1d211cdd Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 7 Jun 2003 13:57:03 +0000 Subject: use possibly updated option defaults from OptionParser, not Option git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1389 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index dc2169476..69d3152fd 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -56,7 +56,7 @@ def set_encoding(option, opt, value, parser): Validate & set the encoding specified. (Option callback.) """ try: - value = validate_encoding(value, option.default) + value = validate_encoding(value, parser.defaults[option.dest]) except LookupError, error: raise (optik.OptionValueError('option "%s": %s' % (opt, error)), None, sys.exc_info[2]) @@ -76,7 +76,8 @@ def set_encoding_and_error_handler(option, opt, value, parser): (Option callback.) """ try: - value = validate_encoding_and_error_handler(value, option.default) + value = validate_encoding_and_error_handler( + value, parser.defaults[option.dest]) except LookupError, error: raise (optik.OptionValueError('option "%s": %s' % (opt, error)), None, sys.exc_info[2]) -- cgit v1.2.1 From 30efea70114c19273c78bbdbb255a05ebb4ee177 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 7 Jun 2003 13:59:29 +0000 Subject: () added git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1390 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 69d3152fd..2597cc5d0 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -59,7 +59,7 @@ def set_encoding(option, opt, value, parser): value = validate_encoding(value, parser.defaults[option.dest]) except LookupError, error: raise (optik.OptionValueError('option "%s": %s' % (opt, error)), - None, sys.exc_info[2]) + None, sys.exc_info()[2]) setattr(parser.values, option.dest, value) def validate_encoding(value, default): @@ -67,7 +67,7 @@ def validate_encoding(value, default): codecs.lookup(value) except LookupError: raise (LookupError('unknown encoding: "%s"' % value), - None, sys.exc_info[2]) + None, sys.exc_info()[2]) return value def set_encoding_and_error_handler(option, opt, value, parser): @@ -80,7 +80,7 @@ def set_encoding_and_error_handler(option, opt, value, parser): value, parser.defaults[option.dest]) except LookupError, error: raise (optik.OptionValueError('option "%s": %s' % (opt, error)), - None, sys.exc_info[2]) + None, sys.exc_info()[2]) setattr(parser.values, option.dest, value) def validate_encoding_and_error_handler(value, default): @@ -99,14 +99,14 @@ def validate_encoding_and_error_handler(value, default): raise (LookupError( 'unknown encoding error handler: "%s" (choices: ' '"strict", "ignore", or "replace")' % handler), - None, sys.exc_info[2]) + None, sys.exc_info()[2]) except LookupError: raise (LookupError( 'unknown encoding error handler: "%s" (choices: ' '"strict", "ignore", "replace", "backslashreplace", ' '"xmlcharrefreplace", and possibly others; see documentation for ' 'the Python ``codecs`` module)' % handler), - None, sys.exc_info[2]) + None, sys.exc_info()[2]) return encoding + ':' + handler def make_paths_absolute(pathdict, keys, base_path=None): -- cgit v1.2.1 From 9ade7d7ac8e96945d4d7c51cf3bb3b1f48e8f138 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 8 Jun 2003 20:56:38 +0000 Subject: Updated encoding handling and setting validation. Added "--error-encoding-error-handler" and "--output-encoding-error-handler". git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1400 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 101 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 33 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 2597cc5d0..2acfbee93 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -56,13 +56,13 @@ def set_encoding(option, opt, value, parser): Validate & set the encoding specified. (Option callback.) """ try: - value = validate_encoding(value, parser.defaults[option.dest]) + value = validate_encoding(option.dest, value) except LookupError, error: raise (optik.OptionValueError('option "%s": %s' % (opt, error)), None, sys.exc_info()[2]) setattr(parser.values, option.dest, value) -def validate_encoding(value, default): +def validate_encoding(name, value): try: codecs.lookup(value) except LookupError: @@ -70,44 +70,59 @@ def validate_encoding(value, default): None, sys.exc_info()[2]) return value -def set_encoding_and_error_handler(option, opt, value, parser): +def set_encoding_error_handler(option, opt, value, parser): """ - Validate & set the encoding and error handlers specified. - (Option callback.) + Validate & set the encoding error handler specified. (Option callback.) """ try: - value = validate_encoding_and_error_handler( - value, parser.defaults[option.dest]) + value = validate_encoding_error_handler(option.dest, value) except LookupError, error: raise (optik.OptionValueError('option "%s": %s' % (opt, error)), None, sys.exc_info()[2]) setattr(parser.values, option.dest, value) -def validate_encoding_and_error_handler(value, default): - if ':' in value: - encoding, handler = value.split(':') - else: - encoding = value - # "strict" is a fallback default encoding error handler if none - # specified by the default value: - handler = (default.split(':') + ['strict'])[1] - validate_encoding(encoding, default) +def validate_encoding_error_handler(name, value): try: - codecs.lookup_error(handler) - except AttributeError: - if handler not in ('strict', 'ignore', 'replace'): + codecs.lookup_error(value) + except AttributeError: # prior to Python 2.3 + if value not in ('strict', 'ignore', 'replace'): raise (LookupError( 'unknown encoding error handler: "%s" (choices: ' - '"strict", "ignore", or "replace")' % handler), + '"strict", "ignore", or "replace")' % value), None, sys.exc_info()[2]) except LookupError: raise (LookupError( 'unknown encoding error handler: "%s" (choices: ' '"strict", "ignore", "replace", "backslashreplace", ' '"xmlcharrefreplace", and possibly others; see documentation for ' - 'the Python ``codecs`` module)' % handler), + 'the Python ``codecs`` module)' % value), + None, sys.exc_info()[2]) + return value + +def set_encoding_and_error_handler(option, opt, value, parser): + """ + Validate & set the encoding and error handler specified. (Option callback.) + """ + try: + value = validate_encoding_and_error_handler(option.dest, value) + except LookupError, error: + raise (optik.OptionValueError('option "%s": %s' % (opt, error)), None, sys.exc_info()[2]) - return encoding + ':' + handler + if ':' in value: + encoding, handler = value.split(':') + setattr(parser.values, option.dest + '_error_handler', handler) + else: + encoding = value + setattr(parser.values, option.dest, encoding) + +def validate_encoding_and_error_handler(name, value): + if ':' in value: + encoding, handler = value.split(':') + validate_encoding_error_handler(name + '_error_handler', handler) + else: + encoding = value + validate_encoding(name, encoding) + return value def make_paths_absolute(pathdict, keys, base_path=None): """ @@ -229,7 +244,12 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): ['--output-encoding', '-o'], {'action': 'callback', 'callback': set_encoding_and_error_handler, 'metavar': '', 'type': 'string', - 'dest': 'output_encoding', 'default': 'utf-8:strict'}), + 'dest': 'output_encoding', 'default': 'utf-8'}), + (optik.SUPPRESS_HELP, # usually handled by --output-encoding + ['--output_encoding_error_handler'], + {'action': 'callback', 'callback': set_encoding_error_handler, + 'type': 'string', 'dest': 'output_encoding_error_handler', + 'default': 'strict'}), ('Specify the text encoding for error output. Default is ASCII. ' 'Optionally also specify the encoding error handler for unencodable ' 'characters, after a colon (":"). Acceptable values are the same ' @@ -238,8 +258,12 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): ['--error-encoding', '-e'], {'action': 'callback', 'callback': set_encoding_and_error_handler, 'metavar': '', 'type': 'string', - 'dest': 'error_encoding', - 'default': 'ascii:%s' % default_error_encoding_error_handler}), + 'dest': 'error_encoding', 'default': 'ascii'}), + (optik.SUPPRESS_HELP, # usually handled by --error-encoding + ['--error_encoding_error_handler'], + {'action': 'callback', 'callback': set_encoding_error_handler, + 'type': 'string', 'dest': 'error_encoding_error_handler', + 'default': default_error_encoding_error_handler}), ('Specify the language of input text (ISO 639 2-letter identifier).' ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', @@ -271,7 +295,8 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): ends. Setting specs specific to individual Docutils components are also used (see `populate_from_components()`).""" - settings_default_overrides = {'_disable_config': None} + settings_defaults = {'_disable_config': None} + """Defaults for settings that don't have command-line option equivalents.""" relative_path_settings = ('warning_stream',) @@ -309,6 +334,12 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): self.set_defaults(_source=None, _destination=None, **defaults) def populate_from_components(self, components): + """ + For each component, first populate from the `SettingsSpec.settings_spec` + structure, then from the `SettingsSpec.settings_defaults` dictionary. + After all components have been processed, check for and populate from + each component's `SettingsSpec.settings_default_overrides` dictionary. + """ for component in components: if component is None: continue @@ -326,6 +357,8 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): for (help_text, option_strings, kwargs) in option_spec: group.add_option(help=help_text, *option_strings, **kwargs) + if component.settings_defaults: + self.defaults.update(component.settings_defaults) i += 3 for component in components: if component and component.settings_default_overrides: @@ -374,12 +407,15 @@ class ConfigParser(CP.ConfigParser): 'options'). Later files override earlier ones.""" validation = { - 'options': {'input_encoding': validate_encoding, - 'output_encoding': validate_encoding_and_error_handler, - 'error_encoding': validate_encoding_and_error_handler}} + 'options': + {'input_encoding': validate_encoding, + 'output_encoding': validate_encoding, + 'output_encoding_error_handler': validate_encoding_error_handler, + 'error_encoding': validate_encoding, + 'error_encoding_error_handler': validate_encoding_error_handler}} """{section: {option: validation function}} mapping, used by - `validate_options`. Validation functions take two parameters: value and - default. They return a modified value, or raise an exception.""" + `validate_options`. Validation functions take two parameters: name and + value. They return a (possibly modified) value, or raise an exception.""" def read_standard_files(self, option_parser): self.read(self.standard_config_files, option_parser) @@ -399,9 +435,8 @@ class ConfigParser(CP.ConfigParser): if self.has_option(section, option): value = self.get(section, option) validator = self.validation[section][option] - default = option_parser.defaults[option] try: - new_value = validator(value, default) + new_value = validator(option, value) except Exception, error: raise (ValueError( 'Error in config file "%s", section "[%s]":\n' -- cgit v1.2.1 From 4d5856ed0b53ed121be993e520271fc0e4a1ce55 Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 16 Jun 2003 03:26:53 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1470 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 2acfbee93..acf44e3b2 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -24,8 +24,8 @@ import types import ConfigParser as CP import codecs import docutils -from docutils import optik -from docutils.optik import Values +import optparse +from optparse import Values, SUPPRESS_HELP def store_multiple(option, opt, value, parser, *args, **kwargs): @@ -58,7 +58,7 @@ def set_encoding(option, opt, value, parser): try: value = validate_encoding(option.dest, value) except LookupError, error: - raise (optik.OptionValueError('option "%s": %s' % (opt, error)), + raise (optparse.OptionValueError('option "%s": %s' % (opt, error)), None, sys.exc_info()[2]) setattr(parser.values, option.dest, value) @@ -77,7 +77,7 @@ def set_encoding_error_handler(option, opt, value, parser): try: value = validate_encoding_error_handler(option.dest, value) except LookupError, error: - raise (optik.OptionValueError('option "%s": %s' % (opt, error)), + raise (optparse.OptionValueError('option "%s": %s' % (opt, error)), None, sys.exc_info()[2]) setattr(parser.values, option.dest, value) @@ -106,7 +106,7 @@ def set_encoding_and_error_handler(option, opt, value, parser): try: value = validate_encoding_and_error_handler(option.dest, value) except LookupError, error: - raise (optik.OptionValueError('option "%s": %s' % (opt, error)), + raise (optparse.OptionValueError('option "%s": %s' % (opt, error)), None, sys.exc_info()[2]) if ':' in value: encoding, handler = value.split(':') @@ -139,7 +139,7 @@ def make_paths_absolute(pathdict, keys, base_path=None): os.path.abspath(os.path.join(base_path, pathdict[key]))) -class OptionParser(optik.OptionParser, docutils.SettingsSpec): +class OptionParser(optparse.OptionParser, docutils.SettingsSpec): """ Parser for command-line and library use. The `settings_spec` @@ -245,7 +245,7 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): {'action': 'callback', 'callback': set_encoding_and_error_handler, 'metavar': '', 'type': 'string', 'dest': 'output_encoding', 'default': 'utf-8'}), - (optik.SUPPRESS_HELP, # usually handled by --output-encoding + (SUPPRESS_HELP, # usually handled by --output-encoding ['--output_encoding_error_handler'], {'action': 'callback', 'callback': set_encoding_error_handler, 'type': 'string', 'dest': 'output_encoding_error_handler', @@ -259,7 +259,7 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): {'action': 'callback', 'callback': set_encoding_and_error_handler, 'metavar': '', 'type': 'string', 'dest': 'error_encoding', 'default': 'ascii'}), - (optik.SUPPRESS_HELP, # usually handled by --error-encoding + (SUPPRESS_HELP, # usually handled by --error-encoding ['--error_encoding_error_handler'], {'action': 'callback', 'callback': set_encoding_error_handler, 'type': 'string', 'dest': 'error_encoding_error_handler', @@ -276,20 +276,11 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): ('Show this help message and exit.', ['--help', '-h'], {'action': 'help'}), # Hidden options, for development use only: - (optik.SUPPRESS_HELP, - ['--dump-settings'], - {'action': 'store_true'}), - (optik.SUPPRESS_HELP, - ['--dump-internals'], - {'action': 'store_true'}), - (optik.SUPPRESS_HELP, - ['--dump-transforms'], - {'action': 'store_true'}), - (optik.SUPPRESS_HELP, - ['--dump-pseudo-xml'], - {'action': 'store_true'}), - (optik.SUPPRESS_HELP, - ['--expose-internal-attribute'], + (SUPPRESS_HELP, ['--dump-settings'], {'action': 'store_true'}), + (SUPPRESS_HELP, ['--dump-internals'], {'action': 'store_true'}), + (SUPPRESS_HELP, ['--dump-transforms'], {'action': 'store_true'}), + (SUPPRESS_HELP, ['--dump-pseudo-xml'], {'action': 'store_true'}), + (SUPPRESS_HELP, ['--expose-internal-attribute'], {'action': 'append', 'dest': 'expose_internals'}),)) """Runtime settings and command-line options common to all Docutils front ends. Setting specs specific to individual Docutils components are also @@ -310,12 +301,9 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): ``.settings_spec`` attribute. `defaults` is a mapping of setting default overrides. """ - optik.OptionParser.__init__( - self, help=None, - format=optik.Titled(), - # Needed when Optik is updated (replaces above 2 lines): - #self, add_help=None, - #formatter=optik.TitledHelpFormatter(width=78), + optparse.OptionParser.__init__( + self, add_help_option=None, + formatter=optparse.TitledHelpFormatter(width=78), *args, **kwargs) if not self.version: self.version = self.version_template @@ -350,7 +338,7 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): while i < len(settings_spec): title, description, option_spec = settings_spec[i:i+3] if title: - group = optik.OptionGroup(self, title, description) + group = optparse.OptionGroup(self, title, description) self.add_option_group(group) else: group = self # single options @@ -387,8 +375,12 @@ class OptionParser(optik.OptionParser, docutils.SettingsSpec): source = destination = None if args: source = args.pop(0) + if source == '-': # means stdin + source = None if args: destination = args.pop(0) + if destination == '-': # means stdout + destination = None if args: self.error('Maximum 2 arguments allowed.') if source and source == destination: -- cgit v1.2.1 From a546d701795706cda0f378fb29f18fa5a45c1c9f Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 16 Jun 2003 17:31:37 +0000 Subject: Added "exit_level" setting ("--exit" option). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1479 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index acf44e3b2..d1393e003 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -228,6 +228,12 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Same as "--halt=info": halt processing at the slightest problem.', ['--strict'], {'action': 'store_const', 'const': 'info', 'dest': 'halt_level'}), + ('Enable a non-zero exit status for normal exit if non-halting ' + 'system messages (at or above ) were generated. Levels as ' + 'in --report. Default is 5 (disabled). Exit status is the maximum ' + 'system message level plus 10 (11 for INFO, etc.).', + ['--exit'], {'choices': threshold_choices, 'dest': 'exit_level', + 'default': 5, 'metavar': ''}), ('Report debug-level system messages.', ['--debug'], {'action': 'store_true'}), ('Do not report debug-level system messages.', @@ -357,6 +363,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): values.report_level = self.check_threshold(values.report_level) if hasattr(values, 'halt_level'): values.halt_level = self.check_threshold(values.halt_level) + if hasattr(values, 'exit_level'): + values.exit_level = self.check_threshold(values.exit_level) values._source, values._destination = self.check_args(args) make_paths_absolute(values.__dict__, self.relative_path_settings, os.getcwd()) -- cgit v1.2.1 From 1a7567c0b74bd5b6f2e4725ddbb0a3c148569670 Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 30 Jun 2003 15:26:41 +0000 Subject: Added "--traceback" & "--no-traceback" options ("traceback" setting). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1532 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index d1393e003..5952ec19e 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -234,12 +234,18 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): 'system message level plus 10 (11 for INFO, etc.).', ['--exit'], {'choices': threshold_choices, 'dest': 'exit_level', 'default': 5, 'metavar': ''}), - ('Report debug-level system messages.', + ('Report debug-level system messages and generate diagnostic output.', ['--debug'], {'action': 'store_true'}), - ('Do not report debug-level system messages.', + ('Do not report debug-level system messages or generate diagnostic ' + 'output.', ['--no-debug'], {'action': 'store_false', 'dest': 'debug'}), ('Send the output of system messages (warnings) to .', ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), + ('Enable Python tracebacks when an error occurs.', + ['--traceback'], {'action': 'store_true', 'default': None}), + ('Disable Python tracebacks when errors occur; report just the error ' + 'instead. This is the default.', + ['--no-traceback'], {'dest': 'traceback', 'action': 'store_false'}), ('Specify the encoding of input text. Default is locale-dependent.', ['--input-encoding', '-i'], {'action': 'callback', 'callback': set_encoding, -- cgit v1.2.1 From 02f76ed5085bdfdcf025e83117d59fa2f482d284 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 5 Jul 2003 19:43:13 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1572 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 5952ec19e..2aeb1049a 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -324,6 +324,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): self.populate_from_components((self,) + tuple(components)) defaults = defaults or {} if read_config_files and not self.defaults['_disable_config']: + # @@@ Extract this code into a method, which can be called from + # the read_config_file callback also. config = ConfigParser() config.read_standard_files(self) config_settings = config.get_section('options') -- cgit v1.2.1 From d814bdb1076cb781bf9c3b0688ba9e7a6397cb03 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 27 Aug 2003 20:43:24 +0000 Subject: Implemented support for config file reorganization: ``standard_config_files`` moved from ``ConfigParser`` to ``OptionParser``; added ``OptionParser.get_config_file_settings()`` and ``.get_standard_config_settings()``; support for old "[options]" section (with deprecation warning) and mapping from old to new settings. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1643 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 96 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 21 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 2aeb1049a..c1d10fe0c 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -21,6 +21,7 @@ import os import os.path import sys import types +import warnings import ConfigParser as CP import codecs import docutils @@ -44,11 +45,7 @@ def read_config_file(option, opt, value, parser): """ Read a configuration file during option processing. (Option callback.) """ - config_parser = ConfigParser() - config_parser.read(value, parser) - settings = config_parser.get_section('options') - make_paths_absolute(settings, parser.relative_path_settings, - os.path.dirname(value)) + settings = parser.get_config_file_settings(value) parser.values.__dict__.update(settings) def set_encoding(option, opt, value, parser): @@ -151,6 +148,13 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): are restrict to using long options. """ + standard_config_files = [ + '/etc/docutils.conf', # system-wide + './docutils.conf', # project-specific + os.path.expanduser('~/.docutils')] # user-specific + """Docutils configuration files, using ConfigParser syntax. + Later files override earlier ones.""" + threshold_choices = 'info 1 warning 2 error 3 severe 4 none 5'.split() """Possible inputs for for --report and --halt threshold values.""" @@ -303,6 +307,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): relative_path_settings = ('warning_stream',) + config_section = 'general' + version_template = '%%prog (Docutils %s)' % docutils.__version__ """Default version message.""" @@ -321,15 +327,11 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): self.version = self.version_template # Make an instance copy (it will be modified): self.relative_path_settings = list(self.relative_path_settings) - self.populate_from_components((self,) + tuple(components)) + self.components = (self,) + tuple(components) + self.populate_from_components(self.components) defaults = defaults or {} if read_config_files and not self.defaults['_disable_config']: - # @@@ Extract this code into a method, which can be called from - # the read_config_file callback also. - config = ConfigParser() - config.read_standard_files(self) - config_settings = config.get_section('options') - make_paths_absolute(config_settings, self.relative_path_settings) + config_settings = self.get_standard_config_settings() defaults.update(config_settings) # Internal settings with no defaults from settings specifications; # initialize manually: @@ -366,6 +368,31 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): if component and component.settings_default_overrides: self.defaults.update(component.settings_default_overrides) + def get_standard_config_settings(self): + settings = {} + for filename in self.standard_config_files: + settings.update(self.get_config_file_settings(filename)) + return settings + + def get_config_file_settings(self, config_file): + parser = ConfigParser() + parser.read(config_file, self) + base_path = os.path.dirname(config_file) + applied = {} + settings = {} + for component in self.components: + if not component: + continue + for section in (tuple(component.config_section_dependencies or ()) + + (component.config_section,)): + if applied.has_key(section): + continue + applied[section] = 1 + settings.update(parser.get_section(section)) + make_paths_absolute( + settings, self.relative_path_settings, base_path) + return settings + def check_values(self, values, args): if hasattr(values, 'report_level'): values.report_level = self.check_threshold(values.report_level) @@ -407,13 +434,6 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): class ConfigParser(CP.ConfigParser): - standard_config_files = ( - '/etc/docutils.conf', # system-wide - './docutils.conf', # project-specific - os.path.expanduser('~/.docutils')) # user-specific - """Docutils configuration files, using ConfigParser syntax (section - 'options'). Later files override earlier ones.""" - validation = { 'options': {'input_encoding': validate_encoding, @@ -425,16 +445,46 @@ class ConfigParser(CP.ConfigParser): `validate_options`. Validation functions take two parameters: name and value. They return a (possibly modified) value, or raise an exception.""" - def read_standard_files(self, option_parser): - self.read(self.standard_config_files, option_parser) + old_settings = { + 'pep_stylesheet': ('pep_html writer', 'stylesheet'), + 'pep_stylesheet_path': ('pep_html writer', 'stylesheet_path'), + 'pep_template': ('pep_html writer', 'template')} + """{old setting: (new section, new setting)} mapping, used by + `handle_old_config`, to convert settings from the old [options] section.""" + + old_warning = """ +The "[option]" section is deprecated. Support for old-format configuration +files will be removed in a future Docutils release. Please revise your +configuration files. See . +""" def read(self, filenames, option_parser): if type(filenames) in types.StringTypes: filenames = [filenames] for filename in filenames: CP.ConfigParser.read(self, filename) + if self.has_section('options'): + self.handle_old_config(filename) self.validate_options(filename, option_parser) + def handle_old_config(self, filename): + warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, + filename, 0) + options = self.get_section('options') + if not self.has_section('general'): + self.add_section('general') + for key, value in options.items(): + if self.old_settings.has_key(key): + section, setting = self.old_settings[key] + if not self.has_section(section): + self.add_section(section) + else: + section = 'general' + setting = key + if not self.has_option(section, setting): + self.set(section, setting, value) + self.remove_section('options') + def validate_options(self, filename, option_parser): for section in self.validation.keys(): if not self.has_section(section): @@ -477,3 +527,7 @@ class ConfigParser(CP.ConfigParser): for option in self.options(section): section_dict[option] = self.get(section, option, raw, vars) return section_dict + + +class ConfigDeprecationWarning(DeprecationWarning): + """Warning for deprecated configuration file features.""" -- cgit v1.2.1 From 55abea8d367801213b71637cd105e94a7efa21cd Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 1 Sep 2003 15:02:17 +0000 Subject: Reimplemented setting validation. Enabled flexible boolean values: yes/no, true/false, on/off. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1658 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 330 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 204 insertions(+), 126 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index c1d10fe0c..091992bde 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -9,10 +9,21 @@ Command-line and common processing for Docutils front-end tools. Exports the following classes: -- `OptionParser`: Standard Docutils command-line processing. -- `Values`: Runtime settings; objects are simple structs +* `OptionParser`: Standard Docutils command-line processing. +* `Option`: Customized version of `optparse.Option`; validation support. +* `Values`: Runtime settings; objects are simple structs (``object.attribute``). -- `ConfigParser`: Standard Docutils config file processing. +* `ConfigParser`: Standard Docutils config file processing. +* `DictUpdater`: Supports cumulative list settings (dict values). + +Also exports the following functions: + +* Option callbacks: `store_multiple`, `read_config_file`. +* Setting validators (see `OptionParser.validators`: `validate_encoding`, + `validate_encoding_error_handler`, `validate_encoding_and_error_handler`, + `validate_boolean`, `validate_threshold`, + `validate_colon_separated_string_list`. +* `make_paths_absolute`. """ __docformat__ = 'reStructuredText' @@ -21,6 +32,7 @@ import os import os.path import sys import types +import copy import warnings import ConfigParser as CP import codecs @@ -45,40 +57,26 @@ def read_config_file(option, opt, value, parser): """ Read a configuration file during option processing. (Option callback.) """ - settings = parser.get_config_file_settings(value) - parser.values.__dict__.update(settings) - -def set_encoding(option, opt, value, parser): - """ - Validate & set the encoding specified. (Option callback.) - """ try: - value = validate_encoding(option.dest, value) - except LookupError, error: - raise (optparse.OptionValueError('option "%s": %s' % (opt, error)), - None, sys.exc_info()[2]) - setattr(parser.values, option.dest, value) - -def validate_encoding(name, value): + new_settings = parser.get_config_file_settings(value) + except ValueError, error: + parser.error(error) + settings = DictUpdater(parser, parser.values.__dict__) + settings.update(new_settings) + parser.values._update_loose(settings.data) + +def validate_encoding(setting, value, option_parser, + config_parser=None, config_section=None): try: codecs.lookup(value) except LookupError: - raise (LookupError('unknown encoding: "%s"' % value), + raise (LookupError('setting "%s": unknown encoding: "%s"' + % (setting, value)), None, sys.exc_info()[2]) return value -def set_encoding_error_handler(option, opt, value, parser): - """ - Validate & set the encoding error handler specified. (Option callback.) - """ - try: - value = validate_encoding_error_handler(option.dest, value) - except LookupError, error: - raise (optparse.OptionValueError('option "%s": %s' % (opt, error)), - None, sys.exc_info()[2]) - setattr(parser.values, option.dest, value) - -def validate_encoding_error_handler(name, value): +def validate_encoding_error_handler(setting, value, option_parser, + config_parser=None, config_section=None): try: codecs.lookup_error(value) except AttributeError: # prior to Python 2.3 @@ -96,29 +94,57 @@ def validate_encoding_error_handler(name, value): None, sys.exc_info()[2]) return value -def set_encoding_and_error_handler(option, opt, value, parser): +def validate_encoding_and_error_handler( + setting, value, option_parser, config_parser=None, config_section=None): """ - Validate & set the encoding and error handler specified. (Option callback.) + Side-effect: if an error handler is included in the value, it is inserted + into the appropriate place as if it was a separate setting/option. """ - try: - value = validate_encoding_and_error_handler(option.dest, value) - except LookupError, error: - raise (optparse.OptionValueError('option "%s": %s' % (opt, error)), - None, sys.exc_info()[2]) if ':' in value: encoding, handler = value.split(':') - setattr(parser.values, option.dest + '_error_handler', handler) + validate_encoding_error_handler( + setting + '_error_handler', handler, option_parser, + config_parser, config_section) + if config_parser: + config_parser.set(config_section, setting + '_error_handler', + handler) + else: + setattr(option_parser.values, setting + '_error_handler', handler) else: encoding = value - setattr(parser.values, option.dest, encoding) + validate_encoding(setting, encoding, option_parser, + config_parser, config_section) + return encoding -def validate_encoding_and_error_handler(name, value): - if ':' in value: - encoding, handler = value.split(':') - validate_encoding_error_handler(name + '_error_handler', handler) +def validate_boolean(setting, value, option_parser, + config_parser=None, config_section=None): + if isinstance(value, types.StringType): + try: + return option_parser.booleans[value.strip().lower()] + except KeyError: + raise (LookupError('unknown boolean value: "%s"' % value), + None, sys.exc_info()[2]) + return value + +def validate_threshold(setting, value, option_parser, + config_parser=None, config_section=None): + try: + int(value) + return value + except ValueError: + try: + return option_parser.thresholds[value.lower()] + except (KeyError, AttributeError): + raise (LookupError('unknown threshold: %r.' % value), + None, sys.exc_info[2]) + +def validate_colon_separated_string_list( + setting, value, option_parser, config_parser=None, config_section=None): + if isinstance(value, types.StringType): + value = value.split(':') else: - encoding = value - validate_encoding(name, encoding) + last = value.pop() + value.extend(last.split(':')) return value def make_paths_absolute(pathdict, keys, base_path=None): @@ -131,9 +157,41 @@ def make_paths_absolute(pathdict, keys, base_path=None): if base_path is None: base_path = os.getcwd() for key in keys: - if pathdict.has_key(key) and pathdict[key]: - pathdict[key] = os.path.normpath( - os.path.abspath(os.path.join(base_path, pathdict[key]))) + if pathdict.has_key(key): + value = pathdict[key] + if isinstance(value, types.ListType): + value = [make_one_path_absolute(base_path, path) + for path in value] + elif value: + value = make_one_path_absolute(base_path, value) + pathdict[key] = value + +def make_one_path_absolute(base_path, path): + return os.path.abspath(os.path.join(base_path, path)) + + +class Option(optparse.Option): + + def process(self, opt, value, values, parser): + """ + Call the validator function on applicable settings. + Extends `optparse.Option.process`. + """ + result = optparse.Option.process(self, opt, value, values, parser) + setting = self.dest + if setting: + value = getattr(values, setting) + validator = parser.validators.get(setting) + if validator: + try: + new_value = validator(setting, value, parser) + except Exception, error: + raise (optparse.OptionValueError( + 'Error in option "%s":\n %s: %s' + % (opt, error.__class__.__name__, error)), + None, sys.exc_info()[2]) + setattr(values, setting, new_value) + return result class OptionParser(optparse.OptionParser, docutils.SettingsSpec): @@ -161,6 +219,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): thresholds = {'info': 1, 'warning': 2, 'error': 3, 'severe': 4, 'none': 5} """Lookup table for --report and --halt threshold values.""" + booleans={'1': 1, 'on': 1, 'yes': 1, 'true': 1, + '0': 0, 'off': 0, 'no': 0, 'false': 0, '': 0} + """Lookup table for boolean configuration file settings.""" + if hasattr(codecs, 'backslashreplace_errors'): default_error_encoding_error_handler = 'backslashreplace' else: @@ -171,7 +233,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): None, (('Include a "Generated by Docutils" credit and link at the end ' 'of the document.', - ['--generator', '-g'], {'action': 'store_true'}), + ['--generator', '-g'], {'action': 'store_true', + 'validator': validate_boolean}), ('Do not include a generator credit.', ['--no-generator'], {'action': 'store_false', 'dest': 'generator'}), ('Include the date at the end of the document (UTC).', @@ -185,7 +248,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ['--no-datestamp'], {'action': 'store_const', 'const': None, 'dest': 'datestamp'}), ('Include a "View document source" link (relative to destination).', - ['--source-link', '-s'], {'action': 'store_true'}), + ['--source-link', '-s'], {'action': 'store_true', + 'validator': validate_boolean}), ('Use the supplied verbatim for a "View document source" ' 'link; implies --source-link.', ['--source-url'], {'metavar': ''}), @@ -208,7 +272,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Enable backlinks from footnotes and citations to their ' 'references. This is the default.', ['--footnote-backlinks'], - {'action': 'store_true', 'default': 1}), + {'action': 'store_true', 'default': 1, + 'validator': validate_boolean}), ('Disable backlinks from footnotes and citations.', ['--no-footnote-backlinks'], {'dest': 'footnote_backlinks', 'action': 'store_false'}), @@ -216,7 +281,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ' (by name or number: "info" or "1", warning/2, error/3, ' 'severe/4; also, "none" or "5"). Default is 2 (warning).', ['--report', '-r'], {'choices': threshold_choices, 'default': 2, - 'dest': 'report_level', 'metavar': ''}), + 'dest': 'report_level', 'metavar': '', + 'validator': validate_threshold}), ('Report all system messages, info-level and higher. (Same as ' '"--report=info".)', ['--verbose', '-v'], {'action': 'store_const', 'const': 'info', @@ -228,7 +294,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): 'converted to exceptions, halting execution immediately. Levels ' 'as in --report. Default is 4 (severe).', ['--halt'], {'choices': threshold_choices, 'dest': 'halt_level', - 'default': 4, 'metavar': ''}), + 'default': 4, 'metavar': '', + 'validator': validate_threshold}), ('Same as "--halt=info": halt processing at the slightest problem.', ['--strict'], {'action': 'store_const', 'const': 'info', 'dest': 'halt_level'}), @@ -237,49 +304,45 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): 'in --report. Default is 5 (disabled). Exit status is the maximum ' 'system message level plus 10 (11 for INFO, etc.).', ['--exit'], {'choices': threshold_choices, 'dest': 'exit_level', - 'default': 5, 'metavar': ''}), + 'default': 5, 'metavar': '', + 'validator': validate_threshold}), ('Report debug-level system messages and generate diagnostic output.', - ['--debug'], {'action': 'store_true'}), + ['--debug'], {'action': 'store_true', 'validator': validate_boolean}), ('Do not report debug-level system messages or generate diagnostic ' 'output.', ['--no-debug'], {'action': 'store_false', 'dest': 'debug'}), ('Send the output of system messages (warnings) to .', ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), ('Enable Python tracebacks when an error occurs.', - ['--traceback'], {'action': 'store_true', 'default': None}), + ['--traceback'], {'action': 'store_true', 'default': None, + 'validator': validate_boolean}), ('Disable Python tracebacks when errors occur; report just the error ' 'instead. This is the default.', ['--no-traceback'], {'dest': 'traceback', 'action': 'store_false'}), ('Specify the encoding of input text. Default is locale-dependent.', ['--input-encoding', '-i'], - {'action': 'callback', 'callback': set_encoding, - 'metavar': '', 'type': 'string', 'dest': 'input_encoding'}), + {'metavar': '', 'validator': validate_encoding}), ('Specify the text encoding for output. Default is UTF-8. ' 'Optionally also specify the encoding error handler for unencodable ' 'characters (see "--error-encoding"); default is "strict".', ['--output-encoding', '-o'], - {'action': 'callback', 'callback': set_encoding_and_error_handler, - 'metavar': '', 'type': 'string', - 'dest': 'output_encoding', 'default': 'utf-8'}), + {'metavar': '', 'default': 'utf-8', + 'validator': validate_encoding_and_error_handler}), (SUPPRESS_HELP, # usually handled by --output-encoding ['--output_encoding_error_handler'], - {'action': 'callback', 'callback': set_encoding_error_handler, - 'type': 'string', 'dest': 'output_encoding_error_handler', - 'default': 'strict'}), + {'default': 'strict', 'validator': validate_encoding_error_handler}), ('Specify the text encoding for error output. Default is ASCII. ' 'Optionally also specify the encoding error handler for unencodable ' 'characters, after a colon (":"). Acceptable values are the same ' 'as for the "error" parameter of Python\'s ``encode`` string ' 'method. Default is "%s".' % default_error_encoding_error_handler, ['--error-encoding', '-e'], - {'action': 'callback', 'callback': set_encoding_and_error_handler, - 'metavar': '', 'type': 'string', - 'dest': 'error_encoding', 'default': 'ascii'}), + {'metavar': '', 'default': 'ascii', + 'validator': validate_encoding_and_error_handler}), (SUPPRESS_HELP, # usually handled by --error-encoding ['--error_encoding_error_handler'], - {'action': 'callback', 'callback': set_encoding_error_handler, - 'type': 'string', 'dest': 'error_encoding_error_handler', - 'default': default_error_encoding_error_handler}), + {'default': default_error_encoding_error_handler, + 'validator': validate_encoding_error_handler}), ('Specify the language of input text (ISO 639 2-letter identifier).' ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', @@ -297,7 +360,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): (SUPPRESS_HELP, ['--dump-transforms'], {'action': 'store_true'}), (SUPPRESS_HELP, ['--dump-pseudo-xml'], {'action': 'store_true'}), (SUPPRESS_HELP, ['--expose-internal-attribute'], - {'action': 'append', 'dest': 'expose_internals'}),)) + {'action': 'append', 'dest': 'expose_internals', + 'validator': validate_colon_separated_string_list}),)) """Runtime settings and command-line options common to all Docutils front ends. Setting specs specific to individual Docutils components are also used (see `populate_from_components()`).""" @@ -319,8 +383,20 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ``.settings_spec`` attribute. `defaults` is a mapping of setting default overrides. """ + self.validators = {} + """{setting: validation function} mapping, used by `validate_options`. + Validation functions take three or five parameters: setting name, + value, an `OptionParser` (``self``), and a `ConfigParser` and config + file section if activated from a config file. They return a (possibly + modified) value, or raise an exception. Populated from the "validator" + keyword argument dictionary entries of components' ``settings_spec`` + attribute.""" + + self.lists = {} + """Set of list-type settings.""" + optparse.OptionParser.__init__( - self, add_help_option=None, + self, option_class=Option, add_help_option=None, formatter=optparse.TitledHelpFormatter(width=78), *args, **kwargs) if not self.version: @@ -331,7 +407,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): self.populate_from_components(self.components) defaults = defaults or {} if read_config_files and not self.defaults['_disable_config']: - config_settings = self.get_standard_config_settings() + try: + config_settings = self.get_standard_config_settings() + except ValueError, error: + self.error(error) defaults.update(config_settings) # Internal settings with no defaults from settings specifications; # initialize manually: @@ -359,8 +438,18 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): else: group = self # single options for (help_text, option_strings, kwargs) in option_spec: - group.add_option(help=help_text, *option_strings, - **kwargs) + kwargs = kwargs.copy() # to be modified, locally only + if kwargs.has_key('validator'): + validator = kwargs['validator'] + del kwargs['validator'] + else: + validator = None + option = group.add_option(help=help_text, *option_strings, + **kwargs) + if validator: + self.validators[option.dest] = validator + if kwargs.get('action') == 'append': + self.lists[option.dest] = 1 if component.settings_defaults: self.defaults.update(component.settings_defaults) i += 3 @@ -379,7 +468,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): parser.read(config_file, self) base_path = os.path.dirname(config_file) applied = {} - settings = {} + settings = DictUpdater(self) for component in self.components: if not component: continue @@ -390,30 +479,16 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): applied[section] = 1 settings.update(parser.get_section(section)) make_paths_absolute( - settings, self.relative_path_settings, base_path) - return settings + settings.data, self.relative_path_settings, base_path) + return settings.data def check_values(self, values, args): - if hasattr(values, 'report_level'): - values.report_level = self.check_threshold(values.report_level) - if hasattr(values, 'halt_level'): - values.halt_level = self.check_threshold(values.halt_level) - if hasattr(values, 'exit_level'): - values.exit_level = self.check_threshold(values.exit_level) + """Store positional arguments as runtime settings.""" values._source, values._destination = self.check_args(args) make_paths_absolute(values.__dict__, self.relative_path_settings, os.getcwd()) return values - def check_threshold(self, level): - try: - return int(level) - except ValueError: - try: - return self.thresholds[level.lower()] - except (KeyError, AttributeError): - self.error('Unknown threshold: %r.' % level) - def check_args(self, args): source = destination = None if args: @@ -434,17 +509,6 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): class ConfigParser(CP.ConfigParser): - validation = { - 'options': - {'input_encoding': validate_encoding, - 'output_encoding': validate_encoding, - 'output_encoding_error_handler': validate_encoding_error_handler, - 'error_encoding': validate_encoding, - 'error_encoding_error_handler': validate_encoding_error_handler}} - """{section: {option: validation function}} mapping, used by - `validate_options`. Validation functions take two parameters: name and - value. They return a (possibly modified) value, or raise an exception.""" - old_settings = { 'pep_stylesheet': ('pep_html writer', 'stylesheet'), 'pep_stylesheet_path': ('pep_html writer', 'stylesheet_path'), @@ -465,7 +529,7 @@ configuration files. See . CP.ConfigParser.read(self, filename) if self.has_section('options'): self.handle_old_config(filename) - self.validate_options(filename, option_parser) + self.validate_settings(filename, option_parser) def handle_old_config(self, filename): warnings.warn_explicit(self.old_warning, ConfigDeprecationWarning, @@ -485,23 +549,24 @@ configuration files. See . self.set(section, setting, value) self.remove_section('options') - def validate_options(self, filename, option_parser): - for section in self.validation.keys(): - if not self.has_section(section): - continue - for option in self.validation[section].keys(): - if self.has_option(section, option): - value = self.get(section, option) - validator = self.validation[section][option] + def validate_settings(self, filename, option_parser): + """Call the validator function on all applicable settings.""" + for section in self.sections(): + for setting in self.options(section): + validator = option_parser.validators.get(setting) + if validator: + value = self.get(section, setting, raw=1) try: - new_value = validator(option, value) + new_value = validator( + setting, value, option_parser, + config_parser=self, config_section=section) except Exception, error: raise (ValueError( 'Error in config file "%s", section "[%s]":\n' ' %s: %s\n %s = %s' % (filename, section, error.__class__.__name__, - error, option, value)), None, sys.exc_info()[2]) - self.set(section, option, new_value) + error, setting, value)), None, sys.exc_info()[2]) + self.set(section, setting, new_value) def optionxform(self, optionstr): """ @@ -509,25 +574,38 @@ configuration files. See . """ return optionstr.lower().replace('-', '_') - def get_section(self, section, raw=0, vars=None): + def get_section(self, section): """ Return a given section as a dictionary (empty if the section doesn't exist). - - All % interpolations are expanded in the return values, based on the - defaults passed into the constructor, unless the optional argument - `raw` is true. Additional substitutions may be provided using the - `vars` argument, which must be a dictionary whose contents overrides - any pre-existing defaults. - - The section DEFAULT is special. """ section_dict = {} if self.has_section(section): for option in self.options(section): - section_dict[option] = self.get(section, option, raw, vars) + section_dict[option] = self.get(section, option, raw=1) return section_dict class ConfigDeprecationWarning(DeprecationWarning): """Warning for deprecated configuration file features.""" + + +class DictUpdater: + + """ + Wraps a dict: updates list values by extension rather than by replacement. + Works in conjunction with the `OptionParser.lists` instance attribute. + """ + + def __init__(self, option_parser, data=None): + self.option_parser = option_parser + self.data = copy.deepcopy(data or {}) + + def update(self, other): + other = other.copy() + for setting in self.option_parser.lists: + if (self.data.has_key(setting) and self.data[setting] + and other.has_key(setting)): + self.data[setting] += other[setting] + del other[setting] + self.data.update(other) -- cgit v1.2.1 From badbd5efb84ea0fcfa2f51804ab7bf28cf69a11e Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 1 Sep 2003 21:09:15 +0000 Subject: Merged ``DictUpdater`` functionality into ``Values``, a subclass of ``optparse.Values``. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1667 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 59 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 091992bde..40c61c081 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -12,9 +12,8 @@ Exports the following classes: * `OptionParser`: Standard Docutils command-line processing. * `Option`: Customized version of `optparse.Option`; validation support. * `Values`: Runtime settings; objects are simple structs - (``object.attribute``). + (``object.attribute``). Supports cumulative list settings (attributes). * `ConfigParser`: Standard Docutils config file processing. -* `DictUpdater`: Supports cumulative list settings (dict values). Also exports the following functions: @@ -61,9 +60,7 @@ def read_config_file(option, opt, value, parser): new_settings = parser.get_config_file_settings(value) except ValueError, error: parser.error(error) - settings = DictUpdater(parser, parser.values.__dict__) - settings.update(new_settings) - parser.values._update_loose(settings.data) + parser.values.update(new_settings, parser) def validate_encoding(setting, value, option_parser, config_parser=None, config_section=None): @@ -170,6 +167,24 @@ def make_one_path_absolute(base_path, path): return os.path.abspath(os.path.join(base_path, path)) +class Values(optparse.Values): + + """ + Updates list attributes by extension rather than by replacement. + Works in conjunction with the `OptionParser.lists` instance attribute. + """ + + def update(self, other_dict, option_parser): + other_dict = other_dict.copy() + for setting in option_parser.lists: + if (hasattr(self, setting) and other_dict.has_key(setting)): + value = getattr(self, setting) + if value: + value += other_dict[setting] + del other_dict[setting] + self._update_loose(other_dict) + + class Option(optparse.Option): def process(self, opt, value, values, parser): @@ -464,11 +479,12 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): return settings def get_config_file_settings(self, config_file): + """Returns a dictionary containing appropriate config file settings.""" parser = ConfigParser() parser.read(config_file, self) base_path = os.path.dirname(config_file) applied = {} - settings = DictUpdater(self) + settings = Values() for component in self.components: if not component: continue @@ -477,10 +493,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): if applied.has_key(section): continue applied[section] = 1 - settings.update(parser.get_section(section)) + settings.update(parser.get_section(section), self) make_paths_absolute( - settings.data, self.relative_path_settings, base_path) - return settings.data + settings.__dict__, self.relative_path_settings, base_path) + return settings.__dict__ def check_values(self, values, args): """Store positional arguments as runtime settings.""" @@ -506,6 +522,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): 'destination. It will clobber the source file.') return source, destination + def get_default_values(self): + """Needed to get custom `Values` instances.""" + return Values(self.defaults) + class ConfigParser(CP.ConfigParser): @@ -588,24 +608,3 @@ configuration files. See . class ConfigDeprecationWarning(DeprecationWarning): """Warning for deprecated configuration file features.""" - - -class DictUpdater: - - """ - Wraps a dict: updates list values by extension rather than by replacement. - Works in conjunction with the `OptionParser.lists` instance attribute. - """ - - def __init__(self, option_parser, data=None): - self.option_parser = option_parser - self.data = copy.deepcopy(data or {}) - - def update(self, other): - other = other.copy() - for setting in self.option_parser.lists: - if (self.data.has_key(setting) and self.data[setting] - and other.has_key(setting)): - self.data[setting] += other[setting] - del other[setting] - self.data.update(other) -- cgit v1.2.1 From 88920f7db59954908fa82c9a39538f6c683666f9 Mon Sep 17 00:00:00 2001 From: cben Date: Thu, 11 Sep 2003 09:52:06 +0000 Subject: Added support for ``DOCUTILSCONFIG`` environment variable. Added method `OptionParser.get_config_files()` to allow overriding this behavior in a subclass. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1674 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 40c61c081..ef7dc5938 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -222,11 +222,11 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): """ standard_config_files = [ - '/etc/docutils.conf', # system-wide - './docutils.conf', # project-specific - os.path.expanduser('~/.docutils')] # user-specific - """Docutils configuration files, using ConfigParser syntax. - Later files override earlier ones.""" + '/etc/docutils.conf', # system-wide + './docutils.conf', # project-specific + '~/.docutils'] # user-specific + """Docutils configuration files, using ConfigParser syntax. Filenames + will be tilde-expanded later. Later files override earlier ones.""" threshold_choices = 'info 1 warning 2 error 3 severe 4 none 5'.split() """Possible inputs for for --report and --halt threshold values.""" @@ -472,7 +472,19 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): if component and component.settings_default_overrides: self.defaults.update(component.settings_default_overrides) + def get_config_files(self): + """Return list of config files, from environment or standard.""" + try: + config_files = os.environ['DOCUTILSCONFIG'] + if config_files == '': + return [] + else: + return config_files.split(os.pathsep) + except KeyError: + return self.standard_config_files + def get_standard_config_settings(self): + config_files = map(os.path.expanduser, self.get_config_files()) settings = {} for filename in self.standard_config_files: settings.update(self.get_config_file_settings(filename)) -- cgit v1.2.1 From 5261c45badb074fa23f7cad47808d96b572b717e Mon Sep 17 00:00:00 2001 From: cben Date: Thu, 11 Sep 2003 14:58:04 +0000 Subject: - Fixed stupid bug that made last change a no-op. - Explicitly made 'DOCUTILSCONFIG' ignore empty path items. - Refactored `test_settings.ConfigFileTests`: - Centralized reading of config files and combining of multiple setting dicts. - Subclassed with a class that runs the very same tests but sets `os.environ['DOCUTILSCONFIG']` instead of reading files directly. - Added test method that reads no files at all, for completeness. - Improved diff display in `compare_output` (order & trailing newlines). - Fixed bug in `test_old_and_new`: it used 'old' expected settings (which are surely the same as 'one') but read the 'one' config file. Assuming it's a cut-and-paste typo, changed to read 'one' file. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1675 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index ef7dc5938..e12449eaf 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -472,21 +472,19 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): if component and component.settings_default_overrides: self.defaults.update(component.settings_default_overrides) - def get_config_files(self): + def get_standard_config_files(self): """Return list of config files, from environment or standard.""" try: config_files = os.environ['DOCUTILSCONFIG'] - if config_files == '': - return [] - else: - return config_files.split(os.pathsep) + return [f for f in config_files.split(os.pathsep) if f != ''] except KeyError: return self.standard_config_files def get_standard_config_settings(self): - config_files = map(os.path.expanduser, self.get_config_files()) + config_files = map(os.path.expanduser, + self.get_standard_config_files()) settings = {} - for filename in self.standard_config_files: + for filename in config_files: settings.update(self.get_config_file_settings(filename)) return settings -- cgit v1.2.1 From ef69adb2f48763ddba3d0d6e6536ba16da78c04b Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 11 Sep 2003 22:42:59 +0000 Subject: simplified config file processing code git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1678 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index e12449eaf..f28333ce7 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -476,15 +476,14 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): """Return list of config files, from environment or standard.""" try: config_files = os.environ['DOCUTILSCONFIG'] - return [f for f in config_files.split(os.pathsep) if f != ''] except KeyError: - return self.standard_config_files + config_files = self.standard_config_files + return [os.path.expanduser(f) + for f in config_files.split(os.pathsep) if f.strip()] def get_standard_config_settings(self): - config_files = map(os.path.expanduser, - self.get_standard_config_files()) settings = {} - for filename in config_files: + for filename in self.get_standard_config_files(): settings.update(self.get_config_file_settings(filename)) return settings -- cgit v1.2.1 From 6d7dc5c949f7f42669203306a403d4d036d15362 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 11 Sep 2003 22:58:37 +0000 Subject: fixed bug git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1680 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index f28333ce7..fdfbacde7 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -475,11 +475,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): def get_standard_config_files(self): """Return list of config files, from environment or standard.""" try: - config_files = os.environ['DOCUTILSCONFIG'] + config_files = os.environ['DOCUTILSCONFIG'].split(os.pathsep) except KeyError: config_files = self.standard_config_files - return [os.path.expanduser(f) - for f in config_files.split(os.pathsep) if f.strip()] + return [os.path.expanduser(f) for f in config_files if f.strip()] def get_standard_config_settings(self): settings = {} -- cgit v1.2.1 From 277277b7cc17291c8149be895eb2d90524d304e9 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 12 Sep 2003 22:24:49 +0000 Subject: improved setting handling git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1682 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index fdfbacde7..1ab644531 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -175,6 +175,8 @@ class Values(optparse.Values): """ def update(self, other_dict, option_parser): + if isinstance(other_dict, Values): + other_dict = other_dict.__dict__ other_dict = other_dict.copy() for setting in option_parser.lists: if (hasattr(self, setting) and other_dict.has_key(setting)): @@ -426,7 +428,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): config_settings = self.get_standard_config_settings() except ValueError, error: self.error(error) - defaults.update(config_settings) + defaults.update(config_settings.__dict__) # Internal settings with no defaults from settings specifications; # initialize manually: self.set_defaults(_source=None, _destination=None, **defaults) @@ -481,9 +483,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): return [os.path.expanduser(f) for f in config_files if f.strip()] def get_standard_config_settings(self): - settings = {} + settings = Values() for filename in self.get_standard_config_files(): - settings.update(self.get_config_file_settings(filename)) + settings.update(self.get_config_file_settings(filename), self) return settings def get_config_file_settings(self, config_file): -- cgit v1.2.1 From e169be827f771c779b1cf97315af5f36c79482dc Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 13 Sep 2003 23:15:43 +0000 Subject: removed Python 2.2 feature git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1683 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 1ab644531..0a6fa8d84 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -553,7 +553,7 @@ configuration files. See . """ def read(self, filenames, option_parser): - if type(filenames) in types.StringTypes: + if type(filenames) in (types.StringType, types.UnicodeType): filenames = [filenames] for filename in filenames: CP.ConfigParser.read(self, filename) -- cgit v1.2.1 From a803d05c6c6121fe4ccdfa49068ef2971868503f Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 14 Sep 2003 00:01:38 +0000 Subject: removed another Python 2.2 feature git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1684 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 0a6fa8d84..5a52ff980 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -178,7 +178,7 @@ class Values(optparse.Values): if isinstance(other_dict, Values): other_dict = other_dict.__dict__ other_dict = other_dict.copy() - for setting in option_parser.lists: + for setting in option_parser.lists.keys(): if (hasattr(self, setting) and other_dict.has_key(setting)): value = getattr(self, setting) if value: -- cgit v1.2.1 From 899263f55439c95856d51e861e7008d7bddfe2b0 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 14 Nov 2003 15:04:54 +0000 Subject: updated config warning git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1739 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 5a52ff980..5267bcf84 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -548,8 +548,9 @@ class ConfigParser(CP.ConfigParser): old_warning = """ The "[option]" section is deprecated. Support for old-format configuration -files will be removed in a future Docutils release. Please revise your -configuration files. See . +files may be removed in a future Docutils release. Please revise your +configuration files. See , section +"Old-Format Configuration Files". """ def read(self, filenames, option_parser): -- cgit v1.2.1 From 101664a3673ff51de5ab0fe799e6c182ff25000f Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 30 Dec 2003 04:02:37 +0000 Subject: typos git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1784 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 5267bcf84..9066765d8 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -346,7 +346,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): {'metavar': '', 'default': 'utf-8', 'validator': validate_encoding_and_error_handler}), (SUPPRESS_HELP, # usually handled by --output-encoding - ['--output_encoding_error_handler'], + ['--output-encoding-error-handler'], {'default': 'strict', 'validator': validate_encoding_error_handler}), ('Specify the text encoding for error output. Default is ASCII. ' 'Optionally also specify the encoding error handler for unencodable ' @@ -357,7 +357,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): {'metavar': '', 'default': 'ascii', 'validator': validate_encoding_and_error_handler}), (SUPPRESS_HELP, # usually handled by --error-encoding - ['--error_encoding_error_handler'], + ['--error-encoding-error-handler'], {'default': default_error_encoding_error_handler, 'validator': validate_encoding_error_handler}), ('Specify the language of input text (ISO 639 2-letter identifier).' -- cgit v1.2.1 From 9899cfe846c05ad7669126b4939a6881e7f028e8 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 22 Jan 2004 20:55:19 +0000 Subject: bugfix git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1810 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 9066765d8..5523c947e 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -126,8 +126,7 @@ def validate_boolean(setting, value, option_parser, def validate_threshold(setting, value, option_parser, config_parser=None, config_section=None): try: - int(value) - return value + return int(value) except ValueError: try: return option_parser.thresholds[value.lower()] -- cgit v1.2.1 From 6126be3ca7e624ff208ac3b31de62116e6bc109a Mon Sep 17 00:00:00 2001 From: orutherfurd Date: Sun, 21 Mar 2004 22:33:36 +0000 Subject: added option to disable section numbering git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1849 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 5523c947e..f98f1bb4c 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -293,6 +293,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Disable backlinks from footnotes and citations.', ['--no-footnote-backlinks'], {'dest': 'footnote_backlinks', 'action': 'store_false'}), + ('Disable Docutils section numbering', + ['--disable-section-numbering'], + {'action': 'store_false', 'default': 1, + 'dest': 'enable_section_numbering', 'validator': validate_boolean}), ('Set verbosity threshold; report system messages at or higher than ' ' (by name or number: "info" or "1", warning/2, error/3, ' 'severe/4; also, "none" or "5"). Default is 2 (warning).', -- cgit v1.2.1 From 95d52aaa548180ccedcb40193ac258b61edc5c47 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 2 Apr 2004 02:29:26 +0000 Subject: changed name of setting & cmdline option for sectnum disabling; now conforms to other settings/options git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1902 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index f98f1bb4c..8b74ab00c 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -294,9 +294,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ['--no-footnote-backlinks'], {'dest': 'footnote_backlinks', 'action': 'store_false'}), ('Disable Docutils section numbering', - ['--disable-section-numbering'], - {'action': 'store_false', 'default': 1, - 'dest': 'enable_section_numbering', 'validator': validate_boolean}), + ['--no-section-numbering'], + {'action': 'store_false', 'dest': 'sectnum_xform', + 'default': 1, 'validator': validate_boolean}), ('Set verbosity threshold; report system messages at or higher than ' ' (by name or number: "info" or "1", warning/2, error/3, ' 'severe/4; also, "none" or "5"). Default is 2 (warning).', -- cgit v1.2.1 From 302da76e224a2fce05548bdebbd506d9d1a6bdad Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 12 May 2004 23:59:32 +0000 Subject: Added help text for --output-encoding-error-handler and --error-encoding-error-handler. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2091 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 8b74ab00c..48a58af69 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -344,22 +344,29 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): {'metavar': '', 'validator': validate_encoding}), ('Specify the text encoding for output. Default is UTF-8. ' 'Optionally also specify the encoding error handler for unencodable ' - 'characters (see "--error-encoding"); default is "strict".', + 'characters (see "--output-encoding-error-encoding"); ' + 'default is "strict".', ['--output-encoding', '-o'], {'metavar': '', 'default': 'utf-8', 'validator': validate_encoding_and_error_handler}), - (SUPPRESS_HELP, # usually handled by --output-encoding + ('Specify the encoding error handler for unencodable characters in ' + 'the output. Acceptable values include "strict", "ignore", ' + '"replace", "backslashreplace" (in Python 2.3+), and ' + '"xmlcharrefreplace" (in Python 2.3+). Default is "strict". ' + 'Usually specified as part of --output-encoding.', ['--output-encoding-error-handler'], {'default': 'strict', 'validator': validate_encoding_error_handler}), ('Specify the text encoding for error output. Default is ASCII. ' 'Optionally also specify the encoding error handler for unencodable ' - 'characters, after a colon (":"). Acceptable values are the same ' - 'as for the "error" parameter of Python\'s ``encode`` string ' - 'method. Default is "%s".' % default_error_encoding_error_handler, + 'characters, after a colon (":"). Default is "%s".' + % default_error_encoding_error_handler, ['--error-encoding', '-e'], {'metavar': '', 'default': 'ascii', 'validator': validate_encoding_and_error_handler}), - (SUPPRESS_HELP, # usually handled by --error-encoding + ('Specify the encoding error handler for unencodable characters in ' + 'error output. See --output-encoding-error-handler for acceptable ' + 'values. Default is "%s". Usually specified as part of ' + '--error-encoding.' % default_error_encoding_error_handler, ['--error-encoding-error-handler'], {'default': default_error_encoding_error_handler, 'validator': validate_encoding_error_handler}), -- cgit v1.2.1 From e63e9e1f758249afebcf545af3e4d73c208e8d29 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 13 May 2004 00:09:42 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2093 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 48a58af69..10716f568 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -343,13 +343,13 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ['--input-encoding', '-i'], {'metavar': '', 'validator': validate_encoding}), ('Specify the text encoding for output. Default is UTF-8. ' - 'Optionally also specify the encoding error handler for unencodable ' - 'characters (see "--output-encoding-error-encoding"); ' - 'default is "strict".', + 'Optionally also specify the error handler for unencodable ' + 'characters, after a colon (":"); default is "strict". (See ' + '"--output-encoding-error-encoding".)', ['--output-encoding', '-o'], {'metavar': '', 'default': 'utf-8', 'validator': validate_encoding_and_error_handler}), - ('Specify the encoding error handler for unencodable characters in ' + ('Specify the error handler for unencodable characters in ' 'the output. Acceptable values include "strict", "ignore", ' '"replace", "backslashreplace" (in Python 2.3+), and ' '"xmlcharrefreplace" (in Python 2.3+). Default is "strict". ' @@ -357,13 +357,14 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ['--output-encoding-error-handler'], {'default': 'strict', 'validator': validate_encoding_error_handler}), ('Specify the text encoding for error output. Default is ASCII. ' - 'Optionally also specify the encoding error handler for unencodable ' - 'characters, after a colon (":"). Default is "%s".' + 'Optionally also specify the error handler for unencodable ' + 'characters, after a colon (":"); default is "%s". (See ' + '"--output-encoding-error-encoding".' % default_error_encoding_error_handler, ['--error-encoding', '-e'], {'metavar': '', 'default': 'ascii', 'validator': validate_encoding_and_error_handler}), - ('Specify the encoding error handler for unencodable characters in ' + ('Specify the error handler for unencodable characters in ' 'error output. See --output-encoding-error-handler for acceptable ' 'values. Default is "%s". Usually specified as part of ' '--error-encoding.' % default_error_encoding_error_handler, -- cgit v1.2.1 From 79eef33c08e3c23042e76702ab41b51a4baf5f20 Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 31 May 2004 16:54:59 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2149 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 10716f568..b440954fb 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -311,8 +311,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ['--quiet', '-q'], {'action': 'store_const', 'const': 'none', 'dest': 'report_level'}), ('Set the threshold () at or above which system messages are ' - 'converted to exceptions, halting execution immediately. Levels ' - 'as in --report. Default is 4 (severe).', + 'converted to exceptions, halting execution immediately by ' + 'exiting (or propagating the exception if --traceback set). ' + 'Levels as in --report. Default is 4 (severe).', ['--halt'], {'choices': threshold_choices, 'dest': 'halt_level', 'default': 4, 'metavar': '', 'validator': validate_threshold}), @@ -333,7 +334,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ['--no-debug'], {'action': 'store_false', 'dest': 'debug'}), ('Send the output of system messages (warnings) to .', ['--warnings'], {'dest': 'warning_stream', 'metavar': ''}), - ('Enable Python tracebacks when an error occurs.', + ('Enable Python tracebacks when halt-level system messages and ' + 'other exceptions occur. Useful for debugging, and essential for ' + 'issue reports.', ['--traceback'], {'action': 'store_true', 'default': None, 'validator': validate_boolean}), ('Disable Python tracebacks when errors occur; report just the error ' -- cgit v1.2.1 From a9df7ccf4f6985faeee5f8f13b4f10a67381a761 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 3 Jun 2004 20:45:04 +0000 Subject: Renamed "--exit" to "--exit-status" git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2209 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index b440954fb..ecf7db0de 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -324,9 +324,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): 'system messages (at or above ) were generated. Levels as ' 'in --report. Default is 5 (disabled). Exit status is the maximum ' 'system message level plus 10 (11 for INFO, etc.).', - ['--exit'], {'choices': threshold_choices, 'dest': 'exit_level', - 'default': 5, 'metavar': '', - 'validator': validate_threshold}), + ['--exit-status'], {'choices': threshold_choices, + 'dest': 'exit_status_level', + 'default': 5, 'metavar': '', + 'validator': validate_threshold}), ('Report debug-level system messages and generate diagnostic output.', ['--debug'], {'action': 'store_true', 'validator': validate_boolean}), ('Do not report debug-level system messages or generate diagnostic ' -- cgit v1.2.1 From ae82315c489d8015f1c902bfed4df47ddb3b35a3 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 5 Jun 2004 19:55:24 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2225 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index ecf7db0de..5899fa856 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -564,8 +564,8 @@ class ConfigParser(CP.ConfigParser): old_warning = """ The "[option]" section is deprecated. Support for old-format configuration files may be removed in a future Docutils release. Please revise your -configuration files. See , section -"Old-Format Configuration Files". +configuration files. See , +section "Old-Format Configuration Files". """ def read(self, filenames, option_parser): -- cgit v1.2.1 From c48260665ecf74131830f99949da7b99b7579348 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 16 Jun 2004 17:21:57 +0000 Subject: added pep_base_url & rfc_base_url settings & support git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2287 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 5899fa856..1be10e396 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -143,6 +143,15 @@ def validate_colon_separated_string_list( value.extend(last.split(':')) return value +def validate_url_trailing_slash( + setting, value, option_parser, config_parser=None, config_section=None): + if not value: + return './' + elif value.endswith('/'): + return value + else: + return value + '/' + def make_paths_absolute(pathdict, keys, base_path=None): """ Interpret filesystem path settings relative to the `base_path` given. -- cgit v1.2.1 From 85038cc782dab0efabfb9cc8410d6e940cebe67d Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 25 Jun 2004 22:10:45 +0000 Subject: Simplified default-setting code git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2383 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 1be10e396..69a311d7b 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -407,7 +407,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ends. Setting specs specific to individual Docutils components are also used (see `populate_from_components()`).""" - settings_defaults = {'_disable_config': None} + settings_defaults = {'_disable_config': None, + '_source': None, + '_destination': None} """Defaults for settings that don't have command-line option equivalents.""" relative_path_settings = ('warning_stream',) @@ -446,16 +448,13 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): self.relative_path_settings = list(self.relative_path_settings) self.components = (self,) + tuple(components) self.populate_from_components(self.components) - defaults = defaults or {} + self.set_defaults(**(defaults or {})) if read_config_files and not self.defaults['_disable_config']: try: config_settings = self.get_standard_config_settings() except ValueError, error: self.error(error) - defaults.update(config_settings.__dict__) - # Internal settings with no defaults from settings specifications; - # initialize manually: - self.set_defaults(_source=None, _destination=None, **defaults) + self.set_defaults(**config_settings.__dict__) def populate_from_components(self, components): """ -- cgit v1.2.1 From 0e3448f831e078189422b8587baf0b864bd74175 Mon Sep 17 00:00:00 2001 From: cben Date: Fri, 9 Jul 2004 15:17:31 +0000 Subject: Trivial loop refactoring git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2425 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 69a311d7b..1d4d25166 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -43,7 +43,7 @@ from optparse import Values, SUPPRESS_HELP def store_multiple(option, opt, value, parser, *args, **kwargs): """ Store multiple values in `parser.values`. (Option callback.) - + Store `None` for each attribute named in `args`, and store the value for each key (attribute name) in `kwargs`. """ @@ -466,11 +466,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): for component in components: if component is None: continue - i = 0 settings_spec = component.settings_spec self.relative_path_settings.extend( component.relative_path_settings) - while i < len(settings_spec): + for i in range(0, len(settings_spec), 3): title, description, option_spec = settings_spec[i:i+3] if title: group = optparse.OptionGroup(self, title, description) @@ -492,7 +491,6 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): self.lists[option.dest] = 1 if component.settings_defaults: self.defaults.update(component.settings_defaults) - i += 3 for component in components: if component and component.settings_default_overrides: self.defaults.update(component.settings_default_overrides) -- cgit v1.2.1 From 1941d0dc7b6120c34640c8d6e089a1eca21a434b Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 24 Jul 2004 14:13:38 +0000 Subject: xmlcharrefreplace backport git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2446 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 1d4d25166..39678ba1d 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -77,10 +77,10 @@ def validate_encoding_error_handler(setting, value, option_parser, try: codecs.lookup_error(value) except AttributeError: # prior to Python 2.3 - if value not in ('strict', 'ignore', 'replace'): + if value not in ('strict', 'ignore', 'replace', 'xmlcharrefreplace'): raise (LookupError( 'unknown encoding error handler: "%s" (choices: ' - '"strict", "ignore", or "replace")' % value), + '"strict", "ignore", "replace", or "xmlcharrefreplace")' % value), None, sys.exc_info()[2]) except LookupError: raise (LookupError( @@ -364,8 +364,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): 'validator': validate_encoding_and_error_handler}), ('Specify the error handler for unencodable characters in ' 'the output. Acceptable values include "strict", "ignore", ' - '"replace", "backslashreplace" (in Python 2.3+), and ' - '"xmlcharrefreplace" (in Python 2.3+). Default is "strict". ' + '"replace", "xmlcharrefreplace", and ' + '"backslashreplace" (in Python 2.3+). Default is "strict". ' 'Usually specified as part of --output-encoding.', ['--output-encoding-error-handler'], {'default': 'strict', 'validator': validate_encoding_error_handler}), -- cgit v1.2.1 From 0ad035759fe1b762b46fc62b506cf04f000ea793 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 9 Sep 2004 21:20:09 +0000 Subject: typo git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2564 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 39678ba1d..4c6031c53 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -358,7 +358,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Specify the text encoding for output. Default is UTF-8. ' 'Optionally also specify the error handler for unencodable ' 'characters, after a colon (":"); default is "strict". (See ' - '"--output-encoding-error-encoding".)', + '"--output-encoding-error-handler".)', ['--output-encoding', '-o'], {'metavar': '', 'default': 'utf-8', 'validator': validate_encoding_and_error_handler}), @@ -372,7 +372,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Specify the text encoding for error output. Default is ASCII. ' 'Optionally also specify the error handler for unencodable ' 'characters, after a colon (":"); default is "%s". (See ' - '"--output-encoding-error-encoding".' + '"--output-encoding-error-handler".' % default_error_encoding_error_handler, ['--error-encoding', '-e'], {'metavar': '', 'default': 'ascii', @@ -637,6 +637,22 @@ section "Old-Format Configuration Files". section_dict[option] = self.get(section, option, raw=1) return section_dict + def set(self, section, option, value): + """ + Set an option. + + Overrides stdlib ConfigParser's set() method to allow non-string + values. Required for compatibility with Python 2.4. + """ + if not section or section == CP.DEFAULTSECT: + sectdict = self._defaults + else: + try: + sectdict = self._sections[section] + except KeyError: + raise CP.NoSectionError(section) + sectdict[self.optionxform(option)] = value + class ConfigDeprecationWarning(DeprecationWarning): """Warning for deprecated configuration file features.""" -- cgit v1.2.1 From eeef0a2eac14f4833500709dd31ab28b36558914 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 9 Sep 2004 21:32:36 +0000 Subject: oops, open issue; didn't meant to check that in yet git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2565 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 4c6031c53..412a1b5ad 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -637,22 +637,6 @@ section "Old-Format Configuration Files". section_dict[option] = self.get(section, option, raw=1) return section_dict - def set(self, section, option, value): - """ - Set an option. - - Overrides stdlib ConfigParser's set() method to allow non-string - values. Required for compatibility with Python 2.4. - """ - if not section or section == CP.DEFAULTSECT: - sectdict = self._defaults - else: - try: - sectdict = self._sections[section] - except KeyError: - raise CP.NoSectionError(section) - sectdict[self.optionxform(option)] = value - class ConfigDeprecationWarning(DeprecationWarning): """Warning for deprecated configuration file features.""" -- cgit v1.2.1 From 2f3ac3cb4695c82cb36fc32bf88bfb9f22aca6ff Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 12 Sep 2004 21:14:54 +0000 Subject: Added --input-encoding-error-handler option & setting. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2589 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 412a1b5ad..87f3377fb 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -352,9 +352,19 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Disable Python tracebacks when errors occur; report just the error ' 'instead. This is the default.', ['--no-traceback'], {'dest': 'traceback', 'action': 'store_false'}), - ('Specify the encoding of input text. Default is locale-dependent.', + ('Specify the encoding of input text. Default is locale-dependent. ' + 'Optionally also specify the error handler for undecodable ' + 'characters, after a colon (":"); default is "strict". (See ' + '"--intput-encoding-error-handler".)', ['--input-encoding', '-i'], - {'metavar': '', 'validator': validate_encoding}), + {'metavar': '', + 'validator': validate_encoding_and_error_handler}), + ('Specify the error handler for undecodable characters in ' + 'the input. Acceptable values include "strict", "ignore", and ' + '"replace". Default is "strict". ' + 'Usually specified as part of --input-encoding.', + ['--input-encoding-error-handler'], + {'default': 'strict', 'validator': validate_encoding_error_handler}), ('Specify the text encoding for output. Default is UTF-8. ' 'Optionally also specify the error handler for unencodable ' 'characters, after a colon (":"); default is "strict". (See ' -- cgit v1.2.1 From 3bbdc469d515dbb723ed5ecd4e57fc854671ec62 Mon Sep 17 00:00:00 2001 From: wiemann Date: Fri, 17 Sep 2004 19:27:30 +0000 Subject: removed misleading import git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2616 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 87f3377fb..38dafd49d 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -37,7 +37,7 @@ import ConfigParser as CP import codecs import docutils import optparse -from optparse import Values, SUPPRESS_HELP +from optparse import SUPPRESS_HELP def store_multiple(option, opt, value, parser, *args, **kwargs): -- cgit v1.2.1 From a61a365d55b4c0f5cf01d4cf04652038537c93a4 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 18 Sep 2004 23:00:20 +0000 Subject: typo git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2620 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 38dafd49d..4dc6e0522 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -382,7 +382,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Specify the text encoding for error output. Default is ASCII. ' 'Optionally also specify the error handler for unencodable ' 'characters, after a colon (":"); default is "%s". (See ' - '"--output-encoding-error-handler".' + '"--output-encoding-error-handler".)' % default_error_encoding_error_handler, ['--error-encoding', '-e'], {'metavar': '', 'default': 'ascii', -- cgit v1.2.1 From 26e823e026f5b9be93d71437039d9b7eb3e0c76d Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 19 Sep 2004 00:34:03 +0000 Subject: added --dependency-file option git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2622 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 4dc6e0522..5f19453b6 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -152,6 +152,13 @@ def validate_url_trailing_slash( else: return value + '/' +def validate_dependency_file( + setting, value, option_parser, config_parser=None, config_section=None): + if value: + return open(value, 'w') + else: + return None + def make_paths_absolute(pathdict, keys, base_path=None): """ Interpret filesystem path settings relative to the `base_path` given. @@ -398,6 +405,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', 'metavar': ''}), + ('Write dependencies (caused e.g. by the include directive) to ' + '. Useful in conjunction with programs like make.', + ['--dependency-file'], + {'metavar': '', 'validator': validate_dependency_file}), ('Read configuration settings from , if it exists.', ['--config'], {'metavar': '', 'type': 'string', 'action': 'callback', 'callback': read_config_file}), -- cgit v1.2.1 From 24f9bd8c8b48555bf5509c5d40c4b3fbf2caefbd Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 19 Sep 2004 14:54:42 +0000 Subject: added 'overrides' attribute for options git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2628 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 5f19453b6..f3551e04d 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -204,9 +204,12 @@ class Values(optparse.Values): class Option(optparse.Option): + ATTRS = optparse.Option.ATTRS + ['overrides'] + def process(self, opt, value, values, parser): """ - Call the validator function on applicable settings. + Call the validator function on applicable settings and + evaluate the 'overrides' option. Extends `optparse.Option.process`. """ result = optparse.Option.process(self, opt, value, values, parser) @@ -223,6 +226,8 @@ class Option(optparse.Option): % (opt, error.__class__.__name__, error)), None, sys.exc_info()[2]) setattr(values, setting, new_value) + if self.overrides is not None: + setattr(values, self.overrides, None) return result -- cgit v1.2.1 From f14f658ca8686deaff7167b47fc84b79515509bf Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 19 Sep 2004 18:11:09 +0000 Subject: made 'validator' a normal keyword for options (just a cosmetic change) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2632 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index f3551e04d..78cd638cb 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -18,10 +18,10 @@ Exports the following classes: Also exports the following functions: * Option callbacks: `store_multiple`, `read_config_file`. -* Setting validators (see `OptionParser.validators`: `validate_encoding`, - `validate_encoding_error_handler`, `validate_encoding_and_error_handler`, - `validate_boolean`, `validate_threshold`, - `validate_colon_separated_string_list`. +* Setting validators: `validate_encoding`, + `validate_encoding_error_handler`, + `validate_encoding_and_error_handler`, `validate_boolean`, + `validate_threshold`, `validate_colon_separated_string_list`. * `make_paths_absolute`. """ @@ -204,7 +204,7 @@ class Values(optparse.Values): class Option(optparse.Option): - ATTRS = optparse.Option.ATTRS + ['overrides'] + ATTRS = optparse.Option.ATTRS + ['validator', 'overrides'] def process(self, opt, value, values, parser): """ @@ -215,18 +215,17 @@ class Option(optparse.Option): result = optparse.Option.process(self, opt, value, values, parser) setting = self.dest if setting: - value = getattr(values, setting) - validator = parser.validators.get(setting) - if validator: + if self.validator: + value = getattr(values, setting) try: - new_value = validator(setting, value, parser) + new_value = self.validator(setting, value, parser) except Exception, error: raise (optparse.OptionValueError( 'Error in option "%s":\n %s: %s' % (opt, error.__class__.__name__, error)), None, sys.exc_info()[2]) setattr(values, setting, new_value) - if self.overrides is not None: + if self.overrides: setattr(values, self.overrides, None) return result @@ -503,16 +502,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): else: group = self # single options for (help_text, option_strings, kwargs) in option_spec: - kwargs = kwargs.copy() # to be modified, locally only - if kwargs.has_key('validator'): - validator = kwargs['validator'] - del kwargs['validator'] - else: - validator = None option = group.add_option(help=help_text, *option_strings, **kwargs) - if validator: - self.validators[option.dest] = validator + if kwargs.get('validator'): + self.validators[option.dest] = kwargs['validator'] if kwargs.get('action') == 'append': self.lists[option.dest] = 1 if component.settings_defaults: -- cgit v1.2.1 From 26efe6977a67b9a3c373fe826bd6a96ac12e5640 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 21 Sep 2004 16:49:04 +0000 Subject: Added config file support for "overrides" setting parameter. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2639 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 78cd638cb..0b1af5da8 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -460,6 +460,11 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): keyword argument dictionary entries of components' ``settings_spec`` attribute.""" + self.overrides = {} + """{setting: overridden setting} mapping, used by `validate_options`. + The overridden setting is set to `None` when the key setting is + encountered.""" + self.lists = {} """Set of list-type settings.""" @@ -508,6 +513,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): self.validators[option.dest] = kwargs['validator'] if kwargs.get('action') == 'append': self.lists[option.dest] = 1 + if kwargs.get('overrides'): + self.overrides[option.dest] = kwargs['overrides'] if component.settings_defaults: self.defaults.update(component.settings_defaults) for component in components: @@ -621,7 +628,10 @@ section "Old-Format Configuration Files". self.remove_section('options') def validate_settings(self, filename, option_parser): - """Call the validator function on all applicable settings.""" + """ + Call the validator function and implement overrides on all applicable + settings. + """ for section in self.sections(): for setting in self.options(section): validator = option_parser.validators.get(setting) @@ -638,6 +648,9 @@ section "Old-Format Configuration Files". % (filename, section, error.__class__.__name__, error, setting, value)), None, sys.exc_info()[2]) self.set(section, setting, new_value) + override = option_parser.overrides.get(setting) + if override: + self.set(section, override, None) def optionxform(self, optionstr): """ -- cgit v1.2.1 From 94cc169e7c0806612a49326d79cd266e0a479ac0 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 25 Sep 2004 23:35:26 +0000 Subject: changed --dependency-file to --record-dependencies git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2645 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 0b1af5da8..2b984f50e 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -21,7 +21,8 @@ Also exports the following functions: * Setting validators: `validate_encoding`, `validate_encoding_error_handler`, `validate_encoding_and_error_handler`, `validate_boolean`, - `validate_threshold`, `validate_colon_separated_string_list`. + `validate_threshold`, `validate_colon_separated_string_list`, + `validate_dependency_file`. * `make_paths_absolute`. """ @@ -154,10 +155,10 @@ def validate_url_trailing_slash( def validate_dependency_file( setting, value, option_parser, config_parser=None, config_section=None): - if value: - return open(value, 'w') - else: - return None + try: + return docutils.utils.DependencyList(value) + except IOError: + return docutils.utils.DependencyList(None) def make_paths_absolute(pathdict, keys, base_path=None): """ @@ -189,6 +190,11 @@ class Values(optparse.Values): Works in conjunction with the `OptionParser.lists` instance attribute. """ + def __init__(self, *args, **kwargs): + optparse.Values.__init__(self, *args, **kwargs) + # Set up dependency list, in case it is needed. + self.record_dependencies = docutils.utils.DependencyList() + def update(self, other_dict, option_parser): if isinstance(other_dict, Values): other_dict = other_dict.__dict__ @@ -409,10 +415,11 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ' Default is "en" (English).', ['--language', '-l'], {'dest': 'language_code', 'default': 'en', 'metavar': ''}), - ('Write dependencies (caused e.g. by the include directive) to ' - '. Useful in conjunction with programs like make.', - ['--dependency-file'], - {'metavar': '', 'validator': validate_dependency_file}), + ('Write dependencies (caused e.g. by file inclusions) to ' + '. Useful in conjunction with programs like "make".', + ['--record-dependencies'], + {'dest': 'record_dependencies', 'metavar': '', + 'validator': validate_dependency_file}), ('Read configuration settings from , if it exists.', ['--config'], {'metavar': '', 'type': 'string', 'action': 'callback', 'callback': read_config_file}), -- cgit v1.2.1 From 3004c8ccb54f33f7f8a23d39cd9dcfaa746e9f49 Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 27 Sep 2004 15:47:44 +0000 Subject: added function to get option by destination git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2657 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 2b984f50e..980838776 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -590,6 +590,19 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): """Needed to get custom `Values` instances.""" return Values(self.defaults) + def get_option_by_dest(self, dest): + """ + Get an option by its dest. + + If you're supplying a dest which is shared by several options, + the behavior is undefined. + """ + for group in self.option_groups + [self]: + for option in group.option_list: + if option.dest == dest: + return option + raise KeyError('No option with dest == %r.' % dest) + class ConfigParser(CP.ConfigParser): -- cgit v1.2.1 From acc174f64afebaf6b72d3f0b113d5f3bfca75dbf Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 27 Sep 2004 16:26:05 +0000 Subject: removed OptionParser.validator and OptionParser.overrides dictionaries; use get_option_by_dest() instead; made documentation of get_option_by_dest() more precise git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2658 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 980838776..6e7d0e318 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -458,19 +458,6 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ``.settings_spec`` attribute. `defaults` is a mapping of setting default overrides. """ - self.validators = {} - """{setting: validation function} mapping, used by `validate_options`. - Validation functions take three or five parameters: setting name, - value, an `OptionParser` (``self``), and a `ConfigParser` and config - file section if activated from a config file. They return a (possibly - modified) value, or raise an exception. Populated from the "validator" - keyword argument dictionary entries of components' ``settings_spec`` - attribute.""" - - self.overrides = {} - """{setting: overridden setting} mapping, used by `validate_options`. - The overridden setting is set to `None` when the key setting is - encountered.""" self.lists = {} """Set of list-type settings.""" @@ -516,12 +503,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): for (help_text, option_strings, kwargs) in option_spec: option = group.add_option(help=help_text, *option_strings, **kwargs) - if kwargs.get('validator'): - self.validators[option.dest] = kwargs['validator'] if kwargs.get('action') == 'append': self.lists[option.dest] = 1 - if kwargs.get('overrides'): - self.overrides[option.dest] = kwargs['overrides'] if component.settings_defaults: self.defaults.update(component.settings_defaults) for component in components: @@ -595,7 +578,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): Get an option by its dest. If you're supplying a dest which is shared by several options, - the behavior is undefined. + it is undefined which option of those is returned. + + A KeyError is raised if there is no option with the supplied + dest. """ for group in self.option_groups + [self]: for option in group.option_list: @@ -654,11 +640,14 @@ section "Old-Format Configuration Files". """ for section in self.sections(): for setting in self.options(section): - validator = option_parser.validators.get(setting) - if validator: + try: + option = option_parser.get_option_by_dest(setting) + except KeyError: + continue + if option.validator: value = self.get(section, setting, raw=1) try: - new_value = validator( + new_value = option.validator( setting, value, option_parser, config_parser=self, config_section=section) except Exception, error: @@ -668,9 +657,8 @@ section "Old-Format Configuration Files". % (filename, section, error.__class__.__name__, error, setting, value)), None, sys.exc_info()[2]) self.set(section, setting, new_value) - override = option_parser.overrides.get(setting) - if override: - self.set(section, override, None) + if option.overrides: + self.set(section, option.overrides, None) def optionxform(self, optionstr): """ -- cgit v1.2.1 From 71458320a74f312ed4f3eedf7314de7c064581fe Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 30 Sep 2004 03:32:48 +0000 Subject: fixed "record_dependencies" default git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2674 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 6e7d0e318..922098896 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -192,8 +192,9 @@ class Values(optparse.Values): def __init__(self, *args, **kwargs): optparse.Values.__init__(self, *args, **kwargs) - # Set up dependency list, in case it is needed. - self.record_dependencies = docutils.utils.DependencyList() + if self.record_dependencies is None: + # Set up dependency list, in case it is needed. + self.record_dependencies = docutils.utils.DependencyList() def update(self, other_dict, option_parser): if isinstance(other_dict, Values): @@ -418,8 +419,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Write dependencies (caused e.g. by file inclusions) to ' '. Useful in conjunction with programs like "make".', ['--record-dependencies'], - {'dest': 'record_dependencies', 'metavar': '', - 'validator': validate_dependency_file}), + {'metavar': '', 'validator': validate_dependency_file, + 'default': None}), # default set in Values class ('Read configuration settings from , if it exists.', ['--config'], {'metavar': '', 'type': 'string', 'action': 'callback', 'callback': read_config_file}), -- cgit v1.2.1 From d1b246da31c77372e38ab3ece5275e07065be26b Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 30 Sep 2004 03:52:14 +0000 Subject: fixed last fix git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2675 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 922098896..ed20057d3 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -192,7 +192,8 @@ class Values(optparse.Values): def __init__(self, *args, **kwargs): optparse.Values.__init__(self, *args, **kwargs) - if self.record_dependencies is None: + if (not hasattr(self, 'record_dependencies') + or self.record_dependencies is None): # Set up dependency list, in case it is needed. self.record_dependencies = docutils.utils.DependencyList() -- cgit v1.2.1 From 2c70de7022257da3b6c9e2e9325cb08d14505b07 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 19 Oct 2004 23:29:44 +0000 Subject: added --strict-visitor option git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2723 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index ed20057d3..bf9b28303 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -436,7 +436,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): (SUPPRESS_HELP, ['--dump-pseudo-xml'], {'action': 'store_true'}), (SUPPRESS_HELP, ['--expose-internal-attribute'], {'action': 'append', 'dest': 'expose_internals', - 'validator': validate_colon_separated_string_list}),)) + 'validator': validate_colon_separated_string_list}), + (SUPPRESS_HELP, ['--strict-visitor'], {'action': 'store_true'}), + )) """Runtime settings and command-line options common to all Docutils front ends. Setting specs specific to individual Docutils components are also used (see `populate_from_components()`).""" -- cgit v1.2.1 From 72b76553d951db5e70365a7333f3a12cea8033e7 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 25 Dec 2004 15:34:06 +0000 Subject: made --verbose do what it's supposed to do git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2911 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index bf9b28303..01731c478 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -333,10 +333,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): 'validator': validate_threshold}), ('Report all system messages, info-level and higher. (Same as ' '"--report=info".)', - ['--verbose', '-v'], {'action': 'store_const', 'const': 'info', + ['--verbose', '-v'], {'action': 'store_const', 'const': 1, 'dest': 'report_level'}), ('Do not report any system messages. (Same as "--report=none".)', - ['--quiet', '-q'], {'action': 'store_const', 'const': 'none', + ['--quiet', '-q'], {'action': 'store_const', 'const': 5, 'dest': 'report_level'}), ('Set the threshold () at or above which system messages are ' 'converted to exceptions, halting execution immediately by ' -- cgit v1.2.1 From f1da7eb10858e31b6e69f96bf9c7f3e46801f50f Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 4 Apr 2005 17:05:37 +0000 Subject: added the "field_name_limit" setting, test & docs git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3164 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 01731c478..d84aa55f3 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -124,6 +124,13 @@ def validate_boolean(setting, value, option_parser, None, sys.exc_info()[2]) return value +def validate_nonnegative_int(setting, value, option_parser, + config_parser=None, config_section=None): + value = int(value) + if value < 0: + raise ValueError('negative value; must be positive or zero') + return value + def validate_threshold(setting, value, option_parser, config_parser=None, config_section=None): try: -- cgit v1.2.1 From 3600f164d1078d31b98a31f9dbd878b6e2b7bf11 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 21 May 2005 00:00:25 +0000 Subject: added --id-prefix and --auto-id-prefix options git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3358 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index d84aa55f3..7cba1706f 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -436,6 +436,9 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ['--version', '-V'], {'action': 'version'}), ('Show this help message and exit.', ['--help', '-h'], {'action': 'help'}), + # Typically not useful for non-programmatical use. + (SUPPRESS_HELP, ['--id-prefix'], {'default': ''}), + (SUPPRESS_HELP, ['--auto-id-prefix'], {'default': 'id'}), # Hidden options, for development use only: (SUPPRESS_HELP, ['--dump-settings'], {'action': 'store_true'}), (SUPPRESS_HELP, ['--dump-internals'], {'action': 'store_true'}), -- cgit v1.2.1 From c61ca0c471901af237277d5700c4c22b04e4d3d3 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 29 May 2005 19:22:10 +0000 Subject: added version suffix for snapshots git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3411 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 7cba1706f..39ca62b85 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -462,7 +462,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): config_section = 'general' - version_template = '%%prog (Docutils %s)' % docutils.__version__ + version_template = ('%%prog (Docutils %s%s)' + % (docutils.__version__, docutils.__version_suffix__)) """Default version message.""" def __init__(self, components=(), defaults=None, read_config_files=None, -- cgit v1.2.1 From 78ed5de20eb3c06ef02efd5710145321fc40596f Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 1 Jun 2005 14:44:50 +0000 Subject: docutils.__version_details__ renamed from .__version_suffix__ git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3417 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 39ca62b85..8a85133e7 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -462,8 +462,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): config_section = 'general' - version_template = ('%%prog (Docutils %s%s)' - % (docutils.__version__, docutils.__version_suffix__)) + version_template = ('%%prog (Docutils %s [%s])' + % (docutils.__version__, docutils.__version_details__)) """Default version message.""" def __init__(self, components=(), defaults=None, read_config_files=None, -- cgit v1.2.1 From 61075e34557635f6facec931b31da5ec3b04243c Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 9 Jun 2005 17:32:17 +0000 Subject: added "title" directive git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3455 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 8a85133e7..679a648be 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -282,7 +282,10 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): settings_spec = ( 'General Docutils Options', None, - (('Include a "Generated by Docutils" credit and link at the end ' + (('Specify the document title as metadata (not part of the document ' + 'body). Overrides a document-provided title. There is no default.', + ['--title'], {}), + ('Include a "Generated by Docutils" credit and link at the end ' 'of the document.', ['--generator', '-g'], {'action': 'store_true', 'validator': validate_boolean}), -- cgit v1.2.1 From d90d048247c7f3012414659a52078b6c8a89765f Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 19 Jun 2005 14:51:42 +0000 Subject: added deactivation of config file reading (for easier testing) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3511 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 679a648be..2fcf33e95 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -41,6 +41,9 @@ import optparse from optparse import SUPPRESS_HELP +_globally_deactivate_config_files = 0 +"""Deactivate reading of config files; for testing purposes.""" + def store_multiple(option, opt, value, parser, *args, **kwargs): """ Store multiple values in `parser.values`. (Option callback.) @@ -531,6 +534,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): def get_standard_config_files(self): """Return list of config files, from environment or standard.""" + if _globally_deactivate_config_files: + return [] try: config_files = os.environ['DOCUTILSCONFIG'].split(os.pathsep) except KeyError: -- cgit v1.2.1 From 4ed3edac78b63fbd77a12d9394040e420dea8ffb Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 20 Jun 2005 19:47:07 +0000 Subject: added docs about using _disable_config git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3539 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 2fcf33e95..284d18ce7 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -42,7 +42,9 @@ from optparse import SUPPRESS_HELP _globally_deactivate_config_files = 0 -"""Deactivate reading of config files; for testing purposes.""" +"""Deactivate reading of config files globally; for testing purposes. +Use _disable_config instead when calling Docutils programatically: +""" def store_multiple(option, opt, value, parser, *args, **kwargs): """ -- cgit v1.2.1 From 635da3c6831a67858695854d926776ec3fb0f6d5 Mon Sep 17 00:00:00 2001 From: wiemann Date: Wed, 22 Jun 2005 19:16:46 +0000 Subject: removed usage of "copy" module; test suite runs 1.6 seconds faster now git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3556 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 1 - 1 file changed, 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 284d18ce7..c74419d50 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -32,7 +32,6 @@ import os import os.path import sys import types -import copy import warnings import ConfigParser as CP import codecs -- cgit v1.2.1 From afb2adba710b0f21e9e2b03c1409807238eece6c Mon Sep 17 00:00:00 2001 From: wiemann Date: Thu, 23 Jun 2005 13:13:31 +0000 Subject: also support "optik" instead of optparse; thanks to patch of Debian package git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3566 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index c74419d50..a0b76c96e 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -36,8 +36,12 @@ import warnings import ConfigParser as CP import codecs import docutils -import optparse -from optparse import SUPPRESS_HELP +try: + import optparse + from optparse import SUPPRESS_HELP +except ImportError: + import optik as optparse + from optik import SUPPRESS_HELP _globally_deactivate_config_files = 0 -- cgit v1.2.1 From 25934f67bf5d516f1bcdb32cc4d770f5d479d6fc Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 23 Jun 2005 17:35:19 +0000 Subject: removed docutils.frontend._globally_deactivate_config_files (reverting much of rev. 3511), since it duplicates settings._disable_config functionality git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3567 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 7 ------- 1 file changed, 7 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index a0b76c96e..8f357ae4b 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -44,11 +44,6 @@ except ImportError: from optik import SUPPRESS_HELP -_globally_deactivate_config_files = 0 -"""Deactivate reading of config files globally; for testing purposes. -Use _disable_config instead when calling Docutils programatically: -""" - def store_multiple(option, opt, value, parser, *args, **kwargs): """ Store multiple values in `parser.values`. (Option callback.) @@ -539,8 +534,6 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): def get_standard_config_files(self): """Return list of config files, from environment or standard.""" - if _globally_deactivate_config_files: - return [] try: config_files = os.environ['DOCUTILSCONFIG'].split(os.pathsep) except KeyError: -- cgit v1.2.1 From fb247a2c98d8fffdca2a6ede5235f1b9e28a27ae Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 28 Jun 2005 13:49:10 +0000 Subject: Added ``_stylesheet_required`` internal setting, docutils.transforms.html.StylesheetCheck transform, docs, tests, and support. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3617 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 8f357ae4b..62037b5f7 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -461,7 +461,8 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): settings_defaults = {'_disable_config': None, '_source': None, - '_destination': None} + '_destination': None, + '_stylesheet_required': 1,} """Defaults for settings that don't have command-line option equivalents.""" relative_path_settings = ('warning_stream',) -- cgit v1.2.1 From 5c90ddc006b36818e727b4a42196a708b2a78a25 Mon Sep 17 00:00:00 2001 From: wiemann Date: Wed, 24 Aug 2005 21:33:21 +0000 Subject: made _stylesheet_required setting default to 0, activating it in the rst2html.py front-end tool git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3830 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 62037b5f7..b0e0048cd 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -461,8 +461,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): settings_defaults = {'_disable_config': None, '_source': None, - '_destination': None, - '_stylesheet_required': 1,} + '_destination': None,} """Defaults for settings that don't have command-line option equivalents.""" relative_path_settings = ('warning_stream',) -- cgit v1.2.1 From 954c213bb271a9a2b91e694c8fbf155925dd9f4e Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 15 Sep 2005 14:16:33 +0000 Subject: Added support for specifying runtime settings at the suite level git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3879 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index b0e0048cd..93506bce5 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -219,6 +219,10 @@ class Values(optparse.Values): del other_dict[setting] self._update_loose(other_dict) + def copy(self): + """Return a shallow copy of `self`.""" + return self.__class__(defaults=self.__dict__) + class Option(optparse.Option): -- cgit v1.2.1 From 118dd3d2aa36cf563590197e28830c1a905f9cd8 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 8 Dec 2005 04:43:13 +0000 Subject: merged branches/s5 changes r4011:4155 into trunk/docutils git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4156 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 93506bce5..43750c30c 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -338,10 +338,14 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ('Disable backlinks from footnotes and citations.', ['--no-footnote-backlinks'], {'dest': 'footnote_backlinks', 'action': 'store_false'}), - ('Disable Docutils section numbering', + ('Enable Docutils section numbering (default: enabled).', + ['--section-numbering'], + {'action': 'store_true', 'dest': 'sectnum_xform', + 'default': 1, 'validator': validate_boolean}), + ('Disable Docutils section numbering (default: enabled).', ['--no-section-numbering'], {'action': 'store_false', 'dest': 'sectnum_xform', - 'default': 1, 'validator': validate_boolean}), + 'validator': validate_boolean}), ('Set verbosity threshold; report system messages at or higher than ' ' (by name or number: "info" or "1", warning/2, error/3, ' 'severe/4; also, "none" or "5"). Default is 2 (warning).', -- cgit v1.2.1 From e329a521a11f62212d4504d25cb1a3c5c76dfc18 Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 12 Dec 2005 04:12:02 +0000 Subject: Added the universal.StripComments transform, the "strip_comments" setting, and the --strip-comments/--leave-comments options. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4183 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/frontend.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'docutils/frontend.py') diff --git a/docutils/frontend.py b/docutils/frontend.py index 43750c30c..46fcaab89 100644 --- a/docutils/frontend.py +++ b/docutils/frontend.py @@ -346,6 +346,15 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec): ['--no-section-numbering'], {'action': 'store_false', 'dest': 'sectnum_xform', 'validator': validate_boolean}), + ('Remove comment elements from the document tree ' + '(default: leave them).', + ['--strip-comments'], + {'action': 'store_true', 'validator': validate_boolean}), + ('Leave comment elements in the document tree ' + '(this is the default).', + ['--leave-comments'], + {'action': 'store_false', 'dest': 'strip_comments', + 'validator': validate_boolean}), ('Set verbosity threshold; report system messages at or higher than ' ' (by name or number: "info" or "1", warning/2, error/3, ' 'severe/4; also, "none" or "5"). Default is 2 (warning).', -- cgit v1.2.1