Anonymous avatar Anonymous committed 4d114c5

now with 2.4 support for tarfile

Comments (0)

Files changed (1)

distribute_setup.py

 from site import USER_SITE
 import sys
 import os
-import shutil
 import time
 import fnmatch
 from distutils import log
-from distutils.errors import DistutilsError
 
 is_jython = sys.platform.startswith('java')
 if is_jython:
 
 
 DEFAULT_VERSION = "0.6.1"
-#DEFAULT_URL     = "http://pypi.python.org/packages/source/d/distribute/"
-DEFAULT_URL = "http://nightly.ziade.org/"
+DEFAULT_URL     = "http://pypi.python.org/packages/source/d/distribute/"
 
 def download_setuptools(
     version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
     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.
     """
-    import urllib2, shutil
+    import urllib2
     tgz_name = "distribute-%s.tar.gz" % version
     url = download_base + tgz_name
     saveto = os.path.join(to_dir, tgz_name)
 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 = []
+
+        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)
+
+        # 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)
+
 def _install(tarball):
     # extracting the tarball
     tmpdir = tempfile.mkdtemp()
     try:
         os.chdir(tmpdir)
         tar = tarfile.open(tarball)
-        tar.extractall()
+        extractall(tar)
         tar.close()
 
         # going in the directory
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.