Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix 30 #83

Merged
merged 5 commits into from
Jul 14, 2018
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
1 change: 1 addition & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ releases:
- action: Added
details:
- "`#32`: option 1 copy a directory without its subdirectories."
- "`#30`: command line template option is ignore when a moban file is present"
date: pending release
version: 0.2.4
- changes:
Expand Down
1 change: 1 addition & 0 deletions .moban.d/travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{%block custom_python_versions%}
python:
- pypy-5.3.1
- 3.7-dev
- 3.6
- 3.5
- 3.4
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ notifications:
email: false
python:
- pypy-5.3.1
- 3.7-dev
- 3.6
- 3.5
- 3.4
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Added

#. `#32 <https://github.com/moremoban/moban/issues/32>`_: option 1 copy a
directory without its subdirectories.
#. `#30 <https://github.com/moremoban/moban/issues/30>`_: command line template
option is ignore when a moban file is present

0.2.3 - 10-07-2018
--------------------------------------------------------------------------------
Expand Down
10 changes: 3 additions & 7 deletions moban/copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def copy_files(self, file_list):
for dest, src in _iterate_list_of_dicts(file_list):
src_path = self._get_src_file(src)
if src_path is None:
if src.endswith('**'):
if src.endswith("**"):
source_dir = src[:-3]
src_path = self._get_src_file(source_dir)
if src_path:
Expand Down Expand Up @@ -60,9 +60,7 @@ def _copy_dir(self, source, actual_source_path, dest):
self._increment_file_count()
src_file_under_dir = os.path.join(source, file_name)
dest_file_under_dir = os.path.join(dest, file_name)
new_file_pair.append(
{dest_file_under_dir: src_file_under_dir}
)
new_file_pair.append({dest_file_under_dir: src_file_under_dir})
if len(new_file_pair) > 0:
self.copy_files(new_file_pair)

Expand All @@ -72,9 +70,7 @@ def _copy_dir_recursively(self, source, actual_source_path, dest):
self._increment_file_count()
src_file_under_dir = os.path.join(source, file_name)
dest_file_under_dir = os.path.join(dest, file_name)
new_file_pair.append(
{dest_file_under_dir: src_file_under_dir}
)
new_file_pair.append({dest_file_under_dir: src_file_under_dir})
self.copy_files(new_file_pair)

def _copy(self, src_path, dest):
Expand Down
27 changes: 27 additions & 0 deletions moban/mobanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def find_default_moban_file():

def handle_moban_file_v1(moban_file_configurations, command_line_options):
merged_options = None
target = extract_target(command_line_options)
if constants.LABEL_CONFIG in moban_file_configurations:
merged_options = merge(
command_line_options,
Expand All @@ -35,6 +36,10 @@ def handle_moban_file_v1(moban_file_configurations, command_line_options):

targets = moban_file_configurations.get(constants.LABEL_TARGETS)
if targets:
if target:
# if command line option exists, append its template to targets
# issue 30
targets += target
number_of_templated_files = handle_targets(merged_options, targets)
else:
number_of_templated_files = 0
Expand Down Expand Up @@ -101,3 +106,25 @@ def handle_plugin_dirs(plugin_dirs):
for plugin in plugins:
plugin_module = os.path.basename(plugin_dir) + "." + plugin
do_import(plugin_module)


def extract_target(options):
template = options.get(constants.LABEL_TEMPLATE)
config = options.get(constants.LABEL_CONFIG)
output = options.get(constants.LABEL_OUTPUT)
result = []
if template:
if output is None:
raise Exception(
"Please specify a output file name for %s." % template)
if config:
result = [
{
constants.LABEL_TEMPLATE: template,
constants.LABEL_CONFIG: config,
constants.LABEL_OUTPUT: output,
}
]
else:
result = [{output: template}]
return result
45 changes: 45 additions & 0 deletions tests/integration_tests/test_command_line_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,51 @@ def test_single_command(self, fake_template_doer):
],
)

@patch("moban.engine.Engine.render_to_files")
def test_single_command_with_a_few_options(self, fake_template_doer):
test_args = ["moban", "-t", "abc.jj2", "-o", "xyz.output"]
with patch.object(sys, "argv", test_args):
main()
call_args = list(fake_template_doer.call_args[0][0])
eq_(
call_args,
[
("README.rst.jj2", "data.yaml", "README.rst"),
("setup.py.jj2", "data.yaml", "setup.py"),
("abc.jj2", "data.yaml", "xyz.output"),
],
)

@patch("moban.engine.Engine.render_to_files")
def test_single_command_with_options(self, fake_template_doer):
test_args = [
"moban",
"-t",
"abc.jj2",
"-c",
"new.yml",
"-o",
"xyz.output",
]
with patch.object(sys, "argv", test_args):
main()
call_args = list(fake_template_doer.call_args[0][0])
eq_(
call_args,
[
("README.rst.jj2", "new.yml", "README.rst"),
("setup.py.jj2", "new.yml", "setup.py"),
("abc.jj2", "new.yml", "xyz.output"),
],
)

@raises(Exception)
@patch("moban.engine.Engine.render_to_files")
def test_single_command_without_output_option(self, fake_template_doer):
test_args = ["moban", "-t", "abc.jj2"]
with patch.object(sys, "argv", test_args):
main()

def tearDown(self):
os.unlink(self.config_file)
os.unlink(self.data_file)
Expand Down