Skip to content

Commit

Permalink
Fix double stdout fixes #393 (#394)
Browse files Browse the repository at this point in the history
* 🚑 fixes double printing on stdout from template file

fixes #393

* updates changelog and contributors for PR

Co-authored-by: jaska <wangc_2011@hotmail.com>
  • Loading branch information
salotz and chfw authored Aug 15, 2020
1 parent 823ee4e commit be6c38f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
Change log
================================================================================

0.7.10 - unreleased
--------------------------------------------------------------------------------

**Updated**

#. `#393 <https://github.com/moremoban/moban/issues/393>`_: Rendered
content output to stdout twice

0.7.9 - 06.08.2020
--------------------------------------------------------------------------------

**Updated**

#. `#390 <https://github.com/moremoban/moban/issues/390>`_: single render action
will print to stdout by defafult
will print to stdout by default

0.7.8 - 09.06.2020
--------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ In alphabetical order:
* `John Vandenberg <https://github.com/jayvdb>`_
* `Joshua Chung <https://github.com/seeeturtle>`_
* `PRAJWAL M <https://github.com/PrajwalM2212>`_
* `salotz <https://github.com/salotz>`_
* `SerekKiri <https://github.com/SerekKiri>`_
21 changes: 20 additions & 1 deletion moban/core/moban_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,40 @@ def render_string_to_file(
self.buffered_writer.close()

def apply_template(self, template_abs_path, template, data, output_file):

# render the content
rendered_content = self.engine.apply_template(
template, data, output_file
)

# convert to utf8 if not already
if not isinstance(rendered_content, bytes):
rendered_content = rendered_content.encode("utf-8")

# attempt to output to the file and printing to stdout instead
# if not found
try:

# check if any of the files have changed
flag = HASH_STORE.is_file_changed(
output_file, rendered_content, template_abs_path
)

# if they have re-render things
if flag:

# write the content to the output file
self.buffered_writer.write_file_out(
output_file, rendered_content
)
if not file_system.is_zip_alike_url(output_file):

# attempt to copy the file permissions of the template
# file to the output file

# if it isn't an archive proceed or stdout
if (not file_system.is_zip_alike_url(output_file) and
output_file != '-'):

try:
file_system.file_permissions_copy(
template_abs_path, output_file
Expand Down

0 comments on commit be6c38f

Please sign in to comment.