Skip to content

Commit

Permalink
✨ force template type regardless of individual template types. #165
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Feb 14, 2019
1 parent 6f0a3ea commit bfe57a7
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
configuration:
template_dir:
- template-sources
force_template_type: copy
targets:
- simple.file.copy: file-in-template-sources-folder.txt
- "misc-1-copying/can-create-folder/if-not-exists.txt": file-in-template-sources-folder.txt
- "test-dir": dir-for-copying
- "test-recursive-dir": dir-for-recusive-copying/**
26 changes: 26 additions & 0 deletions docs/level-17-override-template-type-from-moban-file/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Level 17: force template type
================================================================================

Since moban version 0.4.0, you can enforce all targets to use one and only one
template type, regardless of their individual template types.


Here is example moban file for copying::
configuration:
template_dir:
- template-sources
force_template_type: copy
targets:
- simple.file.copy: file-in-template-sources-folder.txt
- "misc-1-copying/can-create-folder/if-not-exists.txt": file-in-template-sources-folder.txt
- "test-dir": dir-for-copying
- "test-recursive-dir": dir-for-recusive-copying/**

More information is documented in `misc-1-copying-template`.


template copy does:

#. copies any template inside pre-declared template directory to anywhere. moban will create directory if needed.
#. copies any directory to anywhere. If "**" is followed, moban attempts to do recursive copying.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dir for copying
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please look at .moban.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
everything is copied
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dest_directory: source_directory/**
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test file
1 change: 1 addition & 0 deletions moban/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
LABEL_ACTION = "action"
LABEL_SOURCE = "source"
LABEL_DEST = "destination"
LABEL_FORCE_TEMPLATE_TYPE = "force_template_type"

# error messages
ERROR_DATA_FILE_NOT_FOUND = "Both %s and %s does not exist"
Expand Down
9 changes: 7 additions & 2 deletions moban/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ def __init__(
):
self.template_file = template_file
self.data_file = data_file
self.output = output
self.original_output = output
self.template_type = template_type
if self.output.endswith(template_type):
if self.original_output.endswith(template_type):
self.output, _ = os.path.splitext(output)

def set_template_type(self, new_template_type):
self.template_type = new_template_type
if self.original_output.endswith(self.template_type):
self.output, _ = os.path.splitext(self.original_output)

def __eq__(self, other):
return (
self.template_file == other.template_file
Expand Down
5 changes: 5 additions & 0 deletions moban/mobanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def handle_targets(merged_options, targets):
list_of_templating_parameters = parse_targets(merged_options, targets)
jobs_for_each_engine = defaultdict(list)
for target in list_of_templating_parameters:
forced_template_type = merged_options.get(
constants.LABEL_FORCE_TEMPLATE_TYPE)
if forced_template_type:
target.set_template_type(forced_template_type)

template_type = target.template_type
primary_template_type = plugins.ENGINES.get_primary_key(template_type)
if primary_template_type is None:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ def test_level_16_group_targets_using_template_type(self):
folder = "level-16-group-targets-using-template-type"
self._raw_moban(["moban"], folder, expected, "simple.file")

def test_level_17_override_template_type_from_moban_file(self):
expected = "test file\n"

folder = "level-17-override-template-type-from-moban-file"
self._raw_moban(["moban"], folder, expected, "simple.file.copy")

def test_misc_1(self):
expected = "test file\n"

Expand Down

0 comments on commit bfe57a7

Please sign in to comment.