]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/dist.py
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / distutils / dist.py
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/dist.py b/AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/dist.py
deleted file mode 100644 (file)
index 198beda..0000000
+++ /dev/null
@@ -1,1248 +0,0 @@
-"""distutils.dist\r
-\r
-Provides the Distribution class, which represents the module distribution\r
-being built/installed/distributed.\r
-"""\r
-\r
-__revision__ = "$Id$"\r
-\r
-import sys, os, re\r
-from email import message_from_file\r
-\r
-try:\r
-    import warnings\r
-except ImportError:\r
-    warnings = None\r
-\r
-from distutils.errors import (DistutilsOptionError, DistutilsArgError,\r
-                              DistutilsModuleError, DistutilsClassError)\r
-from distutils.fancy_getopt import FancyGetopt, translate_longopt\r
-from distutils.util import check_environ, strtobool, rfc822_escape\r
-from distutils import log\r
-from distutils.debug import DEBUG\r
-\r
-# Encoding used for the PKG-INFO files\r
-PKG_INFO_ENCODING = 'utf-8'\r
-\r
-# Regex to define acceptable Distutils command names.  This is not *quite*\r
-# the same as a Python NAME -- I don't allow leading underscores.  The fact\r
-# that they're very similar is no coincidence; the default naming scheme is\r
-# to look for a Python module named after the command.\r
-command_re = re.compile (r'^[a-zA-Z]([a-zA-Z0-9_]*)$')\r
-\r
-\r
-class Distribution:\r
-    """The core of the Distutils.  Most of the work hiding behind 'setup'\r
-    is really done within a Distribution instance, which farms the work out\r
-    to the Distutils commands specified on the command line.\r
-\r
-    Setup scripts will almost never instantiate Distribution directly,\r
-    unless the 'setup()' function is totally inadequate to their needs.\r
-    However, it is conceivable that a setup script might wish to subclass\r
-    Distribution for some specialized purpose, and then pass the subclass\r
-    to 'setup()' as the 'distclass' keyword argument.  If so, it is\r
-    necessary to respect the expectations that 'setup' has of Distribution.\r
-    See the code for 'setup()', in core.py, for details.\r
-    """\r
-\r
-\r
-    # 'global_options' describes the command-line options that may be\r
-    # supplied to the setup script prior to any actual commands.\r
-    # Eg. "./setup.py -n" or "./setup.py --quiet" both take advantage of\r
-    # these global options.  This list should be kept to a bare minimum,\r
-    # since every global option is also valid as a command option -- and we\r
-    # don't want to pollute the commands with too many options that they\r
-    # have minimal control over.\r
-    # The fourth entry for verbose means that it can be repeated.\r
-    global_options = [('verbose', 'v', "run verbosely (default)", 1),\r
-                      ('quiet', 'q', "run quietly (turns verbosity off)"),\r
-                      ('dry-run', 'n', "don't actually do anything"),\r
-                      ('help', 'h', "show detailed help message"),\r
-                      ('no-user-cfg', None,\r
-                       'ignore pydistutils.cfg in your home directory'),\r
-    ]\r
-\r
-    # 'common_usage' is a short (2-3 line) string describing the common\r
-    # usage of the setup script.\r
-    common_usage = """\\r
-Common commands: (see '--help-commands' for more)\r
-\r
-  setup.py build      will build the package underneath 'build/'\r
-  setup.py install    will install the package\r
-"""\r
-\r
-    # options that are not propagated to the commands\r
-    display_options = [\r
-        ('help-commands', None,\r
-         "list all available commands"),\r
-        ('name', None,\r
-         "print package name"),\r
-        ('version', 'V',\r
-         "print package version"),\r
-        ('fullname', None,\r
-         "print <package name>-<version>"),\r
-        ('author', None,\r
-         "print the author's name"),\r
-        ('author-email', None,\r
-         "print the author's email address"),\r
-        ('maintainer', None,\r
-         "print the maintainer's name"),\r
-        ('maintainer-email', None,\r
-         "print the maintainer's email address"),\r
-        ('contact', None,\r
-         "print the maintainer's name if known, else the author's"),\r
-        ('contact-email', None,\r
-         "print the maintainer's email address if known, else the author's"),\r
-        ('url', None,\r
-         "print the URL for this package"),\r
-        ('license', None,\r
-         "print the license of the package"),\r
-        ('licence', None,\r
-         "alias for --license"),\r
-        ('description', None,\r
-         "print the package description"),\r
-        ('long-description', None,\r
-         "print the long package description"),\r
-        ('platforms', None,\r
-         "print the list of platforms"),\r
-        ('classifiers', None,\r
-         "print the list of classifiers"),\r
-        ('keywords', None,\r
-         "print the list of keywords"),\r
-        ('provides', None,\r
-         "print the list of packages/modules provided"),\r
-        ('requires', None,\r
-         "print the list of packages/modules required"),\r
-        ('obsoletes', None,\r
-         "print the list of packages/modules made obsolete")\r
-        ]\r
-    display_option_names = map(lambda x: translate_longopt(x[0]),\r
-                               display_options)\r
-\r
-    # negative options are options that exclude other options\r
-    negative_opt = {'quiet': 'verbose'}\r
-\r
-\r
-    # -- Creation/initialization methods -------------------------------\r
-\r
-    def __init__ (self, attrs=None):\r
-        """Construct a new Distribution instance: initialize all the\r
-        attributes of a Distribution, and then use 'attrs' (a dictionary\r
-        mapping attribute names to values) to assign some of those\r
-        attributes their "real" values.  (Any attributes not mentioned in\r
-        'attrs' will be assigned to some null value: 0, None, an empty list\r
-        or dictionary, etc.)  Most importantly, initialize the\r
-        'command_obj' attribute to the empty dictionary; this will be\r
-        filled in with real command objects by 'parse_command_line()'.\r
-        """\r
-\r
-        # Default values for our command-line options\r
-        self.verbose = 1\r
-        self.dry_run = 0\r
-        self.help = 0\r
-        for attr in self.display_option_names:\r
-            setattr(self, attr, 0)\r
-\r
-        # Store the distribution meta-data (name, version, author, and so\r
-        # forth) in a separate object -- we're getting to have enough\r
-        # information here (and enough command-line options) that it's\r
-        # worth it.  Also delegate 'get_XXX()' methods to the 'metadata'\r
-        # object in a sneaky and underhanded (but efficient!) way.\r
-        self.metadata = DistributionMetadata()\r
-        for basename in self.metadata._METHOD_BASENAMES:\r
-            method_name = "get_" + basename\r
-            setattr(self, method_name, getattr(self.metadata, method_name))\r
-\r
-        # 'cmdclass' maps command names to class objects, so we\r
-        # can 1) quickly figure out which class to instantiate when\r
-        # we need to create a new command object, and 2) have a way\r
-        # for the setup script to override command classes\r
-        self.cmdclass = {}\r
-\r
-        # 'command_packages' is a list of packages in which commands\r
-        # are searched for.  The factory for command 'foo' is expected\r
-        # to be named 'foo' in the module 'foo' in one of the packages\r
-        # named here.  This list is searched from the left; an error\r
-        # is raised if no named package provides the command being\r
-        # searched for.  (Always access using get_command_packages().)\r
-        self.command_packages = None\r
-\r
-        # 'script_name' and 'script_args' are usually set to sys.argv[0]\r
-        # and sys.argv[1:], but they can be overridden when the caller is\r
-        # not necessarily a setup script run from the command-line.\r
-        self.script_name = None\r
-        self.script_args = None\r
-\r
-        # 'command_options' is where we store command options between\r
-        # parsing them (from config files, the command-line, etc.) and when\r
-        # they are actually needed -- ie. when the command in question is\r
-        # instantiated.  It is a dictionary of dictionaries of 2-tuples:\r
-        #   command_options = { command_name : { option : (source, value) } }\r
-        self.command_options = {}\r
-\r
-        # 'dist_files' is the list of (command, pyversion, file) that\r
-        # have been created by any dist commands run so far. This is\r
-        # filled regardless of whether the run is dry or not. pyversion\r
-        # gives sysconfig.get_python_version() if the dist file is\r
-        # specific to a Python version, 'any' if it is good for all\r
-        # Python versions on the target platform, and '' for a source\r
-        # file. pyversion should not be used to specify minimum or\r
-        # maximum required Python versions; use the metainfo for that\r
-        # instead.\r
-        self.dist_files = []\r
-\r
-        # These options are really the business of various commands, rather\r
-        # than of the Distribution itself.  We provide aliases for them in\r
-        # Distribution as a convenience to the developer.\r
-        self.packages = None\r
-        self.package_data = {}\r
-        self.package_dir = None\r
-        self.py_modules = None\r
-        self.libraries = None\r
-        self.headers = None\r
-        self.ext_modules = None\r
-        self.ext_package = None\r
-        self.include_dirs = None\r
-        self.extra_path = None\r
-        self.scripts = None\r
-        self.data_files = None\r
-        self.password = ''\r
-\r
-        # And now initialize bookkeeping stuff that can't be supplied by\r
-        # the caller at all.  'command_obj' maps command names to\r
-        # Command instances -- that's how we enforce that every command\r
-        # class is a singleton.\r
-        self.command_obj = {}\r
-\r
-        # 'have_run' maps command names to boolean values; it keeps track\r
-        # of whether we have actually run a particular command, to make it\r
-        # cheap to "run" a command whenever we think we might need to -- if\r
-        # it's already been done, no need for expensive filesystem\r
-        # operations, we just check the 'have_run' dictionary and carry on.\r
-        # It's only safe to query 'have_run' for a command class that has\r
-        # been instantiated -- a false value will be inserted when the\r
-        # command object is created, and replaced with a true value when\r
-        # the command is successfully run.  Thus it's probably best to use\r
-        # '.get()' rather than a straight lookup.\r
-        self.have_run = {}\r
-\r
-        # Now we'll use the attrs dictionary (ultimately, keyword args from\r
-        # the setup script) to possibly override any or all of these\r
-        # distribution options.\r
-\r
-        if attrs:\r
-            # Pull out the set of command options and work on them\r
-            # specifically.  Note that this order guarantees that aliased\r
-            # command options will override any supplied redundantly\r
-            # through the general options dictionary.\r
-            options = attrs.get('options')\r
-            if options is not None:\r
-                del attrs['options']\r
-                for (command, cmd_options) in options.items():\r
-                    opt_dict = self.get_option_dict(command)\r
-                    for (opt, val) in cmd_options.items():\r
-                        opt_dict[opt] = ("setup script", val)\r
-\r
-            if 'licence' in attrs:\r
-                attrs['license'] = attrs['licence']\r
-                del attrs['licence']\r
-                msg = "'licence' distribution option is deprecated; use 'license'"\r
-                if warnings is not None:\r
-                    warnings.warn(msg)\r
-                else:\r
-                    sys.stderr.write(msg + "\n")\r
-\r
-            # Now work on the rest of the attributes.  Any attribute that's\r
-            # not already defined is invalid!\r
-            for (key, val) in attrs.items():\r
-                if hasattr(self.metadata, "set_" + key):\r
-                    getattr(self.metadata, "set_" + key)(val)\r
-                elif hasattr(self.metadata, key):\r
-                    setattr(self.metadata, key, val)\r
-                elif hasattr(self, key):\r
-                    setattr(self, key, val)\r
-                else:\r
-                    msg = "Unknown distribution option: %s" % repr(key)\r
-                    if warnings is not None:\r
-                        warnings.warn(msg)\r
-                    else:\r
-                        sys.stderr.write(msg + "\n")\r
-\r
-        # no-user-cfg is handled before other command line args\r
-        # because other args override the config files, and this\r
-        # one is needed before we can load the config files.\r
-        # If attrs['script_args'] wasn't passed, assume false.\r
-        #\r
-        # This also make sure we just look at the global options\r
-        self.want_user_cfg = True\r
-\r
-        if self.script_args is not None:\r
-            for arg in self.script_args:\r
-                if not arg.startswith('-'):\r
-                    break\r
-                if arg == '--no-user-cfg':\r
-                    self.want_user_cfg = False\r
-                    break\r
-\r
-        self.finalize_options()\r
-\r
-    def get_option_dict(self, command):\r
-        """Get the option dictionary for a given command.  If that\r
-        command's option dictionary hasn't been created yet, then create it\r
-        and return the new dictionary; otherwise, return the existing\r
-        option dictionary.\r
-        """\r
-        dict = self.command_options.get(command)\r
-        if dict is None:\r
-            dict = self.command_options[command] = {}\r
-        return dict\r
-\r
-    def dump_option_dicts(self, header=None, commands=None, indent=""):\r
-        from pprint import pformat\r
-\r
-        if commands is None:             # dump all command option dicts\r
-            commands = self.command_options.keys()\r
-            commands.sort()\r
-\r
-        if header is not None:\r
-            self.announce(indent + header)\r
-            indent = indent + "  "\r
-\r
-        if not commands:\r
-            self.announce(indent + "no commands known yet")\r
-            return\r
-\r
-        for cmd_name in commands:\r
-            opt_dict = self.command_options.get(cmd_name)\r
-            if opt_dict is None:\r
-                self.announce(indent +\r
-                              "no option dict for '%s' command" % cmd_name)\r
-            else:\r
-                self.announce(indent +\r
-                              "option dict for '%s' command:" % cmd_name)\r
-                out = pformat(opt_dict)\r
-                for line in out.split('\n'):\r
-                    self.announce(indent + "  " + line)\r
-\r
-    # -- Config file finding/parsing methods ---------------------------\r
-\r
-    def find_config_files(self):\r
-        """Find as many configuration files as should be processed for this\r
-        platform, and return a list of filenames in the order in which they\r
-        should be parsed.  The filenames returned are guaranteed to exist\r
-        (modulo nasty race conditions).\r
-\r
-        There are three possible config files: distutils.cfg in the\r
-        Distutils installation directory (ie. where the top-level\r
-        Distutils __inst__.py file lives), a file in the user's home\r
-        directory named .pydistutils.cfg on Unix and pydistutils.cfg\r
-        on Windows/Mac; and setup.cfg in the current directory.\r
-\r
-        The file in the user's home directory can be disabled with the\r
-        --no-user-cfg option.\r
-        """\r
-        files = []\r
-        check_environ()\r
-\r
-        # Where to look for the system-wide Distutils config file\r
-        sys_dir = os.path.dirname(sys.modules['distutils'].__file__)\r
-\r
-        # Look for the system config file\r
-        sys_file = os.path.join(sys_dir, "distutils.cfg")\r
-        if os.path.isfile(sys_file):\r
-            files.append(sys_file)\r
-\r
-        # What to call the per-user config file\r
-        if os.name == 'posix':\r
-            user_filename = ".pydistutils.cfg"\r
-        else:\r
-            user_filename = "pydistutils.cfg"\r
-\r
-        # And look for the user config file\r
-        if self.want_user_cfg:\r
-            user_file = os.path.join(os.path.expanduser('~'), user_filename)\r
-            if os.path.isfile(user_file):\r
-                files.append(user_file)\r
-\r
-        # All platforms support local setup.cfg\r
-        local_file = "setup.cfg"\r
-        if os.path.isfile(local_file):\r
-            files.append(local_file)\r
-\r
-        if DEBUG:\r
-            self.announce("using config files: %s" % ', '.join(files))\r
-\r
-        return files\r
-\r
-    def parse_config_files(self, filenames=None):\r
-        from ConfigParser import ConfigParser\r
-\r
-        if filenames is None:\r
-            filenames = self.find_config_files()\r
-\r
-        if DEBUG:\r
-            self.announce("Distribution.parse_config_files():")\r
-\r
-        parser = ConfigParser()\r
-        for filename in filenames:\r
-            if DEBUG:\r
-                self.announce("  reading %s" % filename)\r
-            parser.read(filename)\r
-            for section in parser.sections():\r
-                options = parser.options(section)\r
-                opt_dict = self.get_option_dict(section)\r
-\r
-                for opt in options:\r
-                    if opt != '__name__':\r
-                        val = parser.get(section,opt)\r
-                        opt = opt.replace('-', '_')\r
-                        opt_dict[opt] = (filename, val)\r
-\r
-            # Make the ConfigParser forget everything (so we retain\r
-            # the original filenames that options come from)\r
-            parser.__init__()\r
-\r
-        # If there was a "global" section in the config file, use it\r
-        # to set Distribution options.\r
-\r
-        if 'global' in self.command_options:\r
-            for (opt, (src, val)) in self.command_options['global'].items():\r
-                alias = self.negative_opt.get(opt)\r
-                try:\r
-                    if alias:\r
-                        setattr(self, alias, not strtobool(val))\r
-                    elif opt in ('verbose', 'dry_run'): # ugh!\r
-                        setattr(self, opt, strtobool(val))\r
-                    else:\r
-                        setattr(self, opt, val)\r
-                except ValueError, msg:\r
-                    raise DistutilsOptionError, msg\r
-\r
-    # -- Command-line parsing methods ----------------------------------\r
-\r
-    def parse_command_line(self):\r
-        """Parse the setup script's command line, taken from the\r
-        'script_args' instance attribute (which defaults to 'sys.argv[1:]'\r
-        -- see 'setup()' in core.py).  This list is first processed for\r
-        "global options" -- options that set attributes of the Distribution\r
-        instance.  Then, it is alternately scanned for Distutils commands\r
-        and options for that command.  Each new command terminates the\r
-        options for the previous command.  The allowed options for a\r
-        command are determined by the 'user_options' attribute of the\r
-        command class -- thus, we have to be able to load command classes\r
-        in order to parse the command line.  Any error in that 'options'\r
-        attribute raises DistutilsGetoptError; any error on the\r
-        command-line raises DistutilsArgError.  If no Distutils commands\r
-        were found on the command line, raises DistutilsArgError.  Return\r
-        true if command-line was successfully parsed and we should carry\r
-        on with executing commands; false if no errors but we shouldn't\r
-        execute commands (currently, this only happens if user asks for\r
-        help).\r
-        """\r
-        #\r
-        # We now have enough information to show the Macintosh dialog\r
-        # that allows the user to interactively specify the "command line".\r
-        #\r
-        toplevel_options = self._get_toplevel_options()\r
-\r
-        # We have to parse the command line a bit at a time -- global\r
-        # options, then the first command, then its options, and so on --\r
-        # because each command will be handled by a different class, and\r
-        # the options that are valid for a particular class aren't known\r
-        # until we have loaded the command class, which doesn't happen\r
-        # until we know what the command is.\r
-\r
-        self.commands = []\r
-        parser = FancyGetopt(toplevel_options + self.display_options)\r
-        parser.set_negative_aliases(self.negative_opt)\r
-        parser.set_aliases({'licence': 'license'})\r
-        args = parser.getopt(args=self.script_args, object=self)\r
-        option_order = parser.get_option_order()\r
-        log.set_verbosity(self.verbose)\r
-\r
-        # for display options we return immediately\r
-        if self.handle_display_options(option_order):\r
-            return\r
-        while args:\r
-            args = self._parse_command_opts(parser, args)\r
-            if args is None:            # user asked for help (and got it)\r
-                return\r
-\r
-        # Handle the cases of --help as a "global" option, ie.\r
-        # "setup.py --help" and "setup.py --help command ...".  For the\r
-        # former, we show global options (--verbose, --dry-run, etc.)\r
-        # and display-only options (--name, --version, etc.); for the\r
-        # latter, we omit the display-only options and show help for\r
-        # each command listed on the command line.\r
-        if self.help:\r
-            self._show_help(parser,\r
-                            display_options=len(self.commands) == 0,\r
-                            commands=self.commands)\r
-            return\r
-\r
-        # Oops, no commands found -- an end-user error\r
-        if not self.commands:\r
-            raise DistutilsArgError, "no commands supplied"\r
-\r
-        # All is well: return true\r
-        return 1\r
-\r
-    def _get_toplevel_options(self):\r
-        """Return the non-display options recognized at the top level.\r
-\r
-        This includes options that are recognized *only* at the top\r
-        level as well as options recognized for commands.\r
-        """\r
-        return self.global_options + [\r
-            ("command-packages=", None,\r
-             "list of packages that provide distutils commands"),\r
-            ]\r
-\r
-    def _parse_command_opts(self, parser, args):\r
-        """Parse the command-line options for a single command.\r
-        'parser' must be a FancyGetopt instance; 'args' must be the list\r
-        of arguments, starting with the current command (whose options\r
-        we are about to parse).  Returns a new version of 'args' with\r
-        the next command at the front of the list; will be the empty\r
-        list if there are no more commands on the command line.  Returns\r
-        None if the user asked for help on this command.\r
-        """\r
-        # late import because of mutual dependence between these modules\r
-        from distutils.cmd import Command\r
-\r
-        # Pull the current command from the head of the command line\r
-        command = args[0]\r
-        if not command_re.match(command):\r
-            raise SystemExit, "invalid command name '%s'" % command\r
-        self.commands.append(command)\r
-\r
-        # Dig up the command class that implements this command, so we\r
-        # 1) know that it's a valid command, and 2) know which options\r
-        # it takes.\r
-        try:\r
-            cmd_class = self.get_command_class(command)\r
-        except DistutilsModuleError, msg:\r
-            raise DistutilsArgError, msg\r
-\r
-        # Require that the command class be derived from Command -- want\r
-        # to be sure that the basic "command" interface is implemented.\r
-        if not issubclass(cmd_class, Command):\r
-            raise DistutilsClassError, \\r
-                  "command class %s must subclass Command" % cmd_class\r
-\r
-        # Also make sure that the command object provides a list of its\r
-        # known options.\r
-        if not (hasattr(cmd_class, 'user_options') and\r
-                isinstance(cmd_class.user_options, list)):\r
-            raise DistutilsClassError, \\r
-                  ("command class %s must provide " +\r
-                   "'user_options' attribute (a list of tuples)") % \\r
-                  cmd_class\r
-\r
-        # If the command class has a list of negative alias options,\r
-        # merge it in with the global negative aliases.\r
-        negative_opt = self.negative_opt\r
-        if hasattr(cmd_class, 'negative_opt'):\r
-            negative_opt = negative_opt.copy()\r
-            negative_opt.update(cmd_class.negative_opt)\r
-\r
-        # Check for help_options in command class.  They have a different\r
-        # format (tuple of four) so we need to preprocess them here.\r
-        if (hasattr(cmd_class, 'help_options') and\r
-            isinstance(cmd_class.help_options, list)):\r
-            help_options = fix_help_options(cmd_class.help_options)\r
-        else:\r
-            help_options = []\r
-\r
-\r
-        # All commands support the global options too, just by adding\r
-        # in 'global_options'.\r
-        parser.set_option_table(self.global_options +\r
-                                cmd_class.user_options +\r
-                                help_options)\r
-        parser.set_negative_aliases(negative_opt)\r
-        (args, opts) = parser.getopt(args[1:])\r
-        if hasattr(opts, 'help') and opts.help:\r
-            self._show_help(parser, display_options=0, commands=[cmd_class])\r
-            return\r
-\r
-        if (hasattr(cmd_class, 'help_options') and\r
-            isinstance(cmd_class.help_options, list)):\r
-            help_option_found=0\r
-            for (help_option, short, desc, func) in cmd_class.help_options:\r
-                if hasattr(opts, parser.get_attr_name(help_option)):\r
-                    help_option_found=1\r
-                    if hasattr(func, '__call__'):\r
-                        func()\r
-                    else:\r
-                        raise DistutilsClassError(\r
-                            "invalid help function %r for help option '%s': "\r
-                            "must be a callable object (function, etc.)"\r
-                            % (func, help_option))\r
-\r
-            if help_option_found:\r
-                return\r
-\r
-        # Put the options from the command-line into their official\r
-        # holding pen, the 'command_options' dictionary.\r
-        opt_dict = self.get_option_dict(command)\r
-        for (name, value) in vars(opts).items():\r
-            opt_dict[name] = ("command line", value)\r
-\r
-        return args\r
-\r
-    def finalize_options(self):\r
-        """Set final values for all the options on the Distribution\r
-        instance, analogous to the .finalize_options() method of Command\r
-        objects.\r
-        """\r
-        for attr in ('keywords', 'platforms'):\r
-            value = getattr(self.metadata, attr)\r
-            if value is None:\r
-                continue\r
-            if isinstance(value, str):\r
-                value = [elm.strip() for elm in value.split(',')]\r
-                setattr(self.metadata, attr, value)\r
-\r
-    def _show_help(self, parser, global_options=1, display_options=1,\r
-                   commands=[]):\r
-        """Show help for the setup script command-line in the form of\r
-        several lists of command-line options.  'parser' should be a\r
-        FancyGetopt instance; do not expect it to be returned in the\r
-        same state, as its option table will be reset to make it\r
-        generate the correct help text.\r
-\r
-        If 'global_options' is true, lists the global options:\r
-        --verbose, --dry-run, etc.  If 'display_options' is true, lists\r
-        the "display-only" options: --name, --version, etc.  Finally,\r
-        lists per-command help for every command name or command class\r
-        in 'commands'.\r
-        """\r
-        # late import because of mutual dependence between these modules\r
-        from distutils.core import gen_usage\r
-        from distutils.cmd import Command\r
-\r
-        if global_options:\r
-            if display_options:\r
-                options = self._get_toplevel_options()\r
-            else:\r
-                options = self.global_options\r
-            parser.set_option_table(options)\r
-            parser.print_help(self.common_usage + "\nGlobal options:")\r
-            print('')\r
-\r
-        if display_options:\r
-            parser.set_option_table(self.display_options)\r
-            parser.print_help(\r
-                "Information display options (just display " +\r
-                "information, ignore any commands)")\r
-            print('')\r
-\r
-        for command in self.commands:\r
-            if isinstance(command, type) and issubclass(command, Command):\r
-                klass = command\r
-            else:\r
-                klass = self.get_command_class(command)\r
-            if (hasattr(klass, 'help_options') and\r
-                isinstance(klass.help_options, list)):\r
-                parser.set_option_table(klass.user_options +\r
-                                        fix_help_options(klass.help_options))\r
-            else:\r
-                parser.set_option_table(klass.user_options)\r
-            parser.print_help("Options for '%s' command:" % klass.__name__)\r
-            print('')\r
-\r
-        print(gen_usage(self.script_name))\r
-\r
-    def handle_display_options(self, option_order):\r
-        """If there were any non-global "display-only" options\r
-        (--help-commands or the metadata display options) on the command\r
-        line, display the requested info and return true; else return\r
-        false.\r
-        """\r
-        from distutils.core import gen_usage\r
-\r
-        # User just wants a list of commands -- we'll print it out and stop\r
-        # processing now (ie. if they ran "setup --help-commands foo bar",\r
-        # we ignore "foo bar").\r
-        if self.help_commands:\r
-            self.print_commands()\r
-            print('')\r
-            print(gen_usage(self.script_name))\r
-            return 1\r
-\r
-        # If user supplied any of the "display metadata" options, then\r
-        # display that metadata in the order in which the user supplied the\r
-        # metadata options.\r
-        any_display_options = 0\r
-        is_display_option = {}\r
-        for option in self.display_options:\r
-            is_display_option[option[0]] = 1\r
-\r
-        for (opt, val) in option_order:\r
-            if val and is_display_option.get(opt):\r
-                opt = translate_longopt(opt)\r
-                value = getattr(self.metadata, "get_"+opt)()\r
-                if opt in ['keywords', 'platforms']:\r
-                    print(','.join(value))\r
-                elif opt in ('classifiers', 'provides', 'requires',\r
-                             'obsoletes'):\r
-                    print('\n'.join(value))\r
-                else:\r
-                    print(value)\r
-                any_display_options = 1\r
-\r
-        return any_display_options\r
-\r
-    def print_command_list(self, commands, header, max_length):\r
-        """Print a subset of the list of all commands -- used by\r
-        'print_commands()'.\r
-        """\r
-        print(header + ":")\r
-\r
-        for cmd in commands:\r
-            klass = self.cmdclass.get(cmd)\r
-            if not klass:\r
-                klass = self.get_command_class(cmd)\r
-            try:\r
-                description = klass.description\r
-            except AttributeError:\r
-                description = "(no description available)"\r
-\r
-            print("  %-*s  %s" % (max_length, cmd, description))\r
-\r
-    def print_commands(self):\r
-        """Print out a help message listing all available commands with a\r
-        description of each.  The list is divided into "standard commands"\r
-        (listed in distutils.command.__all__) and "extra commands"\r
-        (mentioned in self.cmdclass, but not a standard command).  The\r
-        descriptions come from the command class attribute\r
-        'description'.\r
-        """\r
-        import distutils.command\r
-        std_commands = distutils.command.__all__\r
-        is_std = {}\r
-        for cmd in std_commands:\r
-            is_std[cmd] = 1\r
-\r
-        extra_commands = []\r
-        for cmd in self.cmdclass.keys():\r
-            if not is_std.get(cmd):\r
-                extra_commands.append(cmd)\r
-\r
-        max_length = 0\r
-        for cmd in (std_commands + extra_commands):\r
-            if len(cmd) > max_length:\r
-                max_length = len(cmd)\r
-\r
-        self.print_command_list(std_commands,\r
-                                "Standard commands",\r
-                                max_length)\r
-        if extra_commands:\r
-            print\r
-            self.print_command_list(extra_commands,\r
-                                    "Extra commands",\r
-                                    max_length)\r
-\r
-    def get_command_list(self):\r
-        """Get a list of (command, description) tuples.\r
-        The list is divided into "standard commands" (listed in\r
-        distutils.command.__all__) and "extra commands" (mentioned in\r
-        self.cmdclass, but not a standard command).  The descriptions come\r
-        from the command class attribute 'description'.\r
-        """\r
-        # Currently this is only used on Mac OS, for the Mac-only GUI\r
-        # Distutils interface (by Jack Jansen)\r
-\r
-        import distutils.command\r
-        std_commands = distutils.command.__all__\r
-        is_std = {}\r
-        for cmd in std_commands:\r
-            is_std[cmd] = 1\r
-\r
-        extra_commands = []\r
-        for cmd in self.cmdclass.keys():\r
-            if not is_std.get(cmd):\r
-                extra_commands.append(cmd)\r
-\r
-        rv = []\r
-        for cmd in (std_commands + extra_commands):\r
-            klass = self.cmdclass.get(cmd)\r
-            if not klass:\r
-                klass = self.get_command_class(cmd)\r
-            try:\r
-                description = klass.description\r
-            except AttributeError:\r
-                description = "(no description available)"\r
-            rv.append((cmd, description))\r
-        return rv\r
-\r
-    # -- Command class/object methods ----------------------------------\r
-\r
-    def get_command_packages(self):\r
-        """Return a list of packages from which commands are loaded."""\r
-        pkgs = self.command_packages\r
-        if not isinstance(pkgs, list):\r
-            if pkgs is None:\r
-                pkgs = ''\r
-            pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']\r
-            if "distutils.command" not in pkgs:\r
-                pkgs.insert(0, "distutils.command")\r
-            self.command_packages = pkgs\r
-        return pkgs\r
-\r
-    def get_command_class(self, command):\r
-        """Return the class that implements the Distutils command named by\r
-        'command'.  First we check the 'cmdclass' dictionary; if the\r
-        command is mentioned there, we fetch the class object from the\r
-        dictionary and return it.  Otherwise we load the command module\r
-        ("distutils.command." + command) and fetch the command class from\r
-        the module.  The loaded class is also stored in 'cmdclass'\r
-        to speed future calls to 'get_command_class()'.\r
-\r
-        Raises DistutilsModuleError if the expected module could not be\r
-        found, or if that module does not define the expected class.\r
-        """\r
-        klass = self.cmdclass.get(command)\r
-        if klass:\r
-            return klass\r
-\r
-        for pkgname in self.get_command_packages():\r
-            module_name = "%s.%s" % (pkgname, command)\r
-            klass_name = command\r
-\r
-            try:\r
-                __import__ (module_name)\r
-                module = sys.modules[module_name]\r
-            except ImportError:\r
-                continue\r
-\r
-            try:\r
-                klass = getattr(module, klass_name)\r
-            except AttributeError:\r
-                raise DistutilsModuleError, \\r
-                      "invalid command '%s' (no class '%s' in module '%s')" \\r
-                      % (command, klass_name, module_name)\r
-\r
-            self.cmdclass[command] = klass\r
-            return klass\r
-\r
-        raise DistutilsModuleError("invalid command '%s'" % command)\r
-\r
-\r
-    def get_command_obj(self, command, create=1):\r
-        """Return the command object for 'command'.  Normally this object\r
-        is cached on a previous call to 'get_command_obj()'; if no command\r
-        object for 'command' is in the cache, then we either create and\r
-        return it (if 'create' is true) or return None.\r
-        """\r
-        cmd_obj = self.command_obj.get(command)\r
-        if not cmd_obj and create:\r
-            if DEBUG:\r
-                self.announce("Distribution.get_command_obj(): " \\r
-                              "creating '%s' command object" % command)\r
-\r
-            klass = self.get_command_class(command)\r
-            cmd_obj = self.command_obj[command] = klass(self)\r
-            self.have_run[command] = 0\r
-\r
-            # Set any options that were supplied in config files\r
-            # or on the command line.  (NB. support for error\r
-            # reporting is lame here: any errors aren't reported\r
-            # until 'finalize_options()' is called, which means\r
-            # we won't report the source of the error.)\r
-            options = self.command_options.get(command)\r
-            if options:\r
-                self._set_command_options(cmd_obj, options)\r
-\r
-        return cmd_obj\r
-\r
-    def _set_command_options(self, command_obj, option_dict=None):\r
-        """Set the options for 'command_obj' from 'option_dict'.  Basically\r
-        this means copying elements of a dictionary ('option_dict') to\r
-        attributes of an instance ('command').\r
-\r
-        'command_obj' must be a Command instance.  If 'option_dict' is not\r
-        supplied, uses the standard option dictionary for this command\r
-        (from 'self.command_options').\r
-        """\r
-        command_name = command_obj.get_command_name()\r
-        if option_dict is None:\r
-            option_dict = self.get_option_dict(command_name)\r
-\r
-        if DEBUG:\r
-            self.announce("  setting options for '%s' command:" % command_name)\r
-        for (option, (source, value)) in option_dict.items():\r
-            if DEBUG:\r
-                self.announce("    %s = %s (from %s)" % (option, value,\r
-                                                         source))\r
-            try:\r
-                bool_opts = map(translate_longopt, command_obj.boolean_options)\r
-            except AttributeError:\r
-                bool_opts = []\r
-            try:\r
-                neg_opt = command_obj.negative_opt\r
-            except AttributeError:\r
-                neg_opt = {}\r
-\r
-            try:\r
-                is_string = isinstance(value, str)\r
-                if option in neg_opt and is_string:\r
-                    setattr(command_obj, neg_opt[option], not strtobool(value))\r
-                elif option in bool_opts and is_string:\r
-                    setattr(command_obj, option, strtobool(value))\r
-                elif hasattr(command_obj, option):\r
-                    setattr(command_obj, option, value)\r
-                else:\r
-                    raise DistutilsOptionError, \\r
-                          ("error in %s: command '%s' has no such option '%s'"\r
-                           % (source, command_name, option))\r
-            except ValueError, msg:\r
-                raise DistutilsOptionError, msg\r
-\r
-    def reinitialize_command(self, command, reinit_subcommands=0):\r
-        """Reinitializes a command to the state it was in when first\r
-        returned by 'get_command_obj()': ie., initialized but not yet\r
-        finalized.  This provides the opportunity to sneak option\r
-        values in programmatically, overriding or supplementing\r
-        user-supplied values from the config files and command line.\r
-        You'll have to re-finalize the command object (by calling\r
-        'finalize_options()' or 'ensure_finalized()') before using it for\r
-        real.\r
-\r
-        'command' should be a command name (string) or command object.  If\r
-        'reinit_subcommands' is true, also reinitializes the command's\r
-        sub-commands, as declared by the 'sub_commands' class attribute (if\r
-        it has one).  See the "install" command for an example.  Only\r
-        reinitializes the sub-commands that actually matter, ie. those\r
-        whose test predicates return true.\r
-\r
-        Returns the reinitialized command object.\r
-        """\r
-        from distutils.cmd import Command\r
-        if not isinstance(command, Command):\r
-            command_name = command\r
-            command = self.get_command_obj(command_name)\r
-        else:\r
-            command_name = command.get_command_name()\r
-\r
-        if not command.finalized:\r
-            return command\r
-        command.initialize_options()\r
-        command.finalized = 0\r
-        self.have_run[command_name] = 0\r
-        self._set_command_options(command)\r
-\r
-        if reinit_subcommands:\r
-            for sub in command.get_sub_commands():\r
-                self.reinitialize_command(sub, reinit_subcommands)\r
-\r
-        return command\r
-\r
-    # -- Methods that operate on the Distribution ----------------------\r
-\r
-    def announce(self, msg, level=log.INFO):\r
-        log.log(level, msg)\r
-\r
-    def run_commands(self):\r
-        """Run each command that was seen on the setup script command line.\r
-        Uses the list of commands found and cache of command objects\r
-        created by 'get_command_obj()'.\r
-        """\r
-        for cmd in self.commands:\r
-            self.run_command(cmd)\r
-\r
-    # -- Methods that operate on its Commands --------------------------\r
-\r
-    def run_command(self, command):\r
-        """Do whatever it takes to run a command (including nothing at all,\r
-        if the command has already been run).  Specifically: if we have\r
-        already created and run the command named by 'command', return\r
-        silently without doing anything.  If the command named by 'command'\r
-        doesn't even have a command object yet, create one.  Then invoke\r
-        'run()' on that command object (or an existing one).\r
-        """\r
-        # Already been here, done that? then return silently.\r
-        if self.have_run.get(command):\r
-            return\r
-\r
-        log.info("running %s", command)\r
-        cmd_obj = self.get_command_obj(command)\r
-        cmd_obj.ensure_finalized()\r
-        cmd_obj.run()\r
-        self.have_run[command] = 1\r
-\r
-\r
-    # -- Distribution query methods ------------------------------------\r
-\r
-    def has_pure_modules(self):\r
-        return len(self.packages or self.py_modules or []) > 0\r
-\r
-    def has_ext_modules(self):\r
-        return self.ext_modules and len(self.ext_modules) > 0\r
-\r
-    def has_c_libraries(self):\r
-        return self.libraries and len(self.libraries) > 0\r
-\r
-    def has_modules(self):\r
-        return self.has_pure_modules() or self.has_ext_modules()\r
-\r
-    def has_headers(self):\r
-        return self.headers and len(self.headers) > 0\r
-\r
-    def has_scripts(self):\r
-        return self.scripts and len(self.scripts) > 0\r
-\r
-    def has_data_files(self):\r
-        return self.data_files and len(self.data_files) > 0\r
-\r
-    def is_pure(self):\r
-        return (self.has_pure_modules() and\r
-                not self.has_ext_modules() and\r
-                not self.has_c_libraries())\r
-\r
-    # -- Metadata query methods ----------------------------------------\r
-\r
-    # If you're looking for 'get_name()', 'get_version()', and so forth,\r
-    # they are defined in a sneaky way: the constructor binds self.get_XXX\r
-    # to self.metadata.get_XXX.  The actual code is in the\r
-    # DistributionMetadata class, below.\r
-\r
-class DistributionMetadata:\r
-    """Dummy class to hold the distribution meta-data: name, version,\r
-    author, and so forth.\r
-    """\r
-\r
-    _METHOD_BASENAMES = ("name", "version", "author", "author_email",\r
-                         "maintainer", "maintainer_email", "url",\r
-                         "license", "description", "long_description",\r
-                         "keywords", "platforms", "fullname", "contact",\r
-                         "contact_email", "license", "classifiers",\r
-                         "download_url",\r
-                         # PEP 314\r
-                         "provides", "requires", "obsoletes",\r
-                         )\r
-\r
-    def __init__(self, path=None):\r
-        if path is not None:\r
-            self.read_pkg_file(open(path))\r
-        else:\r
-            self.name = None\r
-            self.version = None\r
-            self.author = None\r
-            self.author_email = None\r
-            self.maintainer = None\r
-            self.maintainer_email = None\r
-            self.url = None\r
-            self.license = None\r
-            self.description = None\r
-            self.long_description = None\r
-            self.keywords = None\r
-            self.platforms = None\r
-            self.classifiers = None\r
-            self.download_url = None\r
-            # PEP 314\r
-            self.provides = None\r
-            self.requires = None\r
-            self.obsoletes = None\r
-\r
-    def read_pkg_file(self, file):\r
-        """Reads the metadata values from a file object."""\r
-        msg = message_from_file(file)\r
-\r
-        def _read_field(name):\r
-            value = msg[name]\r
-            if value == 'UNKNOWN':\r
-                return None\r
-            return value\r
-\r
-        def _read_list(name):\r
-            values = msg.get_all(name, None)\r
-            if values == []:\r
-                return None\r
-            return values\r
-\r
-        metadata_version = msg['metadata-version']\r
-        self.name = _read_field('name')\r
-        self.version = _read_field('version')\r
-        self.description = _read_field('summary')\r
-        # we are filling author only.\r
-        self.author = _read_field('author')\r
-        self.maintainer = None\r
-        self.author_email = _read_field('author-email')\r
-        self.maintainer_email = None\r
-        self.url = _read_field('home-page')\r
-        self.license = _read_field('license')\r
-\r
-        if 'download-url' in msg:\r
-            self.download_url = _read_field('download-url')\r
-        else:\r
-            self.download_url = None\r
-\r
-        self.long_description = _read_field('description')\r
-        self.description = _read_field('summary')\r
-\r
-        if 'keywords' in msg:\r
-            self.keywords = _read_field('keywords').split(',')\r
-\r
-        self.platforms = _read_list('platform')\r
-        self.classifiers = _read_list('classifier')\r
-\r
-        # PEP 314 - these fields only exist in 1.1\r
-        if metadata_version == '1.1':\r
-            self.requires = _read_list('requires')\r
-            self.provides = _read_list('provides')\r
-            self.obsoletes = _read_list('obsoletes')\r
-        else:\r
-            self.requires = None\r
-            self.provides = None\r
-            self.obsoletes = None\r
-\r
-    def write_pkg_info(self, base_dir):\r
-        """Write the PKG-INFO file into the release tree.\r
-        """\r
-        pkg_info = open(os.path.join(base_dir, 'PKG-INFO'), 'w')\r
-        try:\r
-            self.write_pkg_file(pkg_info)\r
-        finally:\r
-            pkg_info.close()\r
-\r
-    def write_pkg_file(self, file):\r
-        """Write the PKG-INFO format data to a file object.\r
-        """\r
-        version = '1.0'\r
-        if self.provides or self.requires or self.obsoletes:\r
-            version = '1.1'\r
-\r
-        self._write_field(file, 'Metadata-Version', version)\r
-        self._write_field(file, 'Name', self.get_name())\r
-        self._write_field(file, 'Version', self.get_version())\r
-        self._write_field(file, 'Summary', self.get_description())\r
-        self._write_field(file, 'Home-page', self.get_url())\r
-        self._write_field(file, 'Author', self.get_contact())\r
-        self._write_field(file, 'Author-email', self.get_contact_email())\r
-        self._write_field(file, 'License', self.get_license())\r
-        if self.download_url:\r
-            self._write_field(file, 'Download-URL', self.download_url)\r
-\r
-        long_desc = rfc822_escape(self.get_long_description())\r
-        self._write_field(file, 'Description', long_desc)\r
-\r
-        keywords = ','.join(self.get_keywords())\r
-        if keywords:\r
-            self._write_field(file, 'Keywords', keywords)\r
-\r
-        self._write_list(file, 'Platform', self.get_platforms())\r
-        self._write_list(file, 'Classifier', self.get_classifiers())\r
-\r
-        # PEP 314\r
-        self._write_list(file, 'Requires', self.get_requires())\r
-        self._write_list(file, 'Provides', self.get_provides())\r
-        self._write_list(file, 'Obsoletes', self.get_obsoletes())\r
-\r
-    def _write_field(self, file, name, value):\r
-        file.write('%s: %s\n' % (name, self._encode_field(value)))\r
-\r
-    def _write_list (self, file, name, values):\r
-        for value in values:\r
-            self._write_field(file, name, value)\r
-\r
-    def _encode_field(self, value):\r
-        if value is None:\r
-            return None\r
-        if isinstance(value, unicode):\r
-            return value.encode(PKG_INFO_ENCODING)\r
-        return str(value)\r
-\r
-    # -- Metadata query methods ----------------------------------------\r
-\r
-    def get_name(self):\r
-        return self.name or "UNKNOWN"\r
-\r
-    def get_version(self):\r
-        return self.version or "0.0.0"\r
-\r
-    def get_fullname(self):\r
-        return "%s-%s" % (self.get_name(), self.get_version())\r
-\r
-    def get_author(self):\r
-        return self._encode_field(self.author) or "UNKNOWN"\r
-\r
-    def get_author_email(self):\r
-        return self.author_email or "UNKNOWN"\r
-\r
-    def get_maintainer(self):\r
-        return self._encode_field(self.maintainer) or "UNKNOWN"\r
-\r
-    def get_maintainer_email(self):\r
-        return self.maintainer_email or "UNKNOWN"\r
-\r
-    def get_contact(self):\r
-        return (self._encode_field(self.maintainer) or\r
-                self._encode_field(self.author) or "UNKNOWN")\r
-\r
-    def get_contact_email(self):\r
-        return self.maintainer_email or self.author_email or "UNKNOWN"\r
-\r
-    def get_url(self):\r
-        return self.url or "UNKNOWN"\r
-\r
-    def get_license(self):\r
-        return self.license or "UNKNOWN"\r
-    get_licence = get_license\r
-\r
-    def get_description(self):\r
-        return self._encode_field(self.description) or "UNKNOWN"\r
-\r
-    def get_long_description(self):\r
-        return self._encode_field(self.long_description) or "UNKNOWN"\r
-\r
-    def get_keywords(self):\r
-        return self.keywords or []\r
-\r
-    def get_platforms(self):\r
-        return self.platforms or ["UNKNOWN"]\r
-\r
-    def get_classifiers(self):\r
-        return self.classifiers or []\r
-\r
-    def get_download_url(self):\r
-        return self.download_url or "UNKNOWN"\r
-\r
-    # PEP 314\r
-    def get_requires(self):\r
-        return self.requires or []\r
-\r
-    def set_requires(self, value):\r
-        import distutils.versionpredicate\r
-        for v in value:\r
-            distutils.versionpredicate.VersionPredicate(v)\r
-        self.requires = value\r
-\r
-    def get_provides(self):\r
-        return self.provides or []\r
-\r
-    def set_provides(self, value):\r
-        value = [v.strip() for v in value]\r
-        for v in value:\r
-            import distutils.versionpredicate\r
-            distutils.versionpredicate.split_provision(v)\r
-        self.provides = value\r
-\r
-    def get_obsoletes(self):\r
-        return self.obsoletes or []\r
-\r
-    def set_obsoletes(self, value):\r
-        import distutils.versionpredicate\r
-        for v in value:\r
-            distutils.versionpredicate.VersionPredicate(v)\r
-        self.obsoletes = value\r
-\r
-def fix_help_options(options):\r
-    """Convert a 4-tuple 'help_options' list as found in various command\r
-    classes to the 3-tuple form required by FancyGetopt.\r
-    """\r
-    new_options = []\r
-    for help_tuple in options:\r
-        new_options.append(help_tuple[0:3])\r
-    return new_options\r