Commit 5c89a252 authored by berumuron's avatar berumuron
Browse files

fix: Handle edge cases when dirs don't exist

parent 412c0221
......@@ -30,3 +30,12 @@ $ tree
Yeah, it's kinda too simple for the moment (it only copies the files from
`./content` to `./output`), but new features are coming soon!
## Tests
There are some tests (i.e. doctests) that can be run to check that everything
works smoothly. They can be executed with:
$ python3 -m doctest -v
#!/bin/env python3
import os
import sys
import shutil
class ProgramError(Exception):
"""Exception raised during the program execution.
>>> try:
... raise ProgramError("Oops")
... except ProgramError as e:
... print(e.args[0])
def main():
# Make sure output dir doesn't exist (shutil will create it later)
# 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)
output_path = os.path.join(os.curdir, "output")
if os.path.isdir(output_path):
# it should be a directory...
elif os.path.exists(output_path):
# ... but it also can be a simple file if user created it manually!
# And copy the files from ./content to ./output
input_path = os.path.join(os.curdir, "content")
if os.path.isdir(input_path):
shutil.copytree(input_path, output_path)
shutil.copytree(content_path, output_path)
if __name__ == "__main__":
except ProgramError as e:
print(e.args[0], file=sys.stderr)
Supports Markdown
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