diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 0a8dc935..cb507900 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -5,12 +5,13 @@ releases: - action: Updated details: - "no verbose for error, -v for warning, -vv for warning+info, -vvv for warning+info+debug" + - "`#351`, show template plugin name, i.e. 'copying' for copy instead of 'templating'" - action: Removed details: - "Message: 'Warning: Attempting to use environment vars as data...' became warning log" - "Message: 'Warning: Both data.yml and /.../.moban.cd/data.yml does not exist' became warning log" - "with -v, you would see them in such a situation" - date: tbd + date: 1.12.2019 version: 0.6.7 - changes: - action: Added diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 5cd45db7..43591b40 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -6,7 +6,7 @@ contact: wangc_2011@hotmail.com license: MIT version: 0.6.7 current_version: 0.6.7 -release: 0.6.6 +release: 0.6.7 branch: master master: index command_line_interface: "moban" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 06184ad4..612dafce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,13 +1,15 @@ Change log ================================================================================ -0.6.7 - tbd +0.6.7 - 1.12.2019 -------------------------------------------------------------------------------- **Updated** #. no verbose for error, -v for warning, -vv for warning+info, -vvv for warning+info+debug +#. `#351 `_, show template plugin + name, i.e. 'copying' for copy instead of 'templating' **Removed** diff --git a/README.rst b/README.rst index da4bffaa..f4cf979c 100644 --- a/README.rst +++ b/README.rst @@ -26,8 +26,6 @@ moban - 模板 Any template, any data in any location :Author: C.W. and its contributors (See contributors.rst) :Issues: http://github.com/moremoban/moban/issues :License: MIT -:Version: |version| -:Generated: |today| **moban** started with bringing the high performance template engine (JINJA2) for web @@ -82,8 +80,6 @@ Quick start $ export HELLO="world" $ moban "{{HELLO}}" - Warning: Both data.yml and /.../.moban.cd/data.yml does not exist - Warning: Attempting to use environment vars as data... Templating {{HELLO}}... to moban.output Templated 1 file. $ cat moban.output @@ -244,7 +240,7 @@ CLI documentation --exit-code tell moban to change exit code -V, --version show program's version number and exit - -v show verbose, try -v, -vv + -v show verbose, try -v, -vv, -vvv Exit codes -------------------------------------------------------------------------------- diff --git a/docs/conf.py b/docs/conf.py index ac7fdf1d..19387fcc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,7 @@ # The short X.Y version version = '0.6.7' # The full version, including alpha/beta/rc tags -release = '0.6.6' +release = '0.6.7' # -- General configuration --------------------------------------------------- diff --git a/moban/constants.py b/moban/constants.py index 2f8f3f4c..dd0300cc 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -75,6 +75,10 @@ LABEL_FORCE_TEMPLATE_TYPE = "force_template_type" LABEL_TEMPLATE_TYPES = "template_types" LABEL_VERBOSE = "verbose" +LABEL_MOBAN_ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Mobanizing" +LABEL_MOBAN_ACTION_IN_PAST_TENSE = "Mobanized" +LABEL_MOBAN_ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Mobanizing" +LABEL_MOBAN_ACTION_IN_PAST_TENSE = "Mobanized" # error messages ERROR_DATA_FILE_NOT_FOUND = "Both %s and %s does not exist" diff --git a/moban/core/moban_factory.py b/moban/core/moban_factory.py index 101394ce..566aebed 100644 --- a/moban/core/moban_factory.py +++ b/moban/core/moban_factory.py @@ -15,7 +15,7 @@ from moban.core.hashstore import HASH_STORE from moban.externals.buffered_writer import BufferedWriter -log = logging.getLogger(__name__) +LOG = logging.getLogger(__name__) PY3_ABOVE = sys.version_info[0] > 2 @@ -29,7 +29,7 @@ def register_extensions(self, extensions): for user_template_type in extensions.keys(): template_type = self.get_primary_key(user_template_type) - log.debug( + LOG.debug( "Registering extensions: {0}={1}".format( user_template_type, extensions[user_template_type] ) @@ -92,14 +92,26 @@ def __init__(self, template_fs, context_dirs, engine): self.templated_count = 0 self.file_count = 0 self.buffered_writer = BufferedWriter() + self.engine_action = getattr( + engine, + "ACTION_IN_PRESENT_CONTINUOUS_TENSE", + constants.LABEL_MOBAN_ACTION_IN_PRESENT_CONTINUOUS_TENSE, + ) + self.engine_actioned = getattr( + engine, + "ACTION_IN_PAST_TENSE", + constants.LABEL_MOBAN_ACTION_IN_PAST_TENSE, + ) def report(self): if self.templated_count == 0: reporter.report_no_action() elif self.templated_count == self.file_count: - reporter.report_full_run(self.file_count) + reporter.report_full_run(self.engine_actioned, self.file_count) else: - reporter.report_partial_run(self.templated_count, self.file_count) + reporter.report_partial_run( + self.engine_actioned, self.templated_count, self.file_count + ) def number_of_templated_files(self): return self.templated_count @@ -119,7 +131,9 @@ def render_to_file(self, template_file, data_file, output_file): template_abs_path, template, data, output_file ) if flag: - reporter.report_templating(template_file, output_file) + reporter.report_templating( + self.engine_action, template_file, output_file + ) self.templated_count += 1 self.buffered_writer.close() @@ -133,7 +147,9 @@ def render_string_to_file( template_abs_path, template, data, output_file ) if flag: - reporter.report_templating(template_abs_path, output_file) + reporter.report_templating( + self.engine_action, template_abs_path, output_file + ) self.templated_count += 1 self.buffered_writer.close() @@ -159,7 +175,7 @@ def apply_template(self, template_abs_path, template, data, output_file): return flag except exceptions.FileNotFound: # the template is a string from command line - log.info("{} is not a file".format(template_abs_path)) + LOG.info("{} is not a file".format(template_abs_path)) self.buffered_writer.write_file_out(output_file, rendered_content) return True @@ -186,7 +202,9 @@ def _render_with_finding_template_first(self, template_file_index): template_abs_path, template, data, output ) if flag: - reporter.report_templating(template_file, output) + reporter.report_templating( + self.engine_action, template_file, output + ) self.templated_count += 1 self.file_count += 1 @@ -202,13 +220,15 @@ def _render_with_finding_data_first(self, data_file_index): template_abs_path, template, data, output ) if flag: - reporter.report_templating(template_file, output) + reporter.report_templating( + self.engine_action, template_file, output + ) self.templated_count += 1 self.file_count += 1 def expand_template_directories(dirs): - log.debug("Expanding %s..." % dirs) + LOG.debug("Expanding %s..." % dirs) if not isinstance(dirs, list): dirs = [dirs] @@ -217,7 +237,7 @@ def expand_template_directories(dirs): def expand_template_directory(directory): - log.debug("Expanding %s..." % directory) + LOG.debug("Expanding %s..." % directory) translated_directory = None if ":" in directory and directory[1] != ":" and "://" not in directory: translated_directory = deprecated_moban_path_notation(directory) diff --git a/moban/externals/reporter.py b/moban/externals/reporter.py index 87002ee5..101f61c5 100644 --- a/moban/externals/reporter.py +++ b/moban/externals/reporter.py @@ -2,11 +2,11 @@ import moban.constants as constants -MESSAGE_TEMPLATING = "Templating {0} to {1}" +MESSAGE_TEMPLATING = "{0} {1} to {2}" MESSAGE_UP_TO_DATE = "Everything is up to date!" -MESSAGE_NO_TEMPLATING = "No templating" -MESSAGE_REPORT = "Templated {0} out of {1} files." -MESSAGE_TEMPLATED_ALL = "Templated {0} files." +MESSAGE_NO_TEMPLATING = "No actions performed" +MESSAGE_REPORT = "{0} {1} out of {2} files." +MESSAGE_TEMPLATED_ALL = "{0} {1} files." MESSAGE_PULLING_REPO = "Updating {0}..." MESSAGE_CLONING_REPO = "Cloning {0}..." MESSAGE_TEMPLATE_NOT_IN_MOBAN_FILE = "{0} is not defined in your moban file!" @@ -14,10 +14,14 @@ type" -def report_templating(source_file, destination_file): +def report_templating( + action_in_present_continuous_tense, source_file, destination_file +): print( MESSAGE_TEMPLATING.format( - crayons.yellow(source_file), crayons.green(destination_file) + action_in_present_continuous_tense, + crayons.yellow(source_file), + crayons.green(destination_file), ) ) @@ -26,16 +30,16 @@ def report_no_action(): print(crayons.yellow(MESSAGE_NO_TEMPLATING, bold=True)) -def report_full_run(file_count): +def report_full_run(action_in_past_tense, file_count): figure = crayons.green(str(file_count), bold=True) - message = MESSAGE_TEMPLATED_ALL.format(figure) + message = MESSAGE_TEMPLATED_ALL.format(action_in_past_tense, figure) print(_format_single(message, file_count)) -def report_partial_run(file_count, total): +def report_partial_run(action_in_past_tense, file_count, total): figure = crayons.green(str(file_count), bold=True) total_figure = crayons.yellow(str(total), bold=True) - message = MESSAGE_REPORT.format(figure, total_figure) + message = MESSAGE_REPORT.format(action_in_past_tense, figure, total_figure) print(_format_single(message, total)) diff --git a/moban/main.py b/moban/main.py index 8a55d0e9..ed7abf5a 100644 --- a/moban/main.py +++ b/moban/main.py @@ -28,12 +28,7 @@ from io import StringIO LOG = logging.getLogger() -LOG_LEVEL = [ - logging.ERROR, - logging.WARNING, - logging.INFO, - logging.DEBUG, -] +LOG_LEVEL = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG] def main(): @@ -175,7 +170,7 @@ def create_parser(): action="count", dest=constants.LABEL_VERBOSE, default=0, - help="show verbose, try -v, -vv", + help="show verbose, try -v, -vv, -vvv", ) return parser diff --git a/moban/plugins/copy.py b/moban/plugins/copy.py index 455c9227..d92d1473 100644 --- a/moban/plugins/copy.py +++ b/moban/plugins/copy.py @@ -21,6 +21,9 @@ class ContentForwardEngine(object): templating mechanism. """ + ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Copying" + ACTION_IN_PAST_TENSE = "Copied" + def __init__(self, template_fs, extensions=None): self.template_fs = template_fs diff --git a/moban/plugins/jinja2/engine.py b/moban/plugins/jinja2/engine.py index 88080157..507d33e3 100644 --- a/moban/plugins/jinja2/engine.py +++ b/moban/plugins/jinja2/engine.py @@ -59,6 +59,10 @@ def __init__(self): constants.TEMPLATE_ENGINE_EXTENSION, tags=["jinja2", "jinja", "jj2", "j2"] ) class Engine(object): + + ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Templating" + ACTION_IN_PAST_TENSE = "Templated" + def __init__(self, template_fs, options=None): """ Contruct a jinja2 template engine diff --git a/setup.py b/setup.py index ac8f1e4d..bff29798 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ "Yet another jinja2 cli command for static text generation" ) URL = "https://github.com/moremoban/moban" -DOWNLOAD_URL = "%s/archive/0.6.6.tar.gz" % URL +DOWNLOAD_URL = "%s/archive/0.6.7.tar.gz" % URL FILES = ["README.rst", "CONTRIBUTORS.rst", "CHANGELOG.rst"] KEYWORDS = [ "python", @@ -97,8 +97,8 @@ } # You do not need to read beyond this line PUBLISH_COMMAND = "{0} setup.py sdist bdist_wheel upload -r pypi".format(sys.executable) -GS_COMMAND = ("gs moban v0.6.6 " + - "Find 0.6.6 in changelog for more details") +GS_COMMAND = ("gs moban v0.6.7 " + + "Find 0.6.7 in changelog for more details") NO_GS_MESSAGE = ("Automatic github release is disabled. " + "Please install gease to enable it.") UPLOAD_FAILED_MSG = ( diff --git a/tests/test_reporter.py b/tests/test_reporter.py index 6450e9b1..ad578a4f 100644 --- a/tests/test_reporter.py +++ b/tests/test_reporter.py @@ -15,17 +15,17 @@ def test_partial_run(): patcher = patch("sys.stdout", new_callable=StringIO) fake_stdout = patcher.start() - reporter.report_partial_run(1, 20) + reporter.report_partial_run("Actioned", 1, 20) patcher.stop() - eq_(fake_stdout.getvalue(), "Templated 1 out of 20 files.\n") + eq_(fake_stdout.getvalue(), "Actioned 1 out of 20 files.\n") def test_full_run(): patcher = patch("sys.stdout", new_callable=StringIO) fake_stdout = patcher.start() - reporter.report_full_run(20) + reporter.report_full_run("Worked on", 20) patcher.stop() - eq_(fake_stdout.getvalue(), "Templated 20 files.\n") + eq_(fake_stdout.getvalue(), "Worked on 20 files.\n") def test_error_message(): @@ -55,9 +55,9 @@ def test_warning_message(): def test_report_templating(): patcher = patch("sys.stdout", new_callable=StringIO) fake_stdout = patcher.start() - reporter.report_templating("a", "b") + reporter.report_templating("Transforming", "a", "b") patcher.stop() - eq_(fake_stdout.getvalue(), "Templating a to b\n") + eq_(fake_stdout.getvalue(), "Transforming a to b\n") def test_no_action(): @@ -65,7 +65,7 @@ def test_no_action(): fake_stdout = patcher.start() reporter.report_no_action() patcher.stop() - eq_(fake_stdout.getvalue(), "No templating\n") + eq_(fake_stdout.getvalue(), "No actions performed\n") def test_format_single():