diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/import_po.py | 4 | ||||
| -rwxr-xr-x | scripts/jinjify.py | 20 | ||||
| -rwxr-xr-x | scripts/set_version.py | 6 |
3 files changed, 19 insertions, 11 deletions
diff --git a/scripts/import_po.py b/scripts/import_po.py index 50afab9..0429b42 100755 --- a/scripts/import_po.py +++ b/scripts/import_po.py @@ -3,7 +3,7 @@ """Download translations from transifex and regenerate files.""" from __future__ import unicode_literals, print_function -import codecs +import io from glob import glob import os import sys @@ -28,5 +28,5 @@ MESSAGES = {""".splitlines() lines.extend(sorted(lines2)) lines.append("}\n") print("Generating:", outf) - with codecs.open(outf, "wb+", "utf8") as outfile: + with io.open(outf, "w+", encoding="utf8") as outfile: outfile.write('\n'.join(lines)) diff --git a/scripts/jinjify.py b/scripts/jinjify.py index 5f07032..be69731 100755 --- a/scripts/jinjify.py +++ b/scripts/jinjify.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import codecs +import io import glob import sys import os @@ -11,7 +11,6 @@ import colorama import jinja2 dumb_replacements = [ - ["{% if isinstance(url, tuple) %}", "{% if url is mapping %}"], ["{% if any(post.is_mathjax for post in posts) %}", '{% if posts|selectattr("is_mathjax")|list %}'], ["json.dumps(title)", "title|tojson"], ["{{ parent.extra_head() }}", "{{ super() }}"], @@ -43,7 +42,7 @@ def jinjify(in_theme, out_theme): lookup.loader = jinja2.FileSystemLoader([out_templates_path], encoding='utf-8') for template in glob.glob(os.path.join(in_templates_path, "*.tmpl")): out_template = os.path.join(out_templates_path, os.path.basename(template)) - with codecs.open(template, "r", "utf-8") as inf: + with io.open(template, "r", encoding="utf-8") as inf: data = mako2jinja(inf) lines = [] @@ -56,7 +55,7 @@ def jinjify(in_theme, out_theme): for repl in dumber_replacements: data = data.replace(*repl) - with codecs.open(out_template, "wb+", "utf-8") as outf: + with io.open(out_template, "w+", encoding="utf-8") as outf: outf.write(data + '\n') # Syntax check output @@ -213,7 +212,16 @@ def mako2jinja(input_file): return output if __name__ == "__main__": - if len(sys.argv) != 3: - print('ERROR: needs exactly two arguments, input and output directory.') + if len(sys.argv) == 1: + print('Performing standard conversions:') + for m, j in ( + ('nikola/data/themes/base', 'nikola/data/themes/base-jinja'), + ('nikola/data/themes/bootstrap', 'nikola/data/themes/bootstrap-jinja'), + ('nikola/data/themes/bootstrap3', 'nikola/data/themes/bootstrap3-jinja') + ): + print(' {0} -> {1}'.format(m, j)) + jinjify(m, j) + elif len(sys.argv) != 3: + print('ERROR: needs input and output directory, or no arguments for default conversions.') else: jinjify(sys.argv[1], sys.argv[2]) diff --git a/scripts/set_version.py b/scripts/set_version.py index 100a9f7..6a64489 100755 --- a/scripts/set_version.py +++ b/scripts/set_version.py @@ -4,7 +4,7 @@ """Script to set the version number wherever it's needed before a release.""" from __future__ import unicode_literals, print_function -import codecs +import io import os import re import sys @@ -14,12 +14,12 @@ import glob def sed_like_thing(pattern, repl, path): """Like re.sub but applies to a file instead of a string.""" - with codecs.open(path, 'rb', 'utf8') as inf: + with io.open(path, 'r', encoding='utf8') as inf: data = inf.read() data = re.sub(pattern, repl, data) - with codecs.open(path, 'wb+', 'utf8') as outf: + with io.open(path, 'w+', encoding='utf8') as outf: outf.write(data) if __name__ == "__main__": |
