Skip to content

Instantly share code, notes, and snippets.

@minacle
Created May 26, 2014 22:40
Show Gist options
  • Save minacle/eb82104271d0773c9bdd to your computer and use it in GitHub Desktop.
Save minacle/eb82104271d0773c9bdd to your computer and use it in GitHub Desktop.
import sys, os, shutil
from compileall import compile_dir
# libpath destpath
if len(sys.argv) < 3:
print("need more arguments.")
os._exit(1)
os.chdir(sys.argv[1])
cwd = os.getcwd()
compile_dir(cwd, ddir="", force=True, legacy=True)
dest = sys.argv[2]
if not os.path.exists(dest):
os.mkdir(dest)
for root, dirs, files in os.walk(cwd):
if "__pycache__" in dirs:
dirs.remove("__pycache__")
for file in files:
if os.path.splitext(file)[1] == ".pyc":
a = os.path.join(root, file)
r = os.path.relpath(a, cwd)
d = os.path.join(dest, r)
p = os.path.dirname(d)
os.makedirs(p, exist_ok=True)
shutil.move(a, d)
print("done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment