zip eklendi fakat test edilmedi..
exception handling ile beraber diger artype'larin destegi eklenecek (bisi yok onda), ayrica symlink'ler ile ilgili bir sorunumuz var ;)
This commit is contained in:
+30
-15
@@ -1,38 +1,53 @@
|
|||||||
# utilities to extract and build archives of zip, tar, targz, tarbz2
|
# -*- coding: utf-8 -*-
|
||||||
# maintainer: baris and meren
|
# unpack magic
|
||||||
|
# maintainer baris and meren
|
||||||
|
|
||||||
import tarfile
|
#standart lisbrary modules
|
||||||
import zipfile
|
import os, sys
|
||||||
|
|
||||||
|
#pisi modules
|
||||||
import config
|
import config
|
||||||
|
|
||||||
class ArchiveBase(object):
|
class ArchiveBase(object):
|
||||||
def __init__(self, filename, type):
|
def __init__(self, fileName, type):
|
||||||
self.type = type
|
self.type = type
|
||||||
self.filename = filename
|
self.fileName = fileName
|
||||||
|
|
||||||
class ArchiveTarFile(ArchiveBase):
|
class ArchiveTarFile(ArchiveBase):
|
||||||
def __init__(self, filename, type):
|
def __init__(self, fileName, type):
|
||||||
super(ArchiveTarFile, self).__init__(filename, type)
|
import tarfile
|
||||||
|
super(ArchiveTarFile, self).__init__(fileName, type)
|
||||||
|
|
||||||
def unpack(self):
|
def unpack(self):
|
||||||
if self.type == "targz":
|
if self.type == "targz":
|
||||||
tar = tarfile.open(config.archives_dir()+"/"+self.filename, 'r:gz')
|
tar = tarfile.open(config.archives_dir() + "/" + self.fileName, 'r:gz')
|
||||||
for tarinfo in tar:
|
for tarinfo in tar:
|
||||||
tar.extract(tarinfo)
|
tar.extract(tarinfo)
|
||||||
tar.close()
|
tar.close()
|
||||||
|
|
||||||
class ArchiveZip(ArchiveBase):
|
class ArchiveZip(ArchiveBase):
|
||||||
def __init__(self, filename, type):
|
def __init__(self, fileName, type):
|
||||||
super(ArchiveZip, self).__init__(filename, type)
|
import zipfile
|
||||||
|
super(ArchiveZip, self).__init__(fileName, type)
|
||||||
|
|
||||||
def unpack(self):
|
def unpack(self):
|
||||||
print "lolo"
|
zip = zipfile.Zipfile(config.archives_dir() + "/" + self.fileName, 'r')
|
||||||
|
fileNames = zip.namelist()
|
||||||
|
for file in fileNames:
|
||||||
|
file = config.archives_dir() + '/' + file
|
||||||
|
if not os.path.exists(os.path.dirname(file)):
|
||||||
|
os.mkdir(os.path.dirname(file))
|
||||||
|
continue
|
||||||
|
buff = open (file, "wb")
|
||||||
|
fileContent = zip.read(file)
|
||||||
|
buff.write(fileContent)
|
||||||
|
buff.close()
|
||||||
|
zip.close()
|
||||||
|
|
||||||
class Archive:
|
class Archive:
|
||||||
"""Unpack magic for Archive files..."""
|
"""Unpack magic for Archive files..."""
|
||||||
|
|
||||||
def __init__(self, type, filename):
|
def __init__(self, type, fileName):
|
||||||
"""accepted archive types:
|
"""accepted archive types:
|
||||||
targz, tarbz2, zip, tar"""
|
targz, tarbz2, zip, tar"""
|
||||||
|
|
||||||
@@ -43,7 +58,7 @@ class Archive:
|
|||||||
'zip': ArchiveZip
|
'zip': ArchiveZip
|
||||||
}
|
}
|
||||||
|
|
||||||
self.archive = actions.get(type)(filename, type)
|
self.archive = actions.get(type)(fileName, type)
|
||||||
|
|
||||||
def unpack(self):
|
def unpack(self):
|
||||||
self.archive.unpack()
|
self.archive.unpack()
|
||||||
|
|||||||
Reference in New Issue
Block a user