Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. import os
  2. import tempfile
  3. import shutil
  4. from subprocess import Popen, PIPE, CREATE_NEW_CONSOLE
  5.  
  6. def compress(output_file, directory):
  7.   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)
  8.   process.communicate()
  9.   exit_code = process.wait()
  10.   if (exit_code != 0):
  11.     print ("Copression of " + directory + " failed")
  12.   else:
  13.     print ("Copressed " + directory + " to " + output_file)
  14.  
  15. rootdir = os.getcwd()
  16.  
  17. for root,dirs,files in os.walk(rootdir, topdown=True):
  18.     depth = root[len(rootdir) + len(os.path.sep):].count(os.path.sep)
  19.     if depth > 3:
  20.       dirs[:] = [] # Don't recurse any deeper
  21.       continue
  22.  
  23.     for dir in dirs:
  24.       if "archive" in dir:
  25.         path = os.path.join(root, dir)
  26.         print ("Found: ", path)
  27.         if len(os.listdir(path) ) != 0:
  28.           temp_archive = tempfile.mktemp() + ".7z"
  29.           final_archive = root + os.path.sep + dir + os.path.sep + "LastBuildOutput.7z"
  30.  
  31.           compress(temp_archive, path)
  32.           shutil.move(temp_archive, final_archive)
  33.           print("Moved " + temp_archive + " to " + final_archive)
  34.         else:
  35.           print ("Skipping " + path + " as directory is empty")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement