diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-09-01 22:10:01 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-09-01 22:24:02 +0300 |
commit | 5320bea15e388200e613e6a2bdac3c1449030986 (patch) | |
tree | 7d8571c63f72cc690cea8323e43be09c18527c45 /bin/wikitrans | |
parent | 0aae19835045bac0be0f22ecd0e84527cdaee21c (diff) | |
download | wikitrans-5320bea15e388200e613e6a2bdac3c1449030986.tar.gz wikitrans-5320bea15e388200e613e6a2bdac3c1449030986.tar.bz2 |
Bugfixes
* README.rst: Describe new options.
* bin/wikitrans: Change handling of the --debug option.
* wikitrans/wikimarkup.py (WikiMarkupParser): New attribute - strict.
(parse_para): Don't throw UnexpectedTokenError if self.strict is False,
instead ignore invalid token.
(WikiMarkup): Fix Python 3 compatibility
* wikitrans/wikitoken.py: Fix Python 3 compatibility
Diffstat (limited to 'bin/wikitrans')
-rwxr-xr-x | bin/wikitrans | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/bin/wikitrans b/bin/wikitrans index 4a0fc06..09ba0b3 100755 --- a/bin/wikitrans +++ b/bin/wikitrans @@ -3,3 +3,3 @@ # Copyright (C) 2008-2018 Sergey Poznyakoff -# +# # This program is free software; you can redistribute it and/or modify @@ -8,3 +8,3 @@ # any later version. -# +# # This program is distributed in the hope that it will be useful, @@ -13,3 +13,3 @@ # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License @@ -34,9 +34,9 @@ from wikitrans.wikidump import DumpWikiMarkup -# Set utf-8 as the default encoding for Python 2.7. -# Trying to do so using encode('utf_8')/unicode, which is +# Set utf-8 as the default encoding for Python 2.7. +# Trying to do so using encode('utf_8')/unicode, which is # supposed to be the right way, does not work in Python 2.7 # Simply calling sys.setdefaultencoding is not possible, -# because, for some obscure reason, Python chooses to delete -# this symbol from the namespace after setting its default -# encoding in site.py. That's why reload is needed. +# because, for some obscure reason, Python chooses to delete +# this symbol from the namespace after setting its default +# encoding in site.py. That's why reload is needed. try: @@ -73,4 +73,9 @@ def setkw(option, opt, value, parser): +def setdebug(option, opt, value, parser): + if not parser.values.kwdict: + parser.values.kwdict = {} + parser.values.kwdict['debug_level'] = value + def getwiki(url, options): - tmp = tempfile.NamedTemporaryFile() + tmp = tempfile.NamedTemporaryFile() if sys.version_info[0] > 2: @@ -97,5 +102,5 @@ def getwiki(url, options): options.itype = 'wiktionary' - + options.kwdict['text'] = text.text.encode() - + def main(): @@ -108,6 +113,6 @@ Otherwise, if --base-url is given, ARG is treated as the name of the page to get from the WikiMedia istallation at that URL. -Otherwise, ARG is name of the file to read wiki material from. +Otherwise, ARG is name of the file to read wiki material from. """ epilog = "Report bugs to: <gray+wikitrans@gnu.org.ua>" - + parser = OptionParser(usage=usage, @@ -137,4 +142,4 @@ Otherwise, ARG is name of the file to read wiki material from. parser.add_option('-d', '--debug', - action='store', type='int', dest='debug', - default=0, + action='callback', callback=setdebug, + type='int', dest='kwdict', help='set debug level (0..100)') @@ -147,3 +152,3 @@ Otherwise, ARG is name of the file to read wiki material from. help='set base url') - + @@ -152,3 +157,4 @@ Otherwise, ARG is name of the file to read wiki material from. if options.base_url: - getwiki(options.base_url + '/wiki/Special:Export/' + args[0], options) + getwiki(options.base_url + '/wiki/Special:Export/' + args[0], + options) elif args[0] == '-': @@ -161,3 +167,3 @@ Otherwise, ARG is name of the file to read wiki material from. parser.error("bad number of arguments") - + options.kwdict['lang'] = options.lang # FIXME @@ -169,3 +175,2 @@ Otherwise, ARG is name of the file to read wiki material from. markup = handlers[options.otype][options.itype](**options.kwdict) - markup.debug_level = options.debug markup.parse() @@ -180,2 +185,2 @@ Otherwise, ARG is name of the file to read wiki material from. if __name__ == '__main__': - main() + main() |