Skip to content

Instantly share code, notes, and snippets.

@astyfx
Forked from moomoohk/generate_build.py
Created July 19, 2016 06:26
Show Gist options
  • Save astyfx/517b343fccb6f1fd3556e46178b5beb2 to your computer and use it in GitHub Desktop.
Save astyfx/517b343fccb6f1fd3556e46178b5beb2 to your computer and use it in GitHub Desktop.
Cactus (http://cactusformac.com/) plugin that generates an external build folder that doesn't overwrite your git files. Perfect for usage with GitHub pages, just stick your .git in the generated build folder.
import distutils.dir_util
import shutil
import os
def copytree(src, dst):
for item in os.listdir(src):
s, d = os.path.join(src, item), os.path.join(dst, item)
if os.path.isdir(s):
shutil.copytree(s, d, False, None)
else:
shutil.copy2(s, d)
def postBuild(site):
build_folder = site._path + "/build"
for sub_file in os.listdir(build_folder):
if sub_file[0] != ".":
sub_file_path = os.path.join(build_folder, sub_file)
try:
if os.path.isfile(sub_file_path):
os.unlink(sub_file_path)
elif os.path.isdir(sub_file_path):
shutil.rmtree(sub_file_path)
except Exception, e:
print e
copytree(site.build_path, build_folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment