diff options
| author | ?ric Araujo <merwok@netwok.org> | 2010-08-16 02:47:21 +0200 |
|---|---|---|
| committer | ?ric Araujo <merwok@netwok.org> | 2010-08-16 02:47:21 +0200 |
| commit | c8290bf703033742eec0a620be200a4847e4c50a (patch) | |
| tree | 90c9d885796d6824862871782a69fe20c665e3d5 /src/distutils2 | |
| parent | 0050a5e28142cc3bdf75c76a18c27b67a7d46a48 (diff) | |
| download | disutils2-c8290bf703033742eec0a620be200a4847e4c50a.tar.gz | |
Kill methods that just do string replacement.
Inspiration taken from the short-lived distutils_refactor branch in
the Python Subversion sandbox by Anthony Baxter.
Diffstat (limited to 'src/distutils2')
| -rw-r--r-- | src/distutils2/dist.py | 13 | ||||
| -rw-r--r-- | src/distutils2/fancy_getopt.py | 15 |
2 files changed, 8 insertions, 20 deletions
diff --git a/src/distutils2/dist.py b/src/distutils2/dist.py index 65ce631..2f491ca 100644 --- a/src/distutils2/dist.py +++ b/src/distutils2/dist.py @@ -15,7 +15,7 @@ from ConfigParser import RawConfigParser from distutils2.errors import (DistutilsOptionError, DistutilsArgError, DistutilsModuleError, DistutilsClassError) -from distutils2.fancy_getopt import FancyGetopt, translate_longopt +from distutils2.fancy_getopt import FancyGetopt from distutils2.util import check_environ, strtobool, resolve_name from distutils2 import log from distutils2.metadata import DistributionMetadata @@ -115,8 +115,7 @@ Common commands: (see '--help-commands' for more) ('convert-2to3-doctests', None, "use 2to3 to convert doctests in seperate text files"), ] - display_option_names = map(lambda x: translate_longopt(x[0]), - display_options) + display_option_names = [x[0].replace('-', '_') for x in display_options] # negative options are options that exclude other options negative_opt = {'quiet': 'verbose'} @@ -452,6 +451,7 @@ Common commands: (see '--help-commands' for more) # for display options we return immediately if self.handle_display_options(option_order): return + while args: args = self._parse_command_opts(parser, args) if args is None: # user asked for help (and got it) @@ -557,7 +557,7 @@ Common commands: (see '--help-commands' for more) isinstance(cmd_class.help_options, list)): help_option_found = 0 for (help_option, short, desc, func) in cmd_class.help_options: - if hasattr(opts, parser.get_attr_name(help_option)): + if hasattr(opts, help_option.replace('-', '_')): help_option_found = 1 if hasattr(func, '__call__'): func() @@ -666,7 +666,7 @@ Common commands: (see '--help-commands' for more) for opt, val in option_order: if val and is_display_option.get(opt): - opt = translate_longopt(opt) + opt = opt.replace('-', '_') value = self.metadata[opt] if opt in ['keywords', 'platform']: print(','.join(value)) @@ -864,7 +864,8 @@ Common commands: (see '--help-commands' for more) log.debug(" %s = %s (from %s)" % (option, value, source)) try: - bool_opts = map(translate_longopt, command_obj.boolean_options) + bool_opts = [x.replace('-', '_') + for x in command_obj.boolean_options] except AttributeError: bool_opts = [] try: diff --git a/src/distutils2/fancy_getopt.py b/src/distutils2/fancy_getopt.py index fef85fc..304fb8a 100644 --- a/src/distutils2/fancy_getopt.py +++ b/src/distutils2/fancy_getopt.py @@ -106,12 +106,6 @@ class FancyGetopt(object): option with long name 'long_option'.""" return long_option in self.option_index - def get_attr_name (self, long_option): - """Translate long option name 'long_option' to the form it - has as an attribute of some object: ie., translate hyphens - to underscores.""" - return long_option.replace('-', '_') - def _check_alias_dict (self, aliases, what): assert isinstance(aliases, dict) for (alias, opt) in aliases.items(): @@ -217,7 +211,7 @@ class FancyGetopt(object): ("invalid long option name '%s' " + "(must be letters, numbers, hyphens only") % long - self.attr_name[long] = self.get_attr_name(long) + self.attr_name[long] = long.replace('-', '_') if short: self.short_opts.append(short) self.short2long[short[0]] = long @@ -462,13 +456,6 @@ def wrap_text (text, width): return lines -def translate_longopt(opt): - """Convert a long option name to a valid Python identifier by - changing "-" to "_". - """ - return opt.replace('-', '_') - - class OptionDummy(object): """Dummy class just used as a place to hold command-line option values as instance attributes.""" |
