Commits

Anonymous committed 20fc872

PEP8 fixes

Comments (0)

Files changed (1)

distribute_setup.py

 import os
 import time
 import fnmatch
+import tempfile
+import tarfile
+import subprocess
 from distutils import log
-import subprocess
+
 
 IS_JYTHON = sys.platform.startswith('java')
 DEFAULT_VERSION = "0.6.2"
-DEFAULT_URL     = "http://pypi.python.org/packages/source/d/distribute/"
+DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
+SETUPTOOLS_PKG_INFO = """\
+Metadata-Version: 1.0
+Name: setuptools
+Version: 0.6c9
+Summary: xxxx
+Home-page: xxx
+Author: xxx
+Author-email: xxx
+License: xxx
+Description: xxx
+"""
+
 
 def quote(c):
     if sys.platform == 'win32':
             return '"%s"' % c
     return c
 
+
 def python_cmd(cmd):
     python = quote(sys.executable)
     cmd = quote(cmd)
     args = [os.P_WAIT, python, python] + cmd.split() + [os.environ]
     return os.spawnle(*args) == 0
 
+
 def _install(tarball):
     # extracting the tarball
     tmpdir = tempfile.mkdtemp()
     finally:
         os.chdir(old_wd)
 
+
 def _build_egg(tarball, to_dir=os.curdir):
     # extracting the tarball
     tmpdir = tempfile.mkdtemp()
     finally:
         os.chdir(old_wd)
 
+
 def _do_download(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
                  to_dir=os.curdir, download_delay=15):
     tarball = download_setuptools(version, download_base,
     import setuptools
     setuptools.bootstrap_install_from = egg
 
-def use_setuptools(
-    version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
-    download_delay=15
-):
-    was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
+
+def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
+                   to_dir=os.curdir, download_delay=15):
+    was_imported = 'pkg_resources' in sys.modules or \
+        'setuptools' in sys.modules
     try:
         import pkg_resources
         if not hasattr(pkg_resources, '_distribute'):
     except ImportError:
         return _do_download(version, download_base, to_dir, download_delay)
     try:
-        pkg_resources.require("distribute>="+version); return
+        pkg_resources.require("distribute>="+version)
+        return
     except pkg_resources.VersionConflict, e:
         if was_imported:
             print >>sys.stderr, (
             "The required version of distribute (>=%s) is not available, and\n"
             "can't be installed while this script is running. Please install\n"
             " a more recent version first, using 'easy_install -U distribute'."
-            "\n\n(Currently using %r)"
-            ) % (version, e.args[0])
+            "\n\n(Currently using %r)") % (version, e.args[0])
             sys.exit(2)
         else:
             del pkg_resources, sys.modules['pkg_resources']    # reload ok
     except pkg_resources.DistributionNotFound:
         return _do_download(version, download_base, to_dir, download_delay)
 
-def download_setuptools(
-    version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
-    delay=15,
-):
+
+def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
+                        to_dir=os.curdir, delay=15):
     """Download distribute from a specified location and return its filename
 
     `version` should be a valid distribute version number that is available
     as an egg for download under the `download_base` URL (which should end
     with a '/'). `to_dir` is the directory where the egg will be downloaded.
-    `delay` is the number of seconds to pause before an actual download attempt.
+    `delay` is the number of seconds to pause before an actual download
+    attempt.
     """
     import urllib2
     tgz_name = "distribute-%s.tar.gz" % version
     src = dst = None
     if not os.path.exists(saveto):  # Avoid repeated downloads
         try:
-            from distutils import log
             log.warn("Downloading %s", url)
             src = urllib2.urlopen(url)
             # Read/write all in one block, so we don't create a corrupt file
     return os.path.realpath(saveto)
 
 
-SETUPTOOLS_PKG_INFO  = """\
-Metadata-Version: 1.0
-Name: setuptools
-Version: 0.6c9
-Summary: xxxx
-Home-page: xxx
-Author: xxx
-Author-email: xxx
-License: xxx
-Description: xxx
-"""
-
 def _patch_file(path, content):
     """Will backup the file then patch it"""
     existing_content = open(path).read()
         f.close()
     return True
 
+
 def _same_content(path, content):
     return open(path).read() == content
 
+
 def _rename_path(path):
     new_name = path + '.OLD.%s' % time.time()
     log.warn('Renaming %s into %s' % (path, new_name))
     os.rename(path, new_name)
     return new_name
 
+
 def _remove_flat_installation(placeholder):
     if not os.path.isdir(placeholder):
         log.warn('Unkown installation at %s' % placeholder)
                      'Setuptools distribution' % element)
     return True
 
+
 def after_install(dist):
     log.warn('After install bootstrap.')
     placeholder = dist.get_command_obj('install').install_purelib
     finally:
         f.close()
 
+
 def _patch_egg_dir(path):
     # let's check if it's already patched
     pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
         f.close()
     return True
 
+
 def before_install():
     log.warn('Before install bootstrap.')
     fake_setuptools()
 
+
 def _under_prefix(location):
     if 'install' not in sys.argv:
         return True
                 return location.startswith(USER_SITE)
     return True
 
+
 def fake_setuptools():
     log.warn('Scanning installed packages')
     try:
     log.warn('Patched done.')
     _relaunch()
 
+
 def _relaunch():
     log.warn('Relaunching...')
     # we have to relaunch the process
-    args = [sys.executable]  + sys.argv
+    args = [sys.executable] + sys.argv
     if IS_JYTHON:
         sys.exit(subprocess.call(args))
     else:
         sys.exit(os.spawnv(os.P_WAIT, sys.executable, args))
 
-import tempfile
-import tarfile
 
 def extractall(self, path=".", members=None):
-        """Extract all members from the archive to the current working
-           directory and set owner, modification time and permissions on
-           directories afterwards. `path' specifies a different directory
-           to extract to. `members' is optional and must be a subset of the
-           list returned by getmembers().
-        """
-        import copy
-        import operator
-        from tarfile import ExtractError
-        directories = []
+    """Extract all members from the archive to the current working
+       directory and set owner, modification time and permissions on
+       directories afterwards. `path' specifies a different directory
+       to extract to. `members' is optional and must be a subset of the
+       list returned by getmembers().
+    """
+    import copy
+    import operator
+    from tarfile import ExtractError
+    directories = []
 
-        if members is None:
-            members = self
+    if members is None:
+        members = self
 
-        for tarinfo in members:
-            if tarinfo.isdir():
-                # Extract directories with a safe mode.
-                directories.append(tarinfo)
-                tarinfo = copy.copy(tarinfo)
-                tarinfo.mode = 0700
-            self.extract(tarinfo, path)
+    for tarinfo in members:
+        if tarinfo.isdir():
+            # Extract directories with a safe mode.
+            directories.append(tarinfo)
+            tarinfo = copy.copy(tarinfo)
+            tarinfo.mode = 0700
+        self.extract(tarinfo, path)
 
-        # Reverse sort directories.
-        directories.sort(key=operator.attrgetter('name'))
-        directories.reverse()
+    # Reverse sort directories.
+    directories.sort(key=operator.attrgetter('name'))
+    directories.reverse()
 
-        # Set correct owner, mtime and filemode on directories.
-        for tarinfo in directories:
-            dirpath = os.path.join(path, tarinfo.name)
-            try:
-                self.chown(tarinfo, dirpath)
-                self.utime(tarinfo, dirpath)
-                self.chmod(tarinfo, dirpath)
-            except ExtractError, e:
-                if self.errorlevel > 1:
-                    raise
-                else:
-                    self._dbg(1, "tarfile: %s" % e)
+    # Set correct owner, mtime and filemode on directories.
+    for tarinfo in directories:
+        dirpath = os.path.join(path, tarinfo.name)
+        try:
+            self.chown(tarinfo, dirpath)
+            self.utime(tarinfo, dirpath)
+            self.chmod(tarinfo, dirpath)
+        except ExtractError, e:
+            if self.errorlevel > 1:
+                raise
+            else:
+                self._dbg(1, "tarfile: %s" % e)
+
 
 def main(argv, version=DEFAULT_VERSION):
     """Install or upgrade setuptools and EasyInstall"""
     tarball = download_setuptools()
     _install(tarball)
 
+
 if __name__ == '__main__':
     main(sys.argv[1:])
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.