Beispiel #1
0
def zipOptions(input, output, config):
    print "##############  zipOptions  ################"
    zip_options = config.options('zip')
    for key in zip_options:
        zipDir = config.get('zip', key)
        print "##############  zipDir  " + zipDir + "  ################"
        zipName = replaceSprit(zipDir + ".zip")
        zipName = output + zipName.replace("/", "_")
        zf = myZipFile.ZipFile(zipName, 'w')
        for root, dirs, files in os.walk(input + zipDir):
            for fileName in files:
                if fileName != MAC_TEMP:
                    fullPath = replaceSprit(root + "/" + fileName)
                    zipPath = fullPath[fullPath.find(zipDir):]
                    zf.write(fullPath, zipPath, myZipFile.ZIP_DEFLATED)
                    print "ZIP: " + fileName + " ==>> " + zipName + " @@ fullPath = " + fullPath[
                        fullPath.find(zipDir):] + " @@ zipPath = " + zipPath

        zf.close()
        shutil.rmtree(input + zipDir)
Beispiel #2
0
def zipAbsolute(input, output, config):
    print "##############  zipAbsolute  ################"
    absolute_options = config.options('absolute')
    print absolute_options
    for key in absolute_options:
        zipFile = config.get('absolute', key)
        print "##############  zipFile  " + zipFile + "  ################"
        zipName = replaceSprit(
            getDir(zipFile) + "_" + getFileName(zipFile) + ".zip")
        zipName = output + zipName.replace("/", "_")

        fullPath = replaceSprit(input + zipFile)

        if os.path.exists(fullPath):
            zf = myZipFile.ZipFile(zipName, 'w')

            zf.write(fullPath, zipFile, myZipFile.ZIP_DEFLATED)
            print "ZIP: " + zipFile + " ==>> " + zipName

            zf.close()
            os.remove(input + zipFile)
        else:
            print "############## " + zipFile + " not exists  ################"
Beispiel #3
0
def zipOther(input, output):
    print "##############  zipOther  ################"
    if input.endswith("/"):
        input = input[:-1]

    res_root_temp = os.path.basename(input)
    res_root = res_root_temp.replace("_temp", "")

    zipName = replaceSprit(res_root + ".zip")
    zipName = output + zipName.replace("/", "_")
    zf = myZipFile.ZipFile(zipName, 'w')

    for root, dirs, files in os.walk(input):
        for fileName in files:
            if fileName != MAC_TEMP:
                fullPath = replaceSprit(root + "/" + fileName)
                zipPath = fullPath[fullPath.find(res_root_temp):]
                zipPath = zipPath[len(res_root_temp):]

                zf.write(fullPath, zipPath, myZipFile.ZIP_DEFLATED)
                print "ZIP: " + fileName + " ==>> " + zipName + " @@ fullPath = " + fullPath + " @@ zipPath = " + zipPath

    zf.close()
    shutil.rmtree(input)
Beispiel #4
0
def autozipDir(dir, input, output, maxSize, config):
    filelist = os.listdir(input + dir)
    filelist.sort()

    firstLetter = None
    zipCount = None
    zipSize = None
    zipName = None
    zf = None
    UpperTag = '_l'

    index = -2
    listlen = len(filelist)

    for fileName in filelist:
        index += 1

        if fileName != MAC_TEMP:
            fullName = input + dir + "/" + fileName
            if os.path.isfile(fullName):
                firLet = fileName[:1]

                if firstLetter == None:
                    print "*************************"
                    firstLetter = firLet
                    zipCount = 1
                    zipSize = 0

                    if firstLetter == firstLetter.upper():
                        UpperTag = '_U'
                    else:
                        UpperTag = '_l'
                    zipName = replaceSprit(dir + "_" + firstLetter + UpperTag +
                                           "_" + str(zipCount) + ".zip")
                    zipName = output + zipName.replace("/", "_")

                    zf = myZipFile.ZipFile(zipName, 'w')
                elif ((zipSize >= maxSize
                       and notSameName(fileName, filelist[index], config))
                      or firstLetter != firLet):
                    zf.close()

                    if firstLetter != firLet:
                        firstLetter = firLet
                        zipCount = 1
                    else:
                        zipCount = zipCount + 1

                    zipSize = 0

                    if firstLetter == firstLetter.upper():
                        UpperTag = '_U'
                    else:
                        UpperTag = '_l'
                    zipName = replaceSprit(dir + "_" + firstLetter + UpperTag +
                                           "_" + str(zipCount) + ".zip")
                    zipName = output + zipName.replace("/", "_")
                    zf = myZipFile.ZipFile(zipName, 'w')

                fullPath = replaceSprit(fullName)
                zipPath = fullPath[fullPath.find(dir):]
                zf.write(fullPath, zipPath, myZipFile.ZIP_DEFLATED)
                print "ZIP: " + fileName + " ==>> " + zipName + " @@ fullPath = " + fullPath + " @@ zipPath = " + zipPath
                zipSize = zipSize + zf.getinfo(zipPath).compress_size
            else:
                autozipDir(dir + "/" + fileName, input, output, maxSize,
                           config)
    if zf:
        zf.close()
        zf = None

    shutil.rmtree(input + dir)

    if zipSize == 0:
        os.remove(zipName)
Beispiel #5
0
import os, sys
from optparse import OptionParser
import hashlib
import shutil
import re
import myZipFile
import ConfigParser



if __name__ == '__main__':
    print("==================    start    ====================")
    for root, dirs, files in os.walk("output"):
        for fileName in files:
			zf = myZipFile.ZipFile(root + "/" + fileName, 'r')
			for file in zf.namelist():
				zf.extract(file, r".")
				
			zf.close()
    print("==================    end    ====================")