def TarIt(root, dir):
    tar_filename = root + '/' + dir + '.tgz'

    if os.path.exists(tar_filename):
        os.remove(tar_filename)

    archive = tarfile.TarFileCompat(tar_filename, "w", tarfile.TAR_GZIPPED)
    ZipDir(root + '/' + dir, archive, dir)
    archive.close()
Example #2
0
 def __init__(self, filepath):
     if zipfile.is_zipfile(filepath):
         self.archive = zipfile.ZipFile(filepath,"r")
     elif tarfile.is_tarfile(filepath):
         self.archive = tarfile.TarFileCompat(filepath,"r")
     else:
         raise AssertionError("filepath '%s' is not a zip or tar " % filepath)
     self.expires = None
     self.last_modified = time.time()
     self.cache = {}
Example #3
0
def extract(distro):
    dir = tempfile.mktemp()
    if zipfile.is_zipfile(distro):
        file = zipfile.ZipFile(distro)
    elif tarfile and tarfile.is_tarfile(distro):
        file = tarfile.TarFileCompat(distro, "r", tarfile.TAR_GZIPPED)
    else:
        if tarfile:
            raise TypeError("%r does not seem to be a zipfile or tarfile" % distro)
        else:
            raise TypeError("%r does not seem to be a zipfile" % distro)
    os.mkdir(dir)
    for info in file.infolist():
        if info.filename[-1] != '/':
            data = file.read(info.filename)
            create_file(os.path.join(dir, info.filename), data)
    return dir