Commit 5c89a252 authored by Marien Fressinaud's avatar Marien Fressinaud

fix: Handle edge cases when dirs don't exist

parent 412c0221
__pycache__
......@@ -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:
```console
$ python3 -m doctest -v boop.py
```
#!/bin/env python3
import os
import sys
import shutil
class ProgramError(Exception):
"""Exception raised during the program execution.
Examples:
>>> try:
... raise ProgramError("Oops")
... except ProgramError as e:
... print(e.args[0])
Oops
"""
pass
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...
shutil.rmtree(output_path)
elif os.path.exists(output_path):
# ... but it also can be a simple file if user created it manually!
os.remove(output_path)
# 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__":
try:
main()
print("Boop!")
except ProgramError as e:
print(e.args[0], file=sys.stderr)
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