Exemple #1
0
    def __init__(self, archivePathname):
        """Create a ZipArchive, treating the archive at archivePathname as a zip file.

        @param archivePathname: a str, naming a path in the filesystem.
        """
        self.zipfile = ChunkingZipFile(archivePathname)
        self.path = archivePathname
        self.pathInArchive = ''
        # zipfile is already wasting O(N) memory on cached ZipInfo instances,
        # so there's no sense in trying to do this lazily or intelligently
        self.childmap = {}  # map parent: list of children

        for name in self.zipfile.namelist():
            name = name.split(ZIP_PATH_SEP)
            for x in range(len(name)):
                child = name[-x]
                parent = ZIP_PATH_SEP.join(name[:-x])
                if parent not in self.childmap:
                    self.childmap[parent] = {}
                self.childmap[parent][child] = 1
            parent = ''
Exemple #2
0
class ZipArchive(ZipPath):
    """ I am a FilePath-like object which can wrap a zip archive as if it were a
    directory.
    """
    archive = property(lambda self: self)

    def __init__(self, archivePathname):
        """Create a ZipArchive, treating the archive at archivePathname as a zip file.

        @param archivePathname: a str, naming a path in the filesystem.
        """
        self.zipfile = ChunkingZipFile(archivePathname)
        self.path = archivePathname
        self.pathInArchive = ''
        # zipfile is already wasting O(N) memory on cached ZipInfo instances,
        # so there's no sense in trying to do this lazily or intelligently
        self.childmap = {}  # map parent: list of children

        for name in self.zipfile.namelist():
            name = name.split(ZIP_PATH_SEP)
            for x in range(len(name)):
                child = name[-x]
                parent = ZIP_PATH_SEP.join(name[:-x])
                if parent not in self.childmap:
                    self.childmap[parent] = {}
                self.childmap[parent][child] = 1
            parent = ''

    def child(self, path):
        """
        Create a ZipPath pointing at a path within the archive.

        @param path: a str with no path separators in it, either '/' or the
        system path separator, if it's different.
        """
        return ZipPath(self, path)

    def exists(self):
        """
        Returns true if the underlying archive exists.
        """
        return FilePath(self.zipfile.filename).exists()

    def getAccessTime(self):
        """
        Return the archive file's last access time.
        """
        return FilePath(self.zipfile.filename).getAccessTime()

    def getModificationTime(self):
        """
        Return the archive file's modification time.
        """
        return FilePath(self.zipfile.filename).getModificationTime()

    def getStatusChangeTime(self):
        """
        Return the archive file's status change time.
        """
        return FilePath(self.zipfile.filename).getStatusChangeTime()

    def __repr__(self):
        return 'ZipArchive(%r)' % (os.path.abspath(self.path), )