|
|
@ -1,23 +1,39 @@ |
|
|
|
import zipfile |
|
|
|
import tarfile |
|
|
|
import os |
|
|
|
import basic.program |
|
|
|
|
|
|
|
ZIEL = '/home/ulrich/tmp' |
|
|
|
QUELLE = '/home/ulrich/1_privat' |
|
|
|
FOLDER = '64-UMKER' |
|
|
|
|
|
|
|
|
|
|
|
def untarFolder(): |
|
|
|
tar_file = tarfile.open(os.path.join(ZIEL, 'tartemp.tar.gz'), 'r:gz') |
|
|
|
tar_file.extractall(path=os.path.join(ZIEL, 'tarliste')) |
|
|
|
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 tarFolder(): |
|
|
|
with tarfile.open(os.path.join(ZIEL, 'tartemp.tar.gz'), 'w:gz') as tar_file: |
|
|
|
for folderName, subfolders, filenames in os.walk(os.path.join(QUELLE, FOLDER)): |
|
|
|
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(QUELLE + '/', '') |
|
|
|
folderShort = folderName.replace(source + '/', '') |
|
|
|
# create complete filepath of file in directory |
|
|
|
filePath = os.path.join(folderName, filename) |
|
|
|
# Add file to zip |
|
|
@ -25,18 +41,18 @@ def tarFolder(): |
|
|
|
tar_file.close() |
|
|
|
|
|
|
|
|
|
|
|
def unzipFolder(): |
|
|
|
zip_file = zipfile.ZipFile(os.path.join(ZIEL, 'temp.zip'), 'r') |
|
|
|
zip_file.extractall(path=os.path.join(ZIEL, 'liste')) |
|
|
|
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(): |
|
|
|
with zipfile.ZipFile(os.path.join(ZIEL, 'temp.zip'), 'w') as zip_file: |
|
|
|
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(QUELLE, FOLDER)): |
|
|
|
for folderName, subfolders, filenames in os.walk(os.path.join(source, sourceFolder)): |
|
|
|
for filename in filenames: |
|
|
|
folderShort = folderName.replace(QUELLE+'/', '') |
|
|
|
folderShort = folderName.replace(source+'/', '') |
|
|
|
# create complete filepath of file in directory |
|
|
|
filePath = os.path.join(folderName, filename) |
|
|
|
# Add file to zip |
|
|
@ -44,8 +60,3 @@ def zipFolder(): |
|
|
|
zip_file.close() |
|
|
|
return "" |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
zipFolder() |
|
|
|
unzipFolder() |
|
|
|
tarFolder() |
|
|
|
untarFolder() |
|
|
|