unittest bir bug daha yakaladı :).
eğer oluşturulmak istenen dizin varsa çakılıyorduk.
This commit is contained in:
+8
-3
@@ -3,7 +3,8 @@
|
||||
# maintainer baris and meren
|
||||
|
||||
#standart lisbrary modules
|
||||
import os, sys
|
||||
import os
|
||||
import sys
|
||||
import tarfile
|
||||
import zipfile
|
||||
|
||||
@@ -15,13 +16,15 @@ class ArchiveBase(object):
|
||||
self.type = type
|
||||
self.fileName = fileName
|
||||
|
||||
self.filePath = config.archives_dir() + '/' + self.fileName
|
||||
|
||||
class ArchiveTarFile(ArchiveBase):
|
||||
def __init__(self, fileName, type):
|
||||
super(ArchiveTarFile, self).__init__(fileName, type)
|
||||
|
||||
def unpack(self):
|
||||
if self.type == 'targz':
|
||||
tar = tarfile.open(config.archives_dir() + '/' + self.fileName, 'r:gz')
|
||||
tar = tarfile.open(self.filePath, 'r:gz')
|
||||
for tarinfo in tar:
|
||||
tar.extract(tarinfo)
|
||||
tar.close()
|
||||
@@ -31,13 +34,15 @@ class ArchiveZip(ArchiveBase):
|
||||
super(ArchiveZip, self).__init__(fileName, type)
|
||||
|
||||
def unpack(self):
|
||||
zip = zipfile.ZipFile(config.archives_dir() + '/' + self.fileName, 'r')
|
||||
zip = zipfile.ZipFile(self.filePath, 'r')
|
||||
fileNames = zip.namelist()
|
||||
for file in fileNames:
|
||||
ofile = config.archives_dir() + '/' + file
|
||||
if not os.path.exists(os.path.dirname(config.archives_dir() + '/' + file)):
|
||||
os.mkdir(os.path.dirname(config.archives_dir() + '/' + file))
|
||||
continue
|
||||
else: # directory is present, we should still continue (or delete?)
|
||||
continue
|
||||
buff = open (ofile, 'wb')
|
||||
fileContent = zip.read(file)
|
||||
buff.write(fileContent)
|
||||
|
||||
Reference in New Issue
Block a user