mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 09:35:44 +00:00
adding latest
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
Priority:
|
Priority:
|
||||||
☐ Go through code TODOs
|
✔ Go through code TODOs @done(21-10-25 05:52)
|
||||||
☐ Check code order and make sure things are where they should be
|
☐ Check code order and make sure things are where they should be
|
||||||
☐ Document the python/logging/typing in Trilium
|
☐ Document the python/logging/typing in Trilium
|
||||||
☐ Write the tests
|
☐ Write the tests
|
||||||
|
|
||||||
Functionality:
|
Functionality:
|
||||||
☐ a
|
☐ Replace loggers with `click.echo` for command outputs. Keep logging messages for actual logging messages
|
||||||
|
|
||||||
Bug:
|
Bug:
|
||||||
☐ a
|
|
||||||
|
|
||||||
Tests:
|
Tests:
|
||||||
☐ Write tests! @2d
|
☐ Write tests! @2d
|
||||||
|
|||||||
13
tembo/cli.py
13
tembo/cli.py
@@ -16,7 +16,7 @@ def run():
|
|||||||
|
|
||||||
@click.command(options_metavar="<options>")
|
@click.command(options_metavar="<options>")
|
||||||
def list_all():
|
def list_all():
|
||||||
r"""List all names for "tembo new <name>"."""
|
"""List all names for 'tembo new <name>'."""
|
||||||
_all_scopes = [user_scope["name"] for user_scope in tembo.CONFIG.scopes]
|
_all_scopes = [user_scope["name"] for user_scope in tembo.CONFIG.scopes]
|
||||||
tembo.logger.info(
|
tembo.logger.info(
|
||||||
"%s names found in config.yml: '%s'", len(_all_scopes), "', '".join(_all_scopes)
|
"%s names found in config.yml: '%s'", len(_all_scopes), "', '".join(_all_scopes)
|
||||||
@@ -24,7 +24,6 @@ def list_all():
|
|||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
||||||
|
|
||||||
# TODO: organise this so all flags are at the top and in order
|
|
||||||
@click.command(options_metavar="<options>")
|
@click.command(options_metavar="<options>")
|
||||||
@click.argument("scope", metavar="<scope>")
|
@click.argument("scope", metavar="<scope>")
|
||||||
@click.argument(
|
@click.argument(
|
||||||
@@ -44,14 +43,17 @@ def new(scope, inputs, dry_run, example):
|
|||||||
|
|
||||||
Example: tembo new meeting my_presentation
|
Example: tembo new meeting my_presentation
|
||||||
"""
|
"""
|
||||||
|
# get the name from the tembo config.yml
|
||||||
try:
|
try:
|
||||||
_name_found = scope in [
|
_name_found = scope in [
|
||||||
user_scope["name"] for user_scope in tembo.CONFIG.scopes
|
user_scope["name"] for user_scope in tembo.CONFIG.scopes
|
||||||
]
|
]
|
||||||
except TypeError as type_error:
|
except TypeError as type_error:
|
||||||
|
# raise error if no scopes are defined
|
||||||
tembo.logger.critical("No scopes found in config.yml - exiting")
|
tembo.logger.critical("No scopes found in config.yml - exiting")
|
||||||
raise SystemExit(1) from type_error
|
raise SystemExit(1) from type_error
|
||||||
|
|
||||||
|
# get the scope information from the tembo config.yml
|
||||||
try:
|
try:
|
||||||
config_scope = [
|
config_scope = [
|
||||||
(
|
(
|
||||||
@@ -66,9 +68,11 @@ def new(scope, inputs, dry_run, example):
|
|||||||
if user_scope["name"] == scope
|
if user_scope["name"] == scope
|
||||||
]
|
]
|
||||||
except KeyError as key_error:
|
except KeyError as key_error:
|
||||||
|
# raise error if any non optional keys are missing
|
||||||
tembo.logger.critical("Key %s not found in config.yml - exiting", key_error)
|
tembo.logger.critical("Key %s not found in config.yml - exiting", key_error)
|
||||||
raise SystemExit(1) from key_error
|
raise SystemExit(1) from key_error
|
||||||
|
|
||||||
|
# print the example to the user
|
||||||
if example:
|
if example:
|
||||||
tembo.logger.info(
|
tembo.logger.info(
|
||||||
"Example for 'tembo new %s': %s",
|
"Example for 'tembo new %s': %s",
|
||||||
@@ -79,6 +83,7 @@ def new(scope, inputs, dry_run, example):
|
|||||||
)
|
)
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
||||||
|
# if the name is in the config.yml, create the scoped page
|
||||||
if _name_found:
|
if _name_found:
|
||||||
scoped_page = pages.ScopedPageCreator().create_page(
|
scoped_page = pages.ScopedPageCreator().create_page(
|
||||||
base_path=str(tembo.CONFIG.base_path),
|
base_path=str(tembo.CONFIG.base_path),
|
||||||
@@ -92,8 +97,11 @@ def new(scope, inputs, dry_run, example):
|
|||||||
scoped_page.save_to_disk(dry_run=dry_run)
|
scoped_page.save_to_disk(dry_run=dry_run)
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
if not _name_found and len(tembo.CONFIG.scopes) > 0:
|
if not _name_found and len(tembo.CONFIG.scopes) > 0:
|
||||||
|
# if the name is missing in the config.yml, raise error
|
||||||
tembo.logger.warning("Command %s not found in config.yml - exiting", scope)
|
tembo.logger.warning("Command %s not found in config.yml - exiting", scope)
|
||||||
raise SystemExit(0)
|
raise SystemExit(0)
|
||||||
|
|
||||||
|
# raise error if no config.yml found
|
||||||
tembo.logger.critical(
|
tembo.logger.critical(
|
||||||
"No config.yml found in %s - exiting", tembo.CONFIG.config_path
|
"No config.yml found in %s - exiting", tembo.CONFIG.config_path
|
||||||
)
|
)
|
||||||
@@ -105,7 +113,6 @@ run.add_command(list_all)
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# BUG: fix this bug where input tokens are mismatched
|
|
||||||
# new(["meeting", "robs presentation", "meeting on gcp"])
|
# new(["meeting", "robs presentation", "meeting on gcp"])
|
||||||
new(["meeting", "a", "b", "c", "d", "--example"])
|
new(["meeting", "a", "b", "c", "d", "--example"])
|
||||||
# new(["meeting", "robs presentation"])
|
# new(["meeting", "robs presentation"])
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import re
|
|||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
import jinja2
|
import jinja2
|
||||||
|
from jinja2.exceptions import TemplateNotFound
|
||||||
import pendulum
|
import pendulum
|
||||||
|
|
||||||
import tembo
|
import tembo
|
||||||
@@ -62,7 +63,14 @@ class PageCreator:
|
|||||||
file_loader = jinja2.FileSystemLoader(template_path)
|
file_loader = jinja2.FileSystemLoader(template_path)
|
||||||
env = jinja2.Environment(loader=file_loader, autoescape=True)
|
env = jinja2.Environment(loader=file_loader, autoescape=True)
|
||||||
# load the template contents
|
# load the template contents
|
||||||
loaded_template = env.get_template(template_filename)
|
try:
|
||||||
|
loaded_template = env.get_template(template_filename)
|
||||||
|
except TemplateNotFound as template_not_found:
|
||||||
|
tembo.logger.critical(
|
||||||
|
"Template file %s not found - exiting",
|
||||||
|
str(template_path) + "/" + str(template_not_found.message),
|
||||||
|
)
|
||||||
|
raise SystemExit(1) from template_not_found
|
||||||
return loaded_template.render()
|
return loaded_template.render()
|
||||||
|
|
||||||
|
|
||||||
@@ -90,7 +98,7 @@ class ScopedPageCreator(PageCreator):
|
|||||||
self.extension = extension
|
self.extension = extension
|
||||||
|
|
||||||
# verify the user input length matches the number of input tokens in the
|
# verify the user input length matches the number of input tokens in the
|
||||||
# tembo.config/templates
|
# tembo config/templates
|
||||||
self._all_input_tokens = self._get_input_tokens(template_filename)
|
self._all_input_tokens = self._get_input_tokens(template_filename)
|
||||||
self._verify_input_tokens(user_input)
|
self._verify_input_tokens(user_input)
|
||||||
|
|
||||||
@@ -146,10 +154,6 @@ class ScopedPageCreator(PageCreator):
|
|||||||
name: str,
|
name: str,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""For a tokened string, substitute input, name and date tokens."""
|
"""For a tokened string, substitute input, name and date tokens."""
|
||||||
# TODO: fn to get tokens from file and template
|
|
||||||
# tokenified_string = self.__substitute_input_tokens(
|
|
||||||
# tokenified_string, user_input, input_token_type
|
|
||||||
# )
|
|
||||||
tokenified_string = self.__substitute_input_tokens(
|
tokenified_string = self.__substitute_input_tokens(
|
||||||
tokenified_string, user_input
|
tokenified_string, user_input
|
||||||
)
|
)
|
||||||
@@ -163,6 +167,7 @@ class ScopedPageCreator(PageCreator):
|
|||||||
user_input: Tuple[str, ...] | Tuple[()],
|
user_input: Tuple[str, ...] | Tuple[()],
|
||||||
) -> str:
|
) -> str:
|
||||||
for input_value, extracted_token in zip(user_input, self._all_input_tokens):
|
for input_value, extracted_token in zip(user_input, self._all_input_tokens):
|
||||||
|
# REVIEW: test this for spaces in the filename/input token
|
||||||
tokenified_string = tokenified_string.replace(
|
tokenified_string = tokenified_string.replace(
|
||||||
extracted_token, input_value.replace(" ", "_")
|
extracted_token, input_value.replace(" ", "_")
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user