Template refactor (#385)
* Initial implementation of new textx parser for template * Implemented parser as singleton * Moved grammar to .tx file * Added filter templates * Added filter templates * Added tests for nested templates * Added tests for filter+path_sep * Added tests for filter+path_sep * Added punctuation templates * Added hook for --replace-keywords * Updated docs for phototemplate * Updated docs for phototemplate * Updated tests data * Updated tests data * Updated docs for phototemplate * Version bump * Updated CLI help * Fixed template processing for boolean, default
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
""" Automatically update certain sections of README.md for osxphotos """
|
||||
""" Automatically update certain sections of README.md for osxphotos
|
||||
Also updates osxphotos/phototemplate.md
|
||||
"""
|
||||
|
||||
# This is a pretty "dumb" script that searches the README.md for
|
||||
# certain tags, expressed as HTML comments, and replaces text between
|
||||
@@ -14,17 +16,31 @@ from osxphotos.cli import help
|
||||
from osxphotos.phototemplate import (
|
||||
TEMPLATE_SUBSTITUTIONS,
|
||||
TEMPLATE_SUBSTITUTIONS_MULTI_VALUED,
|
||||
FILTER_VALUES,
|
||||
)
|
||||
|
||||
TEMPLATE_HELP = "osxphotos/phototemplate.md"
|
||||
|
||||
USAGE_START = (
|
||||
"<!-- OSXPHOTOS-EXPORT-USAGE:START - Do not remove or modify this section -->"
|
||||
)
|
||||
USAGE_STOP = "<!-- OSXPHOTOS-EXPORT-USAGE:END -->"
|
||||
|
||||
TEMPLATE_TABLE_START = (
|
||||
"<!-- OSXPHOTOS-TEMPLATE-TABLE:START - Do not remove or modify this section -->"
|
||||
)
|
||||
TEMPLATE_TABLE_STOP = "<!-- OSXPHOTOS-TEMPLATE-TABLE:END -->"
|
||||
|
||||
TEMPLATE_HELP_START = (
|
||||
"<!-- OSXPHOTOS-TEMPLATE-HELP:START - Do not remove or modify this section -->"
|
||||
)
|
||||
TEMPLATE_HELP_STOP = "<!-- OSXPHOTOS-TEMPLATE-HELP:END -->"
|
||||
|
||||
TEMPLATE_FILTER_TABLE_START = (
|
||||
"!-- OSXPHOTOS-FILTER-TABLE:START - Do not remove or modify this section -->"
|
||||
)
|
||||
TEMPLATE_FILTER_TABLE_STOP = "<!-- OSXPHOTOS-FILTER-TABLE:END -->"
|
||||
|
||||
|
||||
def generate_template_table():
|
||||
""" generate template substitution table for README.md """
|
||||
@@ -87,17 +103,35 @@ def replace_text(text, start_tag, stop_tag, replacement_text, prefix="", postfix
|
||||
|
||||
def main():
|
||||
""" update README.md """
|
||||
# update phototemplate.md with info on filters
|
||||
print(f"Updating {TEMPLATE_HELP}")
|
||||
filter_help = "\n".join(f"- {f}: {descr}" for f, descr in FILTER_VALUES.items())
|
||||
with open(TEMPLATE_HELP) as file:
|
||||
template_help = file.read()
|
||||
|
||||
with open("README.md", "r") as file:
|
||||
readme = file.read()
|
||||
template_help = replace_text(
|
||||
template_help,
|
||||
TEMPLATE_FILTER_TABLE_START,
|
||||
TEMPLATE_FILTER_TABLE_STOP,
|
||||
filter_help,
|
||||
prefix="\n",
|
||||
postfix="\n",
|
||||
)
|
||||
|
||||
with open(TEMPLATE_HELP, "w") as file:
|
||||
file.write(template_help)
|
||||
|
||||
# update the help text for `osxphotos help export`
|
||||
print("Updating help for `osxphotos help export`")
|
||||
with open("README.md", "r") as file:
|
||||
readme = file.read()
|
||||
help_txt = generate_help_text("export")
|
||||
new_readme = replace_text(
|
||||
readme, USAGE_START, USAGE_STOP, help_txt, prefix="\n```\n", postfix="\n```\n"
|
||||
)
|
||||
|
||||
# update the template substitution table
|
||||
print("Updating template substitution table")
|
||||
template_table = generate_template_table()
|
||||
new_readme = replace_text(
|
||||
new_readme,
|
||||
@@ -108,6 +142,21 @@ def main():
|
||||
postfix="\n",
|
||||
)
|
||||
|
||||
# update the template system docs
|
||||
print("Updating template system help")
|
||||
with open(TEMPLATE_HELP) as fd:
|
||||
template_help = fd.read()
|
||||
|
||||
new_readme = replace_text(
|
||||
new_readme,
|
||||
TEMPLATE_HELP_START,
|
||||
TEMPLATE_HELP_STOP,
|
||||
template_help,
|
||||
prefix="\n",
|
||||
postfix="\n",
|
||||
)
|
||||
|
||||
print("Writing new README.md")
|
||||
with open("README.md", "w") as file:
|
||||
file.write(new_readme)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user