zip sorunlu, targetDir calisiyor.. ha haa

This commit is contained in:
A. Murat Eren
2005-06-15 08:57:17 +00:00
parent 6a270f02e0
commit b23fe046e0
+17 -8
View File
@@ -17,17 +17,28 @@ class ArchiveBase(object):
self.fileName = fileName self.fileName = fileName
self.filePath = config.archives_dir() + '/' + self.fileName self.filePath = config.archives_dir() + '/' + self.fileName
self.targetDir = targetDir self.targetDir = targetDir
if not os.path.exists(self.targetDir):
os.makedirs(self.targetDir)
class ArchiveTarFile(ArchiveBase): class ArchiveTarFile(ArchiveBase):
def __init__(self, type, fileName, targetDir): def __init__(self, type, fileName, targetDir):
super(ArchiveTarFile, self).__init__(type, fileName, targetDir) super(ArchiveTarFile, self).__init__(type, fileName, targetDir)
def unpack(self): def unpack(self):
if self.type == 'targz': rmode = ""
tar = tarfile.open(self.filePath, 'r:gz') if self.type == 'tar':
for tarinfo in tar: rmode = 'r:'
tar.extract(tarinfo) elif self.type == 'targz':
tar.close() rmode = 'r:gz'
elif self.type == 'tarbz2':
rmode = 'r:bz2'
tar = tarfile.open(self.filePath, rmode)
oldwd = os.getcwd()
os.chdir(self.targetDir)
for tarinfo in tar:
tar.extract(tarinfo)
os.chdir(oldwd)
tar.close()
class ArchiveZip(ArchiveBase): class ArchiveZip(ArchiveBase):
def __init__(self, type, fileName, targetDir): def __init__(self, type, fileName, targetDir):
@@ -37,12 +48,10 @@ class ArchiveZip(ArchiveBase):
zip = zipfile.ZipFile(self.filePath, 'r') zip = zipfile.ZipFile(self.filePath, 'r')
fileNames = zip.namelist() fileNames = zip.namelist()
for file in fileNames: for file in fileNames:
ofile = config.archives_dir() + '/' + file ofile = self.targetDir + '/' + file
if not os.path.exists(ofile): if not os.path.exists(ofile):
os.mkdir(ofile) os.mkdir(ofile)
continue continue
elif os.path.exists(ofile): #maybe ofile is not a dir, but file.
continue #so we have to check..
buff = open (ofile, 'wb') buff = open (ofile, 'wb')
fileContent = zip.read(file) fileContent = zip.read(file)
buff.write(fileContent) buff.write(fileContent)