import zipfile import tarfile import os import basic.program def untarFolder(target, targetFile): tar_file = tarfile.open(os.path.join(target, targetFile), 'r:gz') tar_file.extractall(path=os.path.join(target, 'tarliste')) tar_file.close() pass def openNewTarFile(target, targetFile): job = basic.program.Job.getInstance() tarfilename = os.path.join(target, targetFile) if os.path.exists(tarfilename): os.remove(tarfilename) job.m.logInfo("Archiv angelegt "+tarfilename) return tarfile.open(tarfilename, 'w:gz') def appendFolderIntoTarFile(source, sourceFolder, tarFile): workFolder = os.path.join(source, sourceFolder) for folderName, subfolders, filenames in os.walk(workFolder): for filename in filenames: folderShort = folderName[len(source)+1:] # create complete filepath of file in directory filePath = os.path.join(folderName, filename) # Add file to zip tarFile.add(filePath, os.path.join(folderShort, filename)) def tarFolder(source, sourceFolder, target, targetFile): with tarfile.open(os.path.join(target, targetFile), 'w:gz') as tar_file: for folderName, subfolders, filenames in os.walk(os.path.join(source, sourceFolder)): for filename in filenames: folderShort = folderName.replace(source + '/', '') # create complete filepath of file in directory filePath = os.path.join(folderName, filename) # Add file to zip tar_file.add(filePath, os.path.join(folderShort, filename)) tar_file.close() def unzipFolder(target, targetFile): zip_file = zipfile.ZipFile(os.path.join(target, targetFile), 'r') zip_file.extractall(path=os.path.join(target, 'liste')) zip_file.close() pass def zipFolder(source, sourceFolder, target, targetFile): with zipfile.ZipFile(os.path.join(target, targetFile), 'w') as zip_file: # Iterate over all the files in directory for folderName, subfolders, filenames in os.walk(os.path.join(source, sourceFolder)): for filename in filenames: folderShort = folderName.replace(source+'/', '') # create complete filepath of file in directory filePath = os.path.join(folderName, filename) # Add file to zip zip_file.write(filePath, os.path.join(folderShort, filename)) zip_file.close() return ""