Commit 9ef8be10 authored by berumuron's avatar berumuron
Browse files

tec: Copy manually files from content to output

First version with shutil was working correctly, but we'll need to
perform specific actions later, depending on files' content.

This commit prepares the future work by copying files one by one.
parent 5c89a252
......@@ -20,13 +20,32 @@ class ProgramError(Exception):
def dir_tree(path):
"""List all the tree directory under the given path.
for filename in os.listdir(path):
full_path = os.path.join(path, filename)
if os.path.isdir(full_path):
for sub_filename in dir_tree(full_path):
yield os.path.join(filename, sub_filename)
yield filename
def mkdirs_for_file(filepath):
"""Create parent directories for a given file.
path = os.path.dirname(filepath)
os.makedirs(path, exist_ok=True)
def main():
# Check that content directory exists on the filesystem
content_path = os.path.join(os.curdir, "content")
if not os.path.isdir(content_path):
raise ProgramError("./content directory does not exist")
# Make sure output dir doesn't exist (shutil will create it after)
# Make sure output dir doesn't exist
output_path = os.path.join(os.curdir, "output")
if os.path.isdir(output_path):
# it should be a directory...
......@@ -36,7 +55,15 @@ def main():
# And copy the files from ./content to ./output
shutil.copytree(content_path, output_path)
for filepath in dir_tree(content_path):
content_filepath = os.path.join(content_path, filepath)
output_filepath = os.path.join(output_path, filepath)
# First we need to create all the parent directories for our file
# Then, we copy content file to its output destination
shutil.copyfile(content_filepath, output_filepath)
if __name__ == "__main__":
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment