]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/cmd.py
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / distutils / cmd.py
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/cmd.py b/AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/cmd.py
deleted file mode 100644 (file)
index ed7822a..0000000
+++ /dev/null
@@ -1,457 +0,0 @@
-"""distutils.cmd\r
-\r
-Provides the Command class, the base class for the command classes\r
-in the distutils.command package.\r
-"""\r
-\r
-__revision__ = "$Id$"\r
-\r
-import sys, os, re\r
-from distutils.errors import DistutilsOptionError\r
-from distutils import util, dir_util, file_util, archive_util, dep_util\r
-from distutils import log\r
-\r
-class Command:\r
-    """Abstract base class for defining command classes, the "worker bees"\r
-    of the Distutils.  A useful analogy for command classes is to think of\r
-    them as subroutines with local variables called "options".  The options\r
-    are "declared" in 'initialize_options()' and "defined" (given their\r
-    final values, aka "finalized") in 'finalize_options()', both of which\r
-    must be defined by every command class.  The distinction between the\r
-    two is necessary because option values might come from the outside\r
-    world (command line, config file, ...), and any options dependent on\r
-    other options must be computed *after* these outside influences have\r
-    been processed -- hence 'finalize_options()'.  The "body" of the\r
-    subroutine, where it does all its work based on the values of its\r
-    options, is the 'run()' method, which must also be implemented by every\r
-    command class.\r
-    """\r
-\r
-    # 'sub_commands' formalizes the notion of a "family" of commands,\r
-    # eg. "install" as the parent with sub-commands "install_lib",\r
-    # "install_headers", etc.  The parent of a family of commands\r
-    # defines 'sub_commands' as a class attribute; it's a list of\r
-    #    (command_name : string, predicate : unbound_method | string | None)\r
-    # tuples, where 'predicate' is a method of the parent command that\r
-    # determines whether the corresponding command is applicable in the\r
-    # current situation.  (Eg. we "install_headers" is only applicable if\r
-    # we have any C header files to install.)  If 'predicate' is None,\r
-    # that command is always applicable.\r
-    #\r
-    # 'sub_commands' is usually defined at the *end* of a class, because\r
-    # predicates can be unbound methods, so they must already have been\r
-    # defined.  The canonical example is the "install" command.\r
-    sub_commands = []\r
-\r
-\r
-    # -- Creation/initialization methods -------------------------------\r
-\r
-    def __init__(self, dist):\r
-        """Create and initialize a new Command object.  Most importantly,\r
-        invokes the 'initialize_options()' method, which is the real\r
-        initializer and depends on the actual command being\r
-        instantiated.\r
-        """\r
-        # late import because of mutual dependence between these classes\r
-        from distutils.dist import Distribution\r
-\r
-        if not isinstance(dist, Distribution):\r
-            raise TypeError, "dist must be a Distribution instance"\r
-        if self.__class__ is Command:\r
-            raise RuntimeError, "Command is an abstract class"\r
-\r
-        self.distribution = dist\r
-        self.initialize_options()\r
-\r
-        # Per-command versions of the global flags, so that the user can\r
-        # customize Distutils' behaviour command-by-command and let some\r
-        # commands fall back on the Distribution's behaviour.  None means\r
-        # "not defined, check self.distribution's copy", while 0 or 1 mean\r
-        # false and true (duh).  Note that this means figuring out the real\r
-        # value of each flag is a touch complicated -- hence "self._dry_run"\r
-        # will be handled by __getattr__, below.\r
-        # XXX This needs to be fixed.\r
-        self._dry_run = None\r
-\r
-        # verbose is largely ignored, but needs to be set for\r
-        # backwards compatibility (I think)?\r
-        self.verbose = dist.verbose\r
-\r
-        # Some commands define a 'self.force' option to ignore file\r
-        # timestamps, but methods defined *here* assume that\r
-        # 'self.force' exists for all commands.  So define it here\r
-        # just to be safe.\r
-        self.force = None\r
-\r
-        # The 'help' flag is just used for command-line parsing, so\r
-        # none of that complicated bureaucracy is needed.\r
-        self.help = 0\r
-\r
-        # 'finalized' records whether or not 'finalize_options()' has been\r
-        # called.  'finalize_options()' itself should not pay attention to\r
-        # this flag: it is the business of 'ensure_finalized()', which\r
-        # always calls 'finalize_options()', to respect/update it.\r
-        self.finalized = 0\r
-\r
-    # XXX A more explicit way to customize dry_run would be better.\r
-    def __getattr__(self, attr):\r
-        if attr == 'dry_run':\r
-            myval = getattr(self, "_" + attr)\r
-            if myval is None:\r
-                return getattr(self.distribution, attr)\r
-            else:\r
-                return myval\r
-        else:\r
-            raise AttributeError, attr\r
-\r
-    def ensure_finalized(self):\r
-        if not self.finalized:\r
-            self.finalize_options()\r
-        self.finalized = 1\r
-\r
-    # Subclasses must define:\r
-    #   initialize_options()\r
-    #     provide default values for all options; may be customized by\r
-    #     setup script, by options from config file(s), or by command-line\r
-    #     options\r
-    #   finalize_options()\r
-    #     decide on the final values for all options; this is called\r
-    #     after all possible intervention from the outside world\r
-    #     (command-line, option file, etc.) has been processed\r
-    #   run()\r
-    #     run the command: do whatever it is we're here to do,\r
-    #     controlled by the command's various option values\r
-\r
-    def initialize_options(self):\r
-        """Set default values for all the options that this command\r
-        supports.  Note that these defaults may be overridden by other\r
-        commands, by the setup script, by config files, or by the\r
-        command-line.  Thus, this is not the place to code dependencies\r
-        between options; generally, 'initialize_options()' implementations\r
-        are just a bunch of "self.foo = None" assignments.\r
-\r
-        This method must be implemented by all command classes.\r
-        """\r
-        raise RuntimeError, \\r
-              "abstract method -- subclass %s must override" % self.__class__\r
-\r
-    def finalize_options(self):\r
-        """Set final values for all the options that this command supports.\r
-        This is always called as late as possible, ie.  after any option\r
-        assignments from the command-line or from other commands have been\r
-        done.  Thus, this is the place to code option dependencies: if\r
-        'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as\r
-        long as 'foo' still has the same value it was assigned in\r
-        'initialize_options()'.\r
-\r
-        This method must be implemented by all command classes.\r
-        """\r
-        raise RuntimeError, \\r
-              "abstract method -- subclass %s must override" % self.__class__\r
-\r
-\r
-    def dump_options(self, header=None, indent=""):\r
-        from distutils.fancy_getopt import longopt_xlate\r
-        if header is None:\r
-            header = "command options for '%s':" % self.get_command_name()\r
-        self.announce(indent + header, level=log.INFO)\r
-        indent = indent + "  "\r
-        for (option, _, _) in self.user_options:\r
-            option = option.translate(longopt_xlate)\r
-            if option[-1] == "=":\r
-                option = option[:-1]\r
-            value = getattr(self, option)\r
-            self.announce(indent + "%s = %s" % (option, value),\r
-                          level=log.INFO)\r
-\r
-    def run(self):\r
-        """A command's raison d'etre: carry out the action it exists to\r
-        perform, controlled by the options initialized in\r
-        'initialize_options()', customized by other commands, the setup\r
-        script, the command-line, and config files, and finalized in\r
-        'finalize_options()'.  All terminal output and filesystem\r
-        interaction should be done by 'run()'.\r
-\r
-        This method must be implemented by all command classes.\r
-        """\r
-        raise RuntimeError, \\r
-              "abstract method -- subclass %s must override" % self.__class__\r
-\r
-    def announce(self, msg, level=1):\r
-        """If the current verbosity level is of greater than or equal to\r
-        'level' print 'msg' to stdout.\r
-        """\r
-        log.log(level, msg)\r
-\r
-    def debug_print(self, msg):\r
-        """Print 'msg' to stdout if the global DEBUG (taken from the\r
-        DISTUTILS_DEBUG environment variable) flag is true.\r
-        """\r
-        from distutils.debug import DEBUG\r
-        if DEBUG:\r
-            print msg\r
-            sys.stdout.flush()\r
-\r
-\r
-    # -- Option validation methods -------------------------------------\r
-    # (these are very handy in writing the 'finalize_options()' method)\r
-    #\r
-    # NB. the general philosophy here is to ensure that a particular option\r
-    # value meets certain type and value constraints.  If not, we try to\r
-    # force it into conformance (eg. if we expect a list but have a string,\r
-    # split the string on comma and/or whitespace).  If we can't force the\r
-    # option into conformance, raise DistutilsOptionError.  Thus, command\r
-    # classes need do nothing more than (eg.)\r
-    #   self.ensure_string_list('foo')\r
-    # and they can be guaranteed that thereafter, self.foo will be\r
-    # a list of strings.\r
-\r
-    def _ensure_stringlike(self, option, what, default=None):\r
-        val = getattr(self, option)\r
-        if val is None:\r
-            setattr(self, option, default)\r
-            return default\r
-        elif not isinstance(val, str):\r
-            raise DistutilsOptionError, \\r
-                  "'%s' must be a %s (got `%s`)" % (option, what, val)\r
-        return val\r
-\r
-    def ensure_string(self, option, default=None):\r
-        """Ensure that 'option' is a string; if not defined, set it to\r
-        'default'.\r
-        """\r
-        self._ensure_stringlike(option, "string", default)\r
-\r
-    def ensure_string_list(self, option):\r
-        """Ensure that 'option' is a list of strings.  If 'option' is\r
-        currently a string, we split it either on /,\s*/ or /\s+/, so\r
-        "foo bar baz", "foo,bar,baz", and "foo,   bar baz" all become\r
-        ["foo", "bar", "baz"].\r
-        """\r
-        val = getattr(self, option)\r
-        if val is None:\r
-            return\r
-        elif isinstance(val, str):\r
-            setattr(self, option, re.split(r',\s*|\s+', val))\r
-        else:\r
-            if isinstance(val, list):\r
-                # checks if all elements are str\r
-                ok = 1\r
-                for element in val:\r
-                    if not isinstance(element, str):\r
-                        ok = 0\r
-                        break\r
-            else:\r
-                ok = 0\r
-\r
-            if not ok:\r
-                raise DistutilsOptionError, \\r
-                    "'%s' must be a list of strings (got %r)" % \\r
-                        (option, val)\r
-\r
-\r
-    def _ensure_tested_string(self, option, tester,\r
-                              what, error_fmt, default=None):\r
-        val = self._ensure_stringlike(option, what, default)\r
-        if val is not None and not tester(val):\r
-            raise DistutilsOptionError, \\r
-                  ("error in '%s' option: " + error_fmt) % (option, val)\r
-\r
-    def ensure_filename(self, option):\r
-        """Ensure that 'option' is the name of an existing file."""\r
-        self._ensure_tested_string(option, os.path.isfile,\r
-                                   "filename",\r
-                                   "'%s' does not exist or is not a file")\r
-\r
-    def ensure_dirname(self, option):\r
-        self._ensure_tested_string(option, os.path.isdir,\r
-                                   "directory name",\r
-                                   "'%s' does not exist or is not a directory")\r
-\r
-\r
-    # -- Convenience methods for commands ------------------------------\r
-\r
-    def get_command_name(self):\r
-        if hasattr(self, 'command_name'):\r
-            return self.command_name\r
-        else:\r
-            return self.__class__.__name__\r
-\r
-    def set_undefined_options(self, src_cmd, *option_pairs):\r
-        """Set the values of any "undefined" options from corresponding\r
-        option values in some other command object.  "Undefined" here means\r
-        "is None", which is the convention used to indicate that an option\r
-        has not been changed between 'initialize_options()' and\r
-        'finalize_options()'.  Usually called from 'finalize_options()' for\r
-        options that depend on some other command rather than another\r
-        option of the same command.  'src_cmd' is the other command from\r
-        which option values will be taken (a command object will be created\r
-        for it if necessary); the remaining arguments are\r
-        '(src_option,dst_option)' tuples which mean "take the value of\r
-        'src_option' in the 'src_cmd' command object, and copy it to\r
-        'dst_option' in the current command object".\r
-        """\r
-\r
-        # Option_pairs: list of (src_option, dst_option) tuples\r
-\r
-        src_cmd_obj = self.distribution.get_command_obj(src_cmd)\r
-        src_cmd_obj.ensure_finalized()\r
-        for (src_option, dst_option) in option_pairs:\r
-            if getattr(self, dst_option) is None:\r
-                setattr(self, dst_option,\r
-                        getattr(src_cmd_obj, src_option))\r
-\r
-\r
-    def get_finalized_command(self, command, create=1):\r
-        """Wrapper around Distribution's 'get_command_obj()' method: find\r
-        (create if necessary and 'create' is true) the command object for\r
-        'command', call its 'ensure_finalized()' method, and return the\r
-        finalized command object.\r
-        """\r
-        cmd_obj = self.distribution.get_command_obj(command, create)\r
-        cmd_obj.ensure_finalized()\r
-        return cmd_obj\r
-\r
-    # XXX rename to 'get_reinitialized_command()'? (should do the\r
-    # same in dist.py, if so)\r
-    def reinitialize_command(self, command, reinit_subcommands=0):\r
-        return self.distribution.reinitialize_command(\r
-            command, reinit_subcommands)\r
-\r
-    def run_command(self, command):\r
-        """Run some other command: uses the 'run_command()' method of\r
-        Distribution, which creates and finalizes the command object if\r
-        necessary and then invokes its 'run()' method.\r
-        """\r
-        self.distribution.run_command(command)\r
-\r
-    def get_sub_commands(self):\r
-        """Determine the sub-commands that are relevant in the current\r
-        distribution (ie., that need to be run).  This is based on the\r
-        'sub_commands' class attribute: each tuple in that list may include\r
-        a method that we call to determine if the subcommand needs to be\r
-        run for the current distribution.  Return a list of command names.\r
-        """\r
-        commands = []\r
-        for (cmd_name, method) in self.sub_commands:\r
-            if method is None or method(self):\r
-                commands.append(cmd_name)\r
-        return commands\r
-\r
-\r
-    # -- External world manipulation -----------------------------------\r
-\r
-    def warn(self, msg):\r
-        log.warn("warning: %s: %s\n" %\r
-                (self.get_command_name(), msg))\r
-\r
-    def execute(self, func, args, msg=None, level=1):\r
-        util.execute(func, args, msg, dry_run=self.dry_run)\r
-\r
-    def mkpath(self, name, mode=0777):\r
-        dir_util.mkpath(name, mode, dry_run=self.dry_run)\r
-\r
-    def copy_file(self, infile, outfile,\r
-                   preserve_mode=1, preserve_times=1, link=None, level=1):\r
-        """Copy a file respecting verbose, dry-run and force flags.  (The\r
-        former two default to whatever is in the Distribution object, and\r
-        the latter defaults to false for commands that don't define it.)"""\r
-\r
-        return file_util.copy_file(\r
-            infile, outfile,\r
-            preserve_mode, preserve_times,\r
-            not self.force,\r
-            link,\r
-            dry_run=self.dry_run)\r
-\r
-    def copy_tree(self, infile, outfile,\r
-                   preserve_mode=1, preserve_times=1, preserve_symlinks=0,\r
-                   level=1):\r
-        """Copy an entire directory tree respecting verbose, dry-run,\r
-        and force flags.\r
-        """\r
-        return dir_util.copy_tree(\r
-            infile, outfile,\r
-            preserve_mode,preserve_times,preserve_symlinks,\r
-            not self.force,\r
-            dry_run=self.dry_run)\r
-\r
-    def move_file (self, src, dst, level=1):\r
-        """Move a file respecting dry-run flag."""\r
-        return file_util.move_file(src, dst, dry_run = self.dry_run)\r
-\r
-    def spawn (self, cmd, search_path=1, level=1):\r
-        """Spawn an external command respecting dry-run flag."""\r
-        from distutils.spawn import spawn\r
-        spawn(cmd, search_path, dry_run= self.dry_run)\r
-\r
-    def make_archive(self, base_name, format, root_dir=None, base_dir=None,\r
-                     owner=None, group=None):\r
-        return archive_util.make_archive(base_name, format, root_dir,\r
-                                         base_dir, dry_run=self.dry_run,\r
-                                         owner=owner, group=group)\r
-\r
-    def make_file(self, infiles, outfile, func, args,\r
-                  exec_msg=None, skip_msg=None, level=1):\r
-        """Special case of 'execute()' for operations that process one or\r
-        more input files and generate one output file.  Works just like\r
-        'execute()', except the operation is skipped and a different\r
-        message printed if 'outfile' already exists and is newer than all\r
-        files listed in 'infiles'.  If the command defined 'self.force',\r
-        and it is true, then the command is unconditionally run -- does no\r
-        timestamp checks.\r
-        """\r
-        if skip_msg is None:\r
-            skip_msg = "skipping %s (inputs unchanged)" % outfile\r
-\r
-        # Allow 'infiles' to be a single string\r
-        if isinstance(infiles, str):\r
-            infiles = (infiles,)\r
-        elif not isinstance(infiles, (list, tuple)):\r
-            raise TypeError, \\r
-                  "'infiles' must be a string, or a list or tuple of strings"\r
-\r
-        if exec_msg is None:\r
-            exec_msg = "generating %s from %s" % \\r
-                       (outfile, ', '.join(infiles))\r
-\r
-        # If 'outfile' must be regenerated (either because it doesn't\r
-        # exist, is out-of-date, or the 'force' flag is true) then\r
-        # perform the action that presumably regenerates it\r
-        if self.force or dep_util.newer_group(infiles, outfile):\r
-            self.execute(func, args, exec_msg, level)\r
-\r
-        # Otherwise, print the "skip" message\r
-        else:\r
-            log.debug(skip_msg)\r
-\r
-# XXX 'install_misc' class not currently used -- it was the base class for\r
-# both 'install_scripts' and 'install_data', but they outgrew it.  It might\r
-# still be useful for 'install_headers', though, so I'm keeping it around\r
-# for the time being.\r
-\r
-class install_misc(Command):\r
-    """Common base class for installing some files in a subdirectory.\r
-    Currently used by install_data and install_scripts.\r
-    """\r
-\r
-    user_options = [('install-dir=', 'd', "directory to install the files to")]\r
-\r
-    def initialize_options (self):\r
-        self.install_dir = None\r
-        self.outfiles = []\r
-\r
-    def _install_dir_from(self, dirname):\r
-        self.set_undefined_options('install', (dirname, 'install_dir'))\r
-\r
-    def _copy_files(self, filelist):\r
-        self.outfiles = []\r
-        if not filelist:\r
-            return\r
-        self.mkpath(self.install_dir)\r
-        for f in filelist:\r
-            self.copy_file(f, self.install_dir)\r
-            self.outfiles.append(os.path.join(self.install_dir, f))\r
-\r
-    def get_outputs(self):\r
-        return self.outfiles\r