Exemplo n.º 1
0
    def extract(self, destination):
        filenames = Paths(verify=False)
        if self.format == '.egg':
            # Eggs are not in a directory for themselves...
            # Add a directory
            destination = os.path.join(
                destination,
                os.path.splitext(os.path.basename(self.filename))[0])

        for filename in self._zip.namelist():
            target_filename = os.path.join(destination, filename)
            target_info = self._zip.getinfo(filename)

            # ZIP specs uses / as path separator
            is_dir = (filename[-1] == '/' or
                      target_info.external_attr & 0x10 == 0x10)
            if not is_dir:
                # Extract the file if it is not a folder
                target_path = os.path.dirname(target_filename)
                if not os.path.exists(target_path):
                    os.makedirs(target_path)

                output = open(target_filename, 'wb')
                output.write(self._zip.read(filename))
                output.close()
            else:
                filename = filename.rstrip('/')
                if not os.path.exists(target_filename):
                    os.makedirs(target_filename)

            filenames.add(filename, directory=is_dir)
        return filenames
Exemplo n.º 2
0
 def extract(self, destination):
     filenames = Paths(verify=False, separator='/')
     for entry in self._tar:
         self._tar.extract(entry, destination)
         filenames.add(entry.name, directory=entry.isdir())
     return filenames