Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/moremoban/moban/issues/351>`_, show template plugin
name, i.e. 'copying' for copy instead of 'templating'

**Removed**

Expand Down
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
--------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions moban/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 31 additions & 11 deletions moban/core/moban_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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]
)
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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]

Expand All @@ -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)
Expand Down
24 changes: 14 additions & 10 deletions moban/externals/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

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!"
MESSAGE_FILE_EXTENSION_NOT_NEEDED = "File extension is not required for ad-hoc\
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),
)
)

Expand All @@ -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))


Expand Down
9 changes: 2 additions & 7 deletions moban/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions moban/plugins/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions moban/plugins/jinja2/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 = (
Expand Down
14 changes: 7 additions & 7 deletions tests/test_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -55,17 +55,17 @@ 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():
patcher = patch("sys.stdout", new_callable=StringIO)
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():
Expand Down