Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tempfile
- import shutil
- from subprocess import Popen, PIPE, CREATE_NEW_CONSOLE
- def compress(output_file, directory):
- process = Popen(["C:/Program Files/7-Zip/7z.exe", "a", output_file, directory+os.path.sep+"*", "-m0=LZMA2:d128m:fb256", "-aoa", "-mmt=8", "-bb0", "-mx9"], creationflags=CREATE_NEW_CONSOLE)
- process.communicate()
- exit_code = process.wait()
- if (exit_code != 0):
- print ("Copression of " + directory + " failed")
- else:
- print ("Copressed " + directory + " to " + output_file)
- rootdir = os.getcwd()
- for root,dirs,files in os.walk(rootdir, topdown=True):
- depth = root[len(rootdir) + len(os.path.sep):].count(os.path.sep)
- if depth > 3:
- dirs[:] = [] # Don't recurse any deeper
- continue
- for dir in dirs:
- if "archive" in dir:
- path = os.path.join(root, dir)
- print ("Found: ", path)
- if len(os.listdir(path) ) != 0:
- temp_archive = tempfile.mktemp() + ".7z"
- final_archive = root + os.path.sep + dir + os.path.sep + "LastBuildOutput.7z"
- compress(temp_archive, path)
- shutil.move(temp_archive, final_archive)
- print("Moved " + temp_archive + " to " + final_archive)
- else:
- print ("Skipping " + path + " as directory is empty")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement