def copy_content(src_dir, dst_dir): "Copy content of the src_dir to dst_dir recursively." for entry in os.listdir(src_dir): src = os.path.join(src_dir, entry) dst = os.path.join(dst_dir, entry) if os.path.isdir(src): fileutil.rmtree_if_exists(dst) shutil.copytree(src, dst) else: shutil.copyfile(src, dst)
def extract(archive, filenames, dest, archive_dir, **kwargs): dest = os.path.join(project_dir, dest) if kwargs.get('clean'): fileutil.rmtree_if_exists(dest) os.mkdir(dest) for filename in filenames: dest_path = os.path.join(dest, filename) if filename.endswith('/'): if not os.path.exists(dest_path): os.mkdir(dest_path) continue with archive.open(archive_dir + filename) as src: with open(dest_path, 'w') as dst: copyfile(src, dst)
#!/usr/bin/env python # This script builds the HTML documentation and commits it to the # ampl.github.io repository. import os, shutil from subprocess import call, check_call from glob import glob from fileutil import rmtree_if_exists REPO = 'ampl.github.io' rmtree_if_exists('html') rmtree_if_exists(REPO) check_call(['cmake', '.']) check_call(['make', 'doc']) # Clone the repo and remove generated content. check_call(['git', 'clone', '[email protected]:ampl/' + REPO + '.git']) for entry in glob(REPO + '/*'): basename = os.path.basename(entry) if basename == 'demo' or basename == 'ampl-book.pdf': continue if os.path.isdir(entry): shutil.rmtree(entry) else: os.remove(entry) # Recursively copy an entire directory tree rooted at src. # A directory with the same basename as src is created in dst # which must name an existing directory.