Skip to content

Commit

Permalink
Merge pull request #162 from moremoban/dev
Browse files Browse the repository at this point in the history
release 0.3.8
  • Loading branch information
chfw authored Jan 12, 2019
2 parents f794c20 + bb8c747 commit 234efa4
Show file tree
Hide file tree
Showing 23 changed files with 226 additions and 98 deletions.
8 changes: 8 additions & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: moban
organisation: moremoban
releases:
- changes:
- action: Updated
details:
- "`#141`: disable file permissions copy feature and not to check file permission changes on windows."
- "`#154`: introduce first ever positional argument for string base template."
- "`#157`: the exit code behavior changed. for backward compactibility please use --exit-code. Otherwise, moban will not tell if there is any changes."
date: 12-1-2019
version: 0.3.8
- changes:
- action: Updated
details:
Expand Down
6 changes: 3 additions & 3 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ organisation: moremoban
author: C. W.
contact: wangc_2011@hotmail.com
license: MIT
version: 0.3.7
current_version: 0.3.7
release: 0.3.7
version: 0.3.8
current_version: 0.3.8
release: 0.3.8
branch: master
command_line_interface: "moban"
entry_point: "moban.main:main"
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ python:
- 3.7-dev
- 3.6
- 3.5
- 3.4
- 2.7
before_install:
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install flake8==2.6.2; fi
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Change log
================================================================================

0.3.8 - 12-1-2019
--------------------------------------------------------------------------------

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

#. `#141 <https://github.com/moremoban/moban/issues/141>`_: disable file
permissions copy feature and not to check file permission changes on windows.
#. `#154 <https://github.com/moremoban/moban/issues/154>`_: introduce first ever
positional argument for string base template.
#. `#157 <https://github.com/moremoban/moban/issues/157>`_: the exit code
behavior changed. for backward compactibility please use --exit-code.
Otherwise, moban will not tell if there is any changes.

0.3.7 - 6-1-2019
--------------------------------------------------------------------------------

Expand Down
39 changes: 35 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,25 @@ or clone it and install it:
Quick start
================================================================================

Here is a simple example:
.. code-block:: bash
$ export HELLO="world"
$ moban "{{HELLO}}"
Warning: Both data.yml and /.../.moban.cd/data.yml does not exist
Warning: Attempting to use environment vars as data...
Templating {{HELLO}}... to moban.output
Templated 1 file.
$ cat moban.output
world
Or simply

.. code-block:: bash
$ HELLO="world" moban "{{HELLO}}"
A bit formal example:

.. code-block:: bash
Expand All @@ -69,6 +87,8 @@ moban.output will contain::

world

Please note that data.yml will take precedence over environment variables.

`the tutorial`_ has more use cases.

.. _the tutorial: http://moban.readthedocs.org/en/latest/#tutorial
Expand All @@ -77,15 +97,19 @@ moban.output will contain::
Usage
================================================================================

::
.. code-block:: bash
usage: moban [-h] [-cd CONFIGURATION_DIR] [-c CONFIGURATION]
[-td [TEMPLATE_DIR [TEMPLATE_DIR ...]]] [-t TEMPLATE] [-o OUTPUT]
[-f] [-m MOBANFILE]
[template]
Yet another jinja2 cli command for static text generation
positional arguments:
template string templates
optional arguments:
-h, --help show this help message and exit
-cd CONFIGURATION_DIR, --configuration_dir CONFIGURATION_DIR
Expand All @@ -104,12 +128,19 @@ Usage
the template type, default is jinja2
-f force moban to template all files despite of
.moban.hashes
--exit-code tell moban to change exit code
-m MOBANFILE, --mobanfile MOBANFILE
custom moban file
exit codes
Exit codes
--------------------------------------------------------------------------------
By default:
- 0 : no changes
- 1 : error occured
With `--exit-code`:
- 0 : no changes
- 1 : has changes
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
author = u'C. W.'

# The short X.Y version
version = u'0.3.7'
version = u'0.3.8'
# The full version, including alpha/beta/rc tags
release = u'0.3.7'
release = u'0.3.8'


# -- General configuration ---------------------------------------------------
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.3.7"
__version__ = "0.3.8"
__author__ = "C. W."
2 changes: 2 additions & 0 deletions moban/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
LABEL_CONFIG_DIR = "configuration_dir"
LABEL_PLUGIN_DIRS = "plugin_dir"
LABEL_TEMPLATE = "template"
POSITIONAL_LABEL_TEMPLATE = "template_in_string"
LABEL_TMPL_DIRS = "template_dir"
LABEL_OUTPUT = "output"
LABEL_TEMPLATE_TYPE = "template_type"
Expand All @@ -30,6 +31,7 @@
LABEL_MOBANFILE = "mobanfile"
LABEL_FORCE = "force"
LABEL_REQUIRES = "requires"
LABEL_EXIT_CODE = "exit-code"

DEFAULT_CONFIGURATION_DIRNAME = ".moban.cd"
DEFAULT_TEMPLATE_DIRNAME = ".moban.td"
Expand Down
13 changes: 10 additions & 3 deletions moban/jinja2/engine.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from jinja2 import Environment, FileSystemLoader
from jinja2 import Template, Environment, FileSystemLoader
from lml.loader import scan_plugins_regex
from lml.plugin import PluginInfo, PluginManager
from jinja2.exceptions import TemplateNotFound

import moban.constants as constants
from moban import constants, exceptions

JINJA2_LIBRARIES = "^moban_jinja2_.+$"
JINJA2_EXENSIONS = [
Expand Down Expand Up @@ -91,9 +92,15 @@ def get_template(self, template_file):
template file exists at:
'/User/moban-pro/my-template/templates/myfile.jj2'
"""
template = self.jj2_environment.get_template(template_file)
try:
template = self.jj2_environment.get_template(template_file)
except TemplateNotFound:
raise exceptions.FileNotFound("%s does not exist" % template_file)
return template

def get_template_from_string(self, string):
return Template(string)

def apply_template(self, template, data, output):
"""
It is not expected this function to write content to file system.
Expand Down
55 changes: 42 additions & 13 deletions moban/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,30 @@ def main():
if moban_file:
try:
count = handle_moban_file(moban_file, options)
if count:
sys.exit(count)
moban_exit(options[constants.LABEL_EXIT_CODE], count)
except (
exceptions.DirectoryNotFound,
exceptions.NoThirdPartyEngine,
exceptions.MobanfileGrammarException,
) as e:
reporter.report_error_message(str(e))
sys.exit(constants.ERROR)
moban_exit(options[constants.LABEL_EXIT_CODE], constants.ERROR)
else:
try:
count = handle_command_line(options)
if count:
sys.exit(count)
moban_exit(options[constants.LABEL_EXIT_CODE], count)
except exceptions.NoTemplate as e:
reporter.report_error_message(str(e))
sys.exit(constants.ERROR)
moban_exit(options[constants.LABEL_EXIT_CODE], constants.ERROR)


def moban_exit(exit_code_toggle_flag, exit_code):
if exit_code_toggle_flag:
if exit_code:
sys.exit(exit_code)
else:
if exit_code == constants.ERROR:
sys.exit(1)


def create_parser():
Expand Down Expand Up @@ -91,9 +98,23 @@ def create_parser():
default=False,
help="force moban to template all files despite of .moban.hashes",
)
parser.add_argument(
"--%s" % constants.LABEL_EXIT_CODE,
action="store_true",
dest=constants.LABEL_EXIT_CODE,
default=False,
help="tell moban to change exit code",
)
parser.add_argument(
"-m", "--%s" % constants.LABEL_MOBANFILE, help="custom moban file"
)
parser.add_argument(
constants.POSITIONAL_LABEL_TEMPLATE,
metavar="template",
type=str,
nargs="?",
help="string templates",
)
return parser


Expand Down Expand Up @@ -153,18 +174,26 @@ def handle_command_line(options):
act upon command options
"""
options = merge(options, constants.DEFAULT_OPTIONS)
if options[constants.LABEL_TEMPLATE] is None:
raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE)
engine = plugins.ENGINES.get_engine(
options[constants.LABEL_TEMPLATE_TYPE],
options[constants.LABEL_TMPL_DIRS],
options[constants.LABEL_CONFIG_DIR],
)
engine.render_to_file(
options[constants.LABEL_TEMPLATE],
options[constants.LABEL_CONFIG],
options[constants.LABEL_OUTPUT],
)
if options[constants.LABEL_TEMPLATE] is None:
if options[constants.POSITIONAL_LABEL_TEMPLATE] is None:
raise exceptions.NoTemplate(constants.ERROR_NO_TEMPLATE)
else:
engine.render_string_to_file(
options[constants.POSITIONAL_LABEL_TEMPLATE],
options[constants.LABEL_CONFIG],
options[constants.LABEL_OUTPUT],
)
else:
engine.render_to_file(
options[constants.LABEL_TEMPLATE],
options[constants.LABEL_CONFIG],
options[constants.LABEL_OUTPUT],
)
engine.report()
HASH_STORE.save_hashes()
exit_code = reporter.convert_to_shell_exit_code(
Expand Down
33 changes: 27 additions & 6 deletions moban/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,49 @@ def render_to_file(self, template_file, data_file, output_file):
template_abs_path = utils.get_template_path(
self.template_dirs, template_file
)

flag = self.apply_template(
template_abs_path, template, data, output_file
)
if flag:
reporter.report_templating(template_file, output_file)
self.templated_count += 1

def render_string_to_file(
self, template_in_string, data_file, output_file
):
self.file_count = 1
template = self.engine.get_template_from_string(template_in_string)
template_abs_path = template_in_string[:10] + "..."
data = self.context.get_data(data_file)
flag = self.apply_template(
template_abs_path, template, data, output_file
)
if flag:
reporter.report_templating(template_abs_path, output_file)
self.templated_count += 1

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")
flag = HASH_STORE.is_file_changed(
output_file, rendered_content, template_abs_path
)
if flag:
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.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.file_permissions_copy(template_abs_path, output_file)
return flag
return True

def render_to_files(self, array_of_param_tuple):
sta = Strategy(array_of_param_tuple)
Expand Down
2 changes: 2 additions & 0 deletions moban/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def file_permissions_copy(source, dest):


def file_permissions(afile):
if sys.platform == "win32":
return "no-permission-support"
if not os.path.exists(afile):
raise exceptions.FileNotFound(afile)
return stat.S_IMODE(os.stat(afile).st_mode)
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

NAME = 'moban'
AUTHOR = 'C. W.'
VERSION = '0.3.7'
VERSION = '0.3.8'
EMAIL = 'wangc_2011@hotmail.com'
LICENSE = 'MIT'
ENTRY_POINTS = {
Expand All @@ -25,7 +25,7 @@
'Yet another jinja2 cli command for static text generation'
)
URL = 'https://github.com/moremoban/moban'
DOWNLOAD_URL = '%s/archive/0.3.7.tar.gz' % URL
DOWNLOAD_URL = '%s/archive/0.3.8.tar.gz' % URL
FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst']
KEYWORDS = [
'python',
Expand Down Expand Up @@ -60,8 +60,8 @@
# You do not need to read beyond this line
PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format(
sys.executable)
GS_COMMAND = ('gs moban v0.3.7 ' +
"Find 0.3.7 in changelog for more details")
GS_COMMAND = ('gs moban v0.3.8 ' +
"Find 0.3.8 in changelog for more details")
NO_GS_MESSAGE = ('Automatic github release is disabled. ' +
'Please install gease to enable it.')
UPLOAD_FAILED_MSG = (
Expand Down
3 changes: 0 additions & 3 deletions test.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
pip freeze

cd tests\moban-mako
python setup.py install
cd ..\..\
nosetests --with-coverage --cover-package=moban --cover-package=tests
flake8 . --exclude=docs,.moban.d --ignore=E203,E121,E123,E126,E226,E24,E704,W503,W504
Loading

0 comments on commit 234efa4

Please sign in to comment.