]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/main.py
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / lib2to3 / main.py
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/main.py b/AppPkg/Applications/Python/Python-2.7.2/Lib/lib2to3/main.py
deleted file mode 100644 (file)
index e0fab43..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-"""\r
-Main program for 2to3.\r
-"""\r
-\r
-from __future__ import with_statement\r
-\r
-import sys\r
-import os\r
-import difflib\r
-import logging\r
-import shutil\r
-import optparse\r
-\r
-from . import refactor\r
-\r
-\r
-def diff_texts(a, b, filename):\r
-    """Return a unified diff of two strings."""\r
-    a = a.splitlines()\r
-    b = b.splitlines()\r
-    return difflib.unified_diff(a, b, filename, filename,\r
-                                "(original)", "(refactored)",\r
-                                lineterm="")\r
-\r
-\r
-class StdoutRefactoringTool(refactor.MultiprocessRefactoringTool):\r
-    """\r
-    Prints output to stdout.\r
-    """\r
-\r
-    def __init__(self, fixers, options, explicit, nobackups, show_diffs):\r
-        self.nobackups = nobackups\r
-        self.show_diffs = show_diffs\r
-        super(StdoutRefactoringTool, self).__init__(fixers, options, explicit)\r
-\r
-    def log_error(self, msg, *args, **kwargs):\r
-        self.errors.append((msg, args, kwargs))\r
-        self.logger.error(msg, *args, **kwargs)\r
-\r
-    def write_file(self, new_text, filename, old_text, encoding):\r
-        if not self.nobackups:\r
-            # Make backup\r
-            backup = filename + ".bak"\r
-            if os.path.lexists(backup):\r
-                try:\r
-                    os.remove(backup)\r
-                except os.error, err:\r
-                    self.log_message("Can't remove backup %s", backup)\r
-            try:\r
-                os.rename(filename, backup)\r
-            except os.error, err:\r
-                self.log_message("Can't rename %s to %s", filename, backup)\r
-        # Actually write the new file\r
-        write = super(StdoutRefactoringTool, self).write_file\r
-        write(new_text, filename, old_text, encoding)\r
-        if not self.nobackups:\r
-            shutil.copymode(backup, filename)\r
-\r
-    def print_output(self, old, new, filename, equal):\r
-        if equal:\r
-            self.log_message("No changes to %s", filename)\r
-        else:\r
-            self.log_message("Refactored %s", filename)\r
-            if self.show_diffs:\r
-                diff_lines = diff_texts(old, new, filename)\r
-                try:\r
-                    if self.output_lock is not None:\r
-                        with self.output_lock:\r
-                            for line in diff_lines:\r
-                                print line\r
-                            sys.stdout.flush()\r
-                    else:\r
-                        for line in diff_lines:\r
-                            print line\r
-                except UnicodeEncodeError:\r
-                    warn("couldn't encode %s's diff for your terminal" %\r
-                         (filename,))\r
-                    return\r
-\r
-\r
-def warn(msg):\r
-    print >> sys.stderr, "WARNING: %s" % (msg,)\r
-\r
-\r
-def main(fixer_pkg, args=None):\r
-    """Main program.\r
-\r
-    Args:\r
-        fixer_pkg: the name of a package where the fixers are located.\r
-        args: optional; a list of command line arguments. If omitted,\r
-              sys.argv[1:] is used.\r
-\r
-    Returns a suggested exit status (0, 1, 2).\r
-    """\r
-    # Set up option parser\r
-    parser = optparse.OptionParser(usage="2to3 [options] file|dir ...")\r
-    parser.add_option("-d", "--doctests_only", action="store_true",\r
-                      help="Fix up doctests only")\r
-    parser.add_option("-f", "--fix", action="append", default=[],\r
-                      help="Each FIX specifies a transformation; default: all")\r
-    parser.add_option("-j", "--processes", action="store", default=1,\r
-                      type="int", help="Run 2to3 concurrently")\r
-    parser.add_option("-x", "--nofix", action="append", default=[],\r
-                      help="Prevent a transformation from being run")\r
-    parser.add_option("-l", "--list-fixes", action="store_true",\r
-                      help="List available transformations")\r
-    parser.add_option("-p", "--print-function", action="store_true",\r
-                      help="Modify the grammar so that print() is a function")\r
-    parser.add_option("-v", "--verbose", action="store_true",\r
-                      help="More verbose logging")\r
-    parser.add_option("--no-diffs", action="store_true",\r
-                      help="Don't show diffs of the refactoring")\r
-    parser.add_option("-w", "--write", action="store_true",\r
-                      help="Write back modified files")\r
-    parser.add_option("-n", "--nobackups", action="store_true", default=False,\r
-                      help="Don't write backups for modified files")\r
-\r
-    # Parse command line arguments\r
-    refactor_stdin = False\r
-    flags = {}\r
-    options, args = parser.parse_args(args)\r
-    if not options.write and options.no_diffs:\r
-        warn("not writing files and not printing diffs; that's not very useful")\r
-    if not options.write and options.nobackups:\r
-        parser.error("Can't use -n without -w")\r
-    if options.list_fixes:\r
-        print "Available transformations for the -f/--fix option:"\r
-        for fixname in refactor.get_all_fix_names(fixer_pkg):\r
-            print fixname\r
-        if not args:\r
-            return 0\r
-    if not args:\r
-        print >> sys.stderr, "At least one file or directory argument required."\r
-        print >> sys.stderr, "Use --help to show usage."\r
-        return 2\r
-    if "-" in args:\r
-        refactor_stdin = True\r
-        if options.write:\r
-            print >> sys.stderr, "Can't write to stdin."\r
-            return 2\r
-    if options.print_function:\r
-        flags["print_function"] = True\r
-\r
-    # Set up logging handler\r
-    level = logging.DEBUG if options.verbose else logging.INFO\r
-    logging.basicConfig(format='%(name)s: %(message)s', level=level)\r
-\r
-    # Initialize the refactoring tool\r
-    avail_fixes = set(refactor.get_fixers_from_package(fixer_pkg))\r
-    unwanted_fixes = set(fixer_pkg + ".fix_" + fix for fix in options.nofix)\r
-    explicit = set()\r
-    if options.fix:\r
-        all_present = False\r
-        for fix in options.fix:\r
-            if fix == "all":\r
-                all_present = True\r
-            else:\r
-                explicit.add(fixer_pkg + ".fix_" + fix)\r
-        requested = avail_fixes.union(explicit) if all_present else explicit\r
-    else:\r
-        requested = avail_fixes.union(explicit)\r
-    fixer_names = requested.difference(unwanted_fixes)\r
-    rt = StdoutRefactoringTool(sorted(fixer_names), flags, sorted(explicit),\r
-                               options.nobackups, not options.no_diffs)\r
-\r
-    # Refactor all files and directories passed as arguments\r
-    if not rt.errors:\r
-        if refactor_stdin:\r
-            rt.refactor_stdin()\r
-        else:\r
-            try:\r
-                rt.refactor(args, options.write, options.doctests_only,\r
-                            options.processes)\r
-            except refactor.MultiprocessingUnsupported:\r
-                assert options.processes > 1\r
-                print >> sys.stderr, "Sorry, -j isn't " \\r
-                    "supported on this platform."\r
-                return 1\r
-        rt.summarize()\r
-\r
-    # Return error status (0 if rt.errors is zero)\r
-    return int(bool(rt.errors))\r