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
6 changes: 6 additions & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: moban
organisation: moremoban
releases:
- changes:
- action: Updated
details:
- "`#265`: Use simple `read binary` to read instead of encoding"
date: 27.05.2019
version: 0.4.4
- changes:
- action: Removed
details:
Expand Down
4 changes: 2 additions & 2 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ organisation: moremoban
author: C. W.
contact: wangc_2011@hotmail.com
license: MIT
version: 0.4.3
current_version: 0.4.3
version: 0.4.4
current_version: 0.4.4
release: 0.4.3
branch: master
master: index
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change log
================================================================================

0.4.4 - 27.05.2019
--------------------------------------------------------------------------------

Updated
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#. `#265 <https://github.com/moremoban/moban/issues/265>`_: Use simple `read
binary` to read instead of encoding

0.4.3 - 16.03.2019
--------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
copyright = '2017-2019 Onni Software Ltd. and its contributors'
author = 'Onni Software Ltd.'
# The short X.Y version
version = '0.4.3'
version = '0.4.4'
# The full version, including alpha/beta/rc tags
release = '0.4.3'

Expand Down
10 changes: 9 additions & 1 deletion docs/level-2-template-inheritance/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ Level 2: template inheritance

Template inheritance is a feature in Jinja2. This example show how it was done.
`a.template` inherits `base.jj2`, which is located in `.moban.td`, the default
template directory.
template directory.


.. warning::

`a.template` could be a symbolic link on Unix/Linux. It will not work if you
template
`a symbolic link on Windows <https://github.com/moremoban/moban/issues/117>`_.
Use symbolic link at your own calculated risk.


Evaluation
Expand Down
7 changes: 7 additions & 0 deletions docs/level-6-complex-configuration/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ default template across `targets`. And in this example, the expand form of
"template": "the template file"
}

.. warning::

`a.template` could be a symbolic link on Unix/Linux. It will not work if you
template
`a symbolic link on Windows <https://github.com/moremoban/moban/issues/117>`_.
Use symbolic link at your own calculated risk.


Evaluation
--------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion moban/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.4.3"
__version__ = "0.4.4"
__author__ = "C. W."
3 changes: 1 addition & 2 deletions moban/copy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from lml.plugin import PluginInfo

import codecs

from moban import utils
from moban import constants
Expand Down Expand Up @@ -30,7 +29,7 @@ def get_template(self, template_file):
real_file_name = utils.find_file_in_template_dirs(
template_file, self.template_dirs
)
with codecs.open(real_file_name, encoding="utf-8") as file_handle:
with open(real_file_name, "rb") as file_handle:
return file_handle.read()

def get_template_from_string(self, string):
Expand Down
7 changes: 6 additions & 1 deletion moban/jinja2/engine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from importlib import import_module

from jinja2 import Template, Environment, FileSystemLoader
Expand Down Expand Up @@ -131,7 +132,7 @@ def apply_template(self, template, data, output):
template.globals["__target__"] = output
template.globals["__template__"] = template.name
rendered_content = template.render(**data)
rendered_content = rendered_content
rendered_content = strip_off_trailing_new_lines(rendered_content)
return rendered_content


Expand All @@ -154,3 +155,7 @@ def import_module_of_extension(extensions):
modules.add(extension.split(".")[0])
for module in modules:
import_module(module)


def strip_off_trailing_new_lines(content):
return re.sub(r"(\n\s+)+$", r"\n", content)
16 changes: 8 additions & 8 deletions moban/plugins/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import logging

from lml.plugin import PluginManager
Expand All @@ -10,6 +11,7 @@
from moban.plugins.strategy import Strategy

log = logging.getLogger(__name__)
PY3_ABOVE = sys.version_info[0] > 2


class MobanFactory(PluginManager):
Expand Down Expand Up @@ -109,22 +111,20 @@ def apply_template(self, template_abs_path, template, data, output_file):
rendered_content = self.engine.apply_template(
template, data, output_file
)
rendered_content = utils.strip_off_trailing_new_lines(rendered_content)
rendered_content = rendered_content.encode("utf-8")
if PY3_ABOVE:
if not isinstance(rendered_content, bytes):
rendered_content = rendered_content.encode("utf-8")

try:
flag = HASH_STORE.is_file_changed(
output_file, rendered_content, template_abs_path
)
if flag:
utils.write_file_out(
output_file, rendered_content, strip=False, encode=False
)
utils.write_file_out(output_file, rendered_content)
utils.file_permissions_copy(template_abs_path, output_file)
return flag
except exceptions.FileNotFound:
utils.write_file_out(
output_file, rendered_content, strip=False, encode=False
)
utils.write_file_out(output_file, rendered_content)
return True

def render_to_files(self, array_of_template_targets):
Expand Down
11 changes: 1 addition & 10 deletions moban/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re
import sys
import stat
import errno
Expand Down Expand Up @@ -60,19 +59,11 @@ def file_permissions(afile):
return stat.S_IMODE(os.stat(afile).st_mode)


def strip_off_trailing_new_lines(content):
return re.sub(r"(\n\s+)+$", r"\n", content)


def write_file_out(filename, content, strip=True, encode=True):
def write_file_out(filename, content):
dest_folder = os.path.dirname(filename)
if dest_folder:
mkdir_p(dest_folder)
with open(filename, "wb") as out:
if strip:
content = strip_off_trailing_new_lines(content)
if encode:
content = content.encode("utf-8")
out.write(content)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

NAME = 'moban'
AUTHOR = 'C. W.'
VERSION = '0.4.3'
VERSION = '0.4.4'
EMAIL = 'wangc_2011@hotmail.com'
LICENSE = 'MIT'
ENTRY_POINTS = {
Expand Down
Loading