Skip to content

Commit

Permalink
Change make_presentation to use Path
Browse files Browse the repository at this point in the history
  • Loading branch information
humrochagf committed Jan 15, 2021
1 parent c11a44b commit 326e2c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion revelation/cli.py
Expand Up @@ -81,7 +81,7 @@ def mkpresentation(presentation: Path):

echo("Starting a new presentation...")

make_presentation(str(presentation))
make_presentation(presentation)


@cli.command()
Expand Down
22 changes: 9 additions & 13 deletions revelation/utils.py
Expand Up @@ -4,27 +4,23 @@
import shutil
import tarfile
import zipfile
from pathlib import Path
from urllib.request import urlretrieve

from . import default_config


def make_presentation(presentation_path):
def make_presentation(presentation_path: Path):
"""
Make a new presentation boilerplate code given a presentation_path
"""
name = os.path.basename(presentation_path)
# Presentation dir
os.mkdir(presentation_path)
# Media dir
os.mkdir(os.path.join(presentation_path, "media"))
# Config file
config_file = os.path.join(
os.path.dirname(default_config.__file__), "default_config.py"
)
shutil.copy(config_file, os.path.join(presentation_path, "config.py"))
# Slide file
with open(os.path.join(presentation_path, "slides.md"), "w") as fp:
name = presentation_path.name

(presentation_path / "media").mkdir(parents=True)

shutil.copy(default_config.__file__, presentation_path / "config.py")

with (presentation_path / "slides.md").open("w") as fp:
title = name.replace("_", " ").replace("-", " ").title()

fp.write(f"# {title}\n\nStart from here!")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Expand Up @@ -75,7 +75,7 @@ def test_extract_file_on_non_tar_or_zip(tmp_path: Path):
def test_make_presentation(tmp_path: Path):
presentation = Presentation(tmp_path)

make_presentation(str(presentation.root))
make_presentation(presentation.root)

assert presentation.root.is_dir()
assert presentation.file.is_file()
Expand Down

0 comments on commit 326e2c3

Please sign in to comment.