diff options
author | infirit <[email protected]> | 2014-07-17 12:18:35 +0200 |
---|---|---|
committer | infirit <[email protected]> | 2014-07-17 12:18:35 +0200 |
commit | 3bd6fc73c8287c92f5d6a84a1e9e45e906ec36e7 (patch) | |
tree | b41f26a2c5c4e7ad5768e957fb4ce52556e05bbf | |
parent | 68a6fc1faaeb47d82347e3f5390ac4bda2cad561 (diff) | |
download | caja-dropbox-3bd6fc73c8287c92f5d6a84a1e9e45e906ec36e7.tar.bz2 caja-dropbox-3bd6fc73c8287c92f5d6a84a1e9e45e906ec36e7.tar.xz |
docgen: Don't use stdin and stdout
The encoding on stdin and stdout are usually ascii and may cause problems
with writing unicode to it. Instead of this we open the file directly
and avoid dealing with annoying unicode encode/decode errors.
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | docgen.py | 31 |
2 files changed, 21 insertions, 12 deletions
diff --git a/Makefile.am b/Makefile.am index 8985128..e420332 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ caja-dropbox: caja-dropbox.in serializeimages.py chmod +x caja-dropbox caja-dropbox.1: caja-dropbox.txt.in caja-dropbox docgen.py - python docgen.py $(PACKAGE_VERSION) < caja-dropbox.txt.in > caja-dropbox.txt + python docgen.py $(PACKAGE_VERSION) caja-dropbox.txt.in caja-dropbox.txt $(RST2MAN) caja-dropbox.txt > caja-dropbox.1 SUBDIRS = data src @@ -1,25 +1,34 @@ +from __future__ import unicode_literals import sys import datetime +import codecs # heeeheee env = {"__name__":"__notmain__"} execfile("caja-dropbox", env) commands = env["commands"] -f = open("AUTHORS", "r") -authors = '| ' + f.read().replace('\n', '\n| ') -f.close() +with codecs.open("AUTHORS", "r", "utf-8") as afile: + authors = '| ' + afile.read().replace('\n', '\n| ') + +with codecs.open(sys.argv[2], "r", encoding="utf-8") as infile: + instr = infile.read() formatted_commands = "" for cmd in commands: split = commands[cmd].__doc__.split('\n', 2) - formatted_commands += split[1].decode('ascii').replace(cmd, "`%s`" % cmd).replace("dropbox", "``dropbox``") - formatted_commands += split[2].decode('ascii').replace('\n', '\n | ') + formatted_commands += split[1].replace(cmd, "`%s`" % cmd).replace("dropbox", "``dropbox``") + formatted_commands += split[2].replace('\n', '\n | ') formatted_commands += '\n\n' -sys.stdout.write(sys.stdin.read().replace\ - ('@AUTHORS@', authors).replace\ - ('@DATE@', datetime.date.today().isoformat()).replace\ - ('@PACKAGE_VERSION@', sys.argv[1]).replace\ - ('@SYNOPSIS@', '| '+'\n| '.join(commands[cmd].__doc__.split('\n', 2)[1].decode('ascii').replace(cmd, "`%s`" % cmd).replace("dropbox", "``dropbox``") for cmd in commands)).replace\ - ('@COMMANDS@', formatted_commands)) +replace = {'@AUTHORS@': authors, + '@DATE@': datetime.date.today().isoformat(), + '@PACKAGE_VERSION@': sys.argv[1], + '@SYNOPSIS@': '| '+'\n| '.join(commands[cmd].__doc__.split('\n', 2)[1].replace(cmd, "`%s`" % cmd).replace("dropbox", "``dropbox``") for cmd in commands), + '@COMMANDS@': formatted_commands} + +for r in replace.keys(): + instr = instr.replace(r, replace[r]) + +with codecs.open(sys.argv[3], "w", encoding="utf-8") as outfile: + outfile.write(instr) |