adding latest

This commit is contained in:
2021-11-01 14:11:20 +00:00
parent 9b277b2931
commit a4df50f77a
5 changed files with 73 additions and 38 deletions

View File

@@ -121,9 +121,28 @@ def new(scope, inputs, dry_run, example):
except exceptions.TemplateFileNotFoundError as template_file_not_found_error:
tembo.logger.critical(template_file_not_found_error.args[0])
raise SystemExit(1) from template_file_not_found_error
except exceptions.MismatchedTokenError as mismatched_token_error:
if config_scope["example"] is not None:
tembo.logger.critical(
"Your tembo config.yml/template specifies %s input tokens, you gave %s. Example: %s",
mismatched_token_error.expected,
mismatched_token_error.given,
config_scope["example"],
)
raise SystemExit(1) from mismatched_token_error
tembo.logger.critical(
"Your tembo config.yml/template specifies %s input tokens, you gave %s",
mismatched_token_error.expected,
mismatched_token_error.given,
)
raise SystemExit(1) from mismatched_token_error
if dry_run:
click.echo(cli_message(f"{scoped_page.path} will be created"))
raise SystemExit(0)
try:
scoped_page.save_to_disk(dry_run=dry_run)
scoped_page.save_to_disk()
raise SystemExit(0)
except exceptions.ScopedPageAlreadyExists as scoped_page_already_exists:
cli_message(f"File {scoped_page_already_exists}")
@@ -150,7 +169,7 @@ run.add_command(list_all)
if __name__ == "__main__":
# new(["meeting", "robs presentation", "meeting on gcp"])
new(["meeting", "a", "b", "c", "d"])
new(["meeting", "a", "b", "c", "d", "e"])
# new(["meeting", "robs presentation"])
# pyinstaller

View File

@@ -2,7 +2,10 @@
class MismatchedTokenError(Exception):
pass
def __init__(self, expected: int, given: int) -> None:
self.expected = expected
self.given = given
super().__init__()
class BasePathDoesNotExistError(Exception):

View File

@@ -154,35 +154,16 @@ class ScopedPageCreator(PageCreator):
def _verify_input_tokens(self) -> None:
if len(self._all_input_tokens) > 0 and self.options.user_input is None:
if self.options.example is not None:
tembo.logger.critical(
"Your tembo.config/template specifies %s input tokens, you gave 0. Example command: %s",
len(self._all_input_tokens),
self.options.example,
)
else:
tembo.logger.critical(
"Your tembo.config/template specifies %s input tokens, you gave 0.",
len(self._all_input_tokens),
)
raise SystemExit(1)
raise exceptions.MismatchedTokenError(
expected=len(self._all_input_tokens), given=0
)
if self.options.user_input is None:
return
if len(self._all_input_tokens) != len(self.options.user_input):
if self.options.example is not None:
tembo.logger.critical(
"Your tembo.config/template specifies %s input tokens, you gave %s. Example command: %s",
len(self._all_input_tokens),
len(self.options.user_input),
self.options.example,
)
else:
tembo.logger.critical(
"Your tembo.config/template specifies %s input tokens, you gave %s.",
len(self._all_input_tokens),
len(self.options.user_input),
)
raise SystemExit(1)
raise exceptions.MismatchedTokenError(
expected=len(self._all_input_tokens),
given=len(self.options.user_input),
)
return
def _substitute_tokens(self, tokenified_string: str) -> str:
@@ -236,7 +217,7 @@ class Page(metaclass=ABCMeta):
raise NotImplementedError
@abstractmethod
def save_to_disk(self, dry_run: bool) -> None:
def save_to_disk(self) -> None:
raise NotImplementedError
@@ -261,7 +242,7 @@ class ScopedPage(Page):
def __str__(self) -> str:
return f"ScopedPage({self.path})"
def save_to_disk(self, dry_run: bool = False) -> None:
def save_to_disk(self) -> None:
"""Save the scoped page to disk and write the `page_content`.
If the page already exists a message will be logged to stdout and no file
@@ -279,16 +260,13 @@ class ScopedPage(Page):
"""
# TODO: move this functionality to the CLI so the page is created and the message
# returned to the user from the CLI.
if dry_run:
tembo.logger.info("%s will be created", self.path)
raise SystemExit(0)
# create the parent directories
scoped_note_file = pathlib.Path(self.path)
scoped_note_file.parents[0].mkdir(parents=True, exist_ok=True)
if scoped_note_file.exists():
scoped_page_file = pathlib.Path(self.path)
scoped_page_file.parents[0].mkdir(parents=True, exist_ok=True)
if scoped_page_file.exists():
raise exceptions.ScopedPageAlreadyExists(f"{self.path} already exists")
with scoped_note_file.open("w", encoding="utf-8") as scoped_page:
with scoped_page_file.open("w", encoding="utf-8") as scoped_page:
scoped_page.write(self.page_content)
# TODO: pass this back somehow
tembo.logger.info("Saved %s to disk", self.path)