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
|
# maintainer baris and meren
|
||||||
|
|
||||||
#standart lisbrary modules
|
#standart lisbrary modules
|
||||||
import os, sys
|
import os
|
||||||
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
@@ -15,13 +16,15 @@ class ArchiveBase(object):
|
|||||||
self.type = type
|
self.type = type
|
||||||
self.fileName = fileName
|
self.fileName = fileName
|
||||||
|
|
||||||
|
self.filePath = config.archives_dir() + '/' + self.fileName
|
||||||
|
|
||||||
class ArchiveTarFile(ArchiveBase):
|
class ArchiveTarFile(ArchiveBase):
|
||||||
def __init__(self, fileName, type):
|
def __init__(self, fileName, type):
|
||||||
super(ArchiveTarFile, self).__init__(fileName, type)
|
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(self.filePath, 'r:gz')
|
||||||
for tarinfo in tar:
|
for tarinfo in tar:
|
||||||
tar.extract(tarinfo)
|
tar.extract(tarinfo)
|
||||||
tar.close()
|
tar.close()
|
||||||
@@ -31,13 +34,15 @@ class ArchiveZip(ArchiveBase):
|
|||||||
super(ArchiveZip, self).__init__(fileName, type)
|
super(ArchiveZip, self).__init__(fileName, type)
|
||||||
|
|
||||||
def unpack(self):
|
def unpack(self):
|
||||||
zip = zipfile.ZipFile(config.archives_dir() + '/' + self.fileName, '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 = config.archives_dir() + '/' + file
|
||||||
if not os.path.exists(os.path.dirname(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))
|
os.mkdir(os.path.dirname(config.archives_dir() + '/' + file))
|
||||||
continue
|
continue
|
||||||
|
else: # directory is present, we should still continue (or delete?)
|
||||||
|
continue
|
||||||
buff = open (ofile, 'wb')
|
buff = open (ofile, 'wb')
|
||||||
fileContent = zip.read(file)
|
fileContent = zip.read(file)
|
||||||
buff.write(fileContent)
|
buff.write(fileContent)
|
||||||
|
|||||||
Reference in New Issue
Block a user