Skip to content

Commit 053b242

Browse files
authored
Verbose template plugin name in mobanizing (#352)
* ✨ Copy engine to have 'Copying'. * ✨ add jinja2 template action and past tense verb * 💚 update unit tests * 📚 update documentation * 📚 update docs * 🔨 code refactoring * 📚 update change log * ✨ prepare for 0.6.7 release
1 parent 8dae1d9 commit 053b242

File tree

13 files changed

+76
-47
lines changed

13 files changed

+76
-47
lines changed

.moban.cd/changelog.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ releases:
55
- action: Updated
66
details:
77
- "no verbose for error, -v for warning, -vv for warning+info, -vvv for warning+info+debug"
8+
- "`#351`, show template plugin name, i.e. 'copying' for copy instead of 'templating'"
89
- action: Removed
910
details:
1011
- "Message: 'Warning: Attempting to use environment vars as data...' became warning log"
1112
- "Message: 'Warning: Both data.yml and /.../.moban.cd/data.yml does not exist' became warning log"
1213
- "with -v, you would see them in such a situation"
13-
date: tbd
14+
date: 1.12.2019
1415
version: 0.6.7
1516
- changes:
1617
- action: Added

.moban.cd/moban.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ contact: wangc_2011@hotmail.com
66
license: MIT
77
version: 0.6.7
88
current_version: 0.6.7
9-
release: 0.6.6
9+
release: 0.6.7
1010
branch: master
1111
master: index
1212
command_line_interface: "moban"

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
Change log
22
================================================================================
33

4-
0.6.7 - tbd
4+
0.6.7 - 1.12.2019
55
--------------------------------------------------------------------------------
66

77
**Updated**
88

99
#. no verbose for error, -v for warning, -vv for warning+info, -vvv for
1010
warning+info+debug
11+
#. `#351 <https://github.com/moremoban/moban/issues/351>`_, show template plugin
12+
name, i.e. 'copying' for copy instead of 'templating'
1113

1214
**Removed**
1315

README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ moban - 模板 Any template, any data in any location
2626
:Author: C.W. and its contributors (See contributors.rst)
2727
:Issues: http://github.com/moremoban/moban/issues
2828
:License: MIT
29-
:Version: |version|
30-
:Generated: |today|
3129

3230

3331
**moban** started with bringing the high performance template engine (JINJA2) for web
@@ -82,8 +80,6 @@ Quick start
8280
8381
$ export HELLO="world"
8482
$ moban "{{HELLO}}"
85-
Warning: Both data.yml and /.../.moban.cd/data.yml does not exist
86-
Warning: Attempting to use environment vars as data...
8783
Templating {{HELLO}}... to moban.output
8884
Templated 1 file.
8985
$ cat moban.output
@@ -244,7 +240,7 @@ CLI documentation
244240
245241
--exit-code tell moban to change exit code
246242
-V, --version show program's version number and exit
247-
-v show verbose, try -v, -vv
243+
-v show verbose, try -v, -vv, -vvv
248244
249245
Exit codes
250246
--------------------------------------------------------------------------------

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# The short X.Y version
2828
version = '0.6.7'
2929
# The full version, including alpha/beta/rc tags
30-
release = '0.6.6'
30+
release = '0.6.7'
3131

3232
# -- General configuration ---------------------------------------------------
3333

moban/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
LABEL_FORCE_TEMPLATE_TYPE = "force_template_type"
7676
LABEL_TEMPLATE_TYPES = "template_types"
7777
LABEL_VERBOSE = "verbose"
78+
LABEL_MOBAN_ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Mobanizing"
79+
LABEL_MOBAN_ACTION_IN_PAST_TENSE = "Mobanized"
80+
LABEL_MOBAN_ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Mobanizing"
81+
LABEL_MOBAN_ACTION_IN_PAST_TENSE = "Mobanized"
7882

7983
# error messages
8084
ERROR_DATA_FILE_NOT_FOUND = "Both %s and %s does not exist"

moban/core/moban_factory.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from moban.core.hashstore import HASH_STORE
1616
from moban.externals.buffered_writer import BufferedWriter
1717

18-
log = logging.getLogger(__name__)
18+
LOG = logging.getLogger(__name__)
1919
PY3_ABOVE = sys.version_info[0] > 2
2020

2121

@@ -29,7 +29,7 @@ def register_extensions(self, extensions):
2929
for user_template_type in extensions.keys():
3030
template_type = self.get_primary_key(user_template_type)
3131

32-
log.debug(
32+
LOG.debug(
3333
"Registering extensions: {0}={1}".format(
3434
user_template_type, extensions[user_template_type]
3535
)
@@ -92,14 +92,26 @@ def __init__(self, template_fs, context_dirs, engine):
9292
self.templated_count = 0
9393
self.file_count = 0
9494
self.buffered_writer = BufferedWriter()
95+
self.engine_action = getattr(
96+
engine,
97+
"ACTION_IN_PRESENT_CONTINUOUS_TENSE",
98+
constants.LABEL_MOBAN_ACTION_IN_PRESENT_CONTINUOUS_TENSE,
99+
)
100+
self.engine_actioned = getattr(
101+
engine,
102+
"ACTION_IN_PAST_TENSE",
103+
constants.LABEL_MOBAN_ACTION_IN_PAST_TENSE,
104+
)
95105

96106
def report(self):
97107
if self.templated_count == 0:
98108
reporter.report_no_action()
99109
elif self.templated_count == self.file_count:
100-
reporter.report_full_run(self.file_count)
110+
reporter.report_full_run(self.engine_actioned, self.file_count)
101111
else:
102-
reporter.report_partial_run(self.templated_count, self.file_count)
112+
reporter.report_partial_run(
113+
self.engine_actioned, self.templated_count, self.file_count
114+
)
103115

104116
def number_of_templated_files(self):
105117
return self.templated_count
@@ -119,7 +131,9 @@ def render_to_file(self, template_file, data_file, output_file):
119131
template_abs_path, template, data, output_file
120132
)
121133
if flag:
122-
reporter.report_templating(template_file, output_file)
134+
reporter.report_templating(
135+
self.engine_action, template_file, output_file
136+
)
123137
self.templated_count += 1
124138
self.buffered_writer.close()
125139

@@ -133,7 +147,9 @@ def render_string_to_file(
133147
template_abs_path, template, data, output_file
134148
)
135149
if flag:
136-
reporter.report_templating(template_abs_path, output_file)
150+
reporter.report_templating(
151+
self.engine_action, template_abs_path, output_file
152+
)
137153
self.templated_count += 1
138154
self.buffered_writer.close()
139155

@@ -159,7 +175,7 @@ def apply_template(self, template_abs_path, template, data, output_file):
159175
return flag
160176
except exceptions.FileNotFound:
161177
# the template is a string from command line
162-
log.info("{} is not a file".format(template_abs_path))
178+
LOG.info("{} is not a file".format(template_abs_path))
163179
self.buffered_writer.write_file_out(output_file, rendered_content)
164180
return True
165181

@@ -186,7 +202,9 @@ def _render_with_finding_template_first(self, template_file_index):
186202
template_abs_path, template, data, output
187203
)
188204
if flag:
189-
reporter.report_templating(template_file, output)
205+
reporter.report_templating(
206+
self.engine_action, template_file, output
207+
)
190208
self.templated_count += 1
191209
self.file_count += 1
192210

@@ -202,13 +220,15 @@ def _render_with_finding_data_first(self, data_file_index):
202220
template_abs_path, template, data, output
203221
)
204222
if flag:
205-
reporter.report_templating(template_file, output)
223+
reporter.report_templating(
224+
self.engine_action, template_file, output
225+
)
206226
self.templated_count += 1
207227
self.file_count += 1
208228

209229

210230
def expand_template_directories(dirs):
211-
log.debug("Expanding %s..." % dirs)
231+
LOG.debug("Expanding %s..." % dirs)
212232
if not isinstance(dirs, list):
213233
dirs = [dirs]
214234

@@ -217,7 +237,7 @@ def expand_template_directories(dirs):
217237

218238

219239
def expand_template_directory(directory):
220-
log.debug("Expanding %s..." % directory)
240+
LOG.debug("Expanding %s..." % directory)
221241
translated_directory = None
222242
if ":" in directory and directory[1] != ":" and "://" not in directory:
223243
translated_directory = deprecated_moban_path_notation(directory)

moban/externals/reporter.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22

33
import moban.constants as constants
44

5-
MESSAGE_TEMPLATING = "Templating {0} to {1}"
5+
MESSAGE_TEMPLATING = "{0} {1} to {2}"
66
MESSAGE_UP_TO_DATE = "Everything is up to date!"
7-
MESSAGE_NO_TEMPLATING = "No templating"
8-
MESSAGE_REPORT = "Templated {0} out of {1} files."
9-
MESSAGE_TEMPLATED_ALL = "Templated {0} files."
7+
MESSAGE_NO_TEMPLATING = "No actions performed"
8+
MESSAGE_REPORT = "{0} {1} out of {2} files."
9+
MESSAGE_TEMPLATED_ALL = "{0} {1} files."
1010
MESSAGE_PULLING_REPO = "Updating {0}..."
1111
MESSAGE_CLONING_REPO = "Cloning {0}..."
1212
MESSAGE_TEMPLATE_NOT_IN_MOBAN_FILE = "{0} is not defined in your moban file!"
1313
MESSAGE_FILE_EXTENSION_NOT_NEEDED = "File extension is not required for ad-hoc\
1414
type"
1515

1616

17-
def report_templating(source_file, destination_file):
17+
def report_templating(
18+
action_in_present_continuous_tense, source_file, destination_file
19+
):
1820
print(
1921
MESSAGE_TEMPLATING.format(
20-
crayons.yellow(source_file), crayons.green(destination_file)
22+
action_in_present_continuous_tense,
23+
crayons.yellow(source_file),
24+
crayons.green(destination_file),
2125
)
2226
)
2327

@@ -26,16 +30,16 @@ def report_no_action():
2630
print(crayons.yellow(MESSAGE_NO_TEMPLATING, bold=True))
2731

2832

29-
def report_full_run(file_count):
33+
def report_full_run(action_in_past_tense, file_count):
3034
figure = crayons.green(str(file_count), bold=True)
31-
message = MESSAGE_TEMPLATED_ALL.format(figure)
35+
message = MESSAGE_TEMPLATED_ALL.format(action_in_past_tense, figure)
3236
print(_format_single(message, file_count))
3337

3438

35-
def report_partial_run(file_count, total):
39+
def report_partial_run(action_in_past_tense, file_count, total):
3640
figure = crayons.green(str(file_count), bold=True)
3741
total_figure = crayons.yellow(str(total), bold=True)
38-
message = MESSAGE_REPORT.format(figure, total_figure)
42+
message = MESSAGE_REPORT.format(action_in_past_tense, figure, total_figure)
3943
print(_format_single(message, total))
4044

4145

moban/main.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@
2828
from io import StringIO
2929

3030
LOG = logging.getLogger()
31-
LOG_LEVEL = [
32-
logging.ERROR,
33-
logging.WARNING,
34-
logging.INFO,
35-
logging.DEBUG,
36-
]
31+
LOG_LEVEL = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
3732

3833

3934
def main():
@@ -175,7 +170,7 @@ def create_parser():
175170
action="count",
176171
dest=constants.LABEL_VERBOSE,
177172
default=0,
178-
help="show verbose, try -v, -vv",
173+
help="show verbose, try -v, -vv, -vvv",
179174
)
180175
return parser
181176

moban/plugins/copy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class ContentForwardEngine(object):
2121
templating mechanism.
2222
"""
2323

24+
ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Copying"
25+
ACTION_IN_PAST_TENSE = "Copied"
26+
2427
def __init__(self, template_fs, extensions=None):
2528
self.template_fs = template_fs
2629

0 commit comments

Comments
 (0)