commit b33b5eeeb1868c6c94fc6a11be4ee11fea9dd7fb Author: Julien Palard Date: Wed May 24 22:36:06 2017 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71e6852 --- /dev/null +++ b/.gitignore @@ -0,0 +1,62 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# pyenv python configuration file +.python-version diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2f6be11 --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ + +MIT License + +Copyright (c) 2017, Julien Palard + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..c4bbc94 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,8 @@ +include LICENSE +include README.rst + +recursive-include tests * +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] + +recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..1e1e5d3 --- /dev/null +++ b/README.rst @@ -0,0 +1,18 @@ +======== +poindent +======== + + +.. image:: https://img.shields.io/pypi/v/poindent.svg + :target: https://pypi.python.org/pypi/poindent + +Script to fix indentation of given ``.po`` files. If ``--modified`` is +given, it will only fix modified files according to git (usefull if +your ``.po`` files are versionned). + + +This package only runs ``msgcat`` from the ``gettext`` package, so if +your distribution don't have it, it just won't work. + + +* Free software: MIT license diff --git a/poindent/__init__.py b/poindent/__init__.py new file mode 100644 index 0000000..f78533f --- /dev/null +++ b/poindent/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +__author__ = """Julien Palard""" +__email__ = 'julien@palard.fr' +__version__ = '0.1.0' diff --git a/poindent/poindent.py b/poindent/poindent.py new file mode 100644 index 0000000..be8b08c --- /dev/null +++ b/poindent/poindent.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +"""Fix style of uncommited po files, or all if --all is given. + +The "tac|tac" trick is an equivalent to "sponge" but as tac is in +coreutils we're avoiding you to install a new packet. Without +`tac|tac` or `sponge`, `msgcat` may start to write in the po file +before having finised to read it, yielding unpredictible behavior. +(Yep we also can write to another file and mv it, like sed -i does.) +""" + +from shlex import quote +from subprocess import check_output + +from tqdm import tqdm + + +def fix_style(po_files, modified=False, no_wrap=False): + """Fix style of unversionned ``.po`` files, or or all f + """ + if modified: + git_status = check_output(["git", "status", "--porcelain"], + universal_newlines=True) + git_status_lines = [line.split(maxsplit=2) for line in + git_status.split('\n') + if line] + po_files.extend(filename for status, filename in git_status_lines + if filename.endswith('.po')) + for po_file in tqdm(po_files, desc="Fixing indentation in po files"): + check_output('tac {} | tac | msgcat - -o {} {}'.format( + quote(po_file), quote(po_file), '--no-wrap' if no_wrap else ''), + shell=True) + + +def main(): + import argparse + parser = argparse.ArgumentParser( + description='Ensure po files are using the standard gettext format') + parser.add_argument('--modified', '-m', action='store_true', + help='Use git to find modified files.') + parser.add_argument('--no-wrap', action='store_true', + help='see `man msgcat`, usefull to sed right after.') + parser.add_argument('po_files', nargs='*', help='po files.') + args = parser.parse_args() + if not args.po_files and not args.modified: + parser.print_help() + exit(1) + fix_style(args.po_files, args.modified, args.no_wrap) diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..65d1a09 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,3 @@ +pip==8.1.2 +wheel==0.29.0 +flake8==2.6.0 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..26eb706 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,18 @@ +[bumpversion] +current_version = 0.1.0 +commit = True +tag = True + +[bumpversion:file:setup.py] +search = version='{current_version}' +replace = version='{new_version}' + +[bumpversion:file:poindent/__init__.py] +search = __version__ = '{current_version}' +replace = __version__ = '{new_version}' + +[bdist_wheel] +universal = 1 + +[flake8] +exclude = docs diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..aeeee6b --- /dev/null +++ b/setup.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from setuptools import setup + +with open('README.rst') as readme_file: + readme = readme_file.read() + +requirements = [ + 'tqdm' +] + +setup( + name='poindent', + version='0.1.0', + description="Find an properly reindent .po files.", + long_description=readme, + author="Julien Palard", + author_email='julien@palard.fr', + url='https://github.com/JulienPalard/poindent', + packages=[ + 'poindent', + ], + package_dir={'poindent': + 'poindent'}, + entry_points={ + 'console_scripts': ['poindent=poindent.poindent:main'] + }, + include_package_data=True, + install_requires=requirements, + license="MIT license", + zip_safe=False, + keywords='poindent', + classifiers=[ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Natural Language :: English', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6' + ] +)