Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
berumuron
Boop
Commits
5c89a252
Commit
5c89a252
authored
Nov 03, 2018
by
berumuron
Browse files
fix: Handle edge cases when dirs don't exist
parent
412c0221
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
5c89a252
__pycache__
README.md
View file @
5c89a252
...
...
@@ -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
```
boop.py
View file @
5c89a252
#!/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__"
:
main
()
print
(
"Boop!"
)
try
:
main
()
print
(
"Boop!"
)
except
ProgramError
as
e
:
print
(
e
.
args
[
0
],
file
=
sys
.
stderr
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment