check zipextensions as one string or list

This commit is contained in:
Jakobus Schürz 2020-04-19 09:17:10 +02:00
parent 42e6c9a1c3
commit 64776a8714

View file

@ -152,11 +152,20 @@ class WorkdirFS(Operations):
return path return path
def _check_fileext(self, filename, zipext):
if type(zipext) is str:
return zipext in filename
elif type(zipext) is list:
for e in arr:
if (lambda x: x in filename)(e):
return True
return False
def _cleanup_dirs(self): def _cleanup_dirs(self):
print("Cleanup dir", self.yesterdaypath) print("Cleanup dir", self.yesterdaypath)
zip_fileext=".gz" #zip_fileext=".gz"
zip_fileext=[".gz","tgz",".gz.tar"]
zip_compressionlevel=5 zip_compressionlevel=5
#for root, dirs, files in os.walk(self.yesterdaypath, topdown=False): #for root, dirs, files in os.walk(self.yesterdaypath, topdown=False):
print("Archivepath",self.archivpathbase) print("Archivepath",self.archivpathbase)
@ -170,7 +179,8 @@ class WorkdirFS(Operations):
if self.args.compress: if self.args.compress:
for f in files: for f in files:
print("compress", os.path.join(root, f)) print("compress", os.path.join(root, f))
if zip_fileext not in f: #if zip_fileext not in f:
if not _check_fileext(f,zip_fileext):
try: try:
with open(os.path.join(root, f), 'rb') as f_in: with open(os.path.join(root, f), 'rb') as f_in:
with gzip.open( with gzip.open(