diff options
Diffstat (limited to 'bin/wikitrans')
-rwxr-xr-x | bin/wikitrans | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/bin/wikitrans b/bin/wikitrans index 4a0fc06..09ba0b3 100755 --- a/bin/wikitrans +++ b/bin/wikitrans @@ -68,12 +68,17 @@ def setkw(option, opt, value, parser): if not parser.values.kwdict: parser.values.kwdict = {} (kw,sep,val) = value.partition('=') if val: parser.values.kwdict[kw] = val +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() if sys.version_info[0] > 2: import urllib.request with urllib.request.urlopen(url) as u: root = etree.fromstring(u.read()) @@ -132,14 +137,14 @@ Otherwise, ARG is name of the file to read wiki material from. parser.add_option('-o', '--option', action='callback', callback=setkw, type='string', dest='kwdict', default={}, help='set keyword option for the parser class constructor') 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)') parser.add_option('-D', '--dump', action='store_const', const='dump', dest='otype', help='dump parse tree and exit; similar to --type=dump') parser.add_option('-b', '--base-url', @@ -147,13 +152,14 @@ Otherwise, ARG is name of the file to read wiki material from. help='set base url') (options, args) = parser.parse_args() if len(args) == 1: 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] == '-': options.kwdict['file'] = sys.stdin elif re.match('^(http|ftp)s?://',args[0]): getwiki(args[0], options) else: options.kwdict['filename'] = args[0] @@ -164,13 +170,12 @@ Otherwise, ARG is name of the file to read wiki material from. if options.otype == 'dump' and not 'indent' in options.kwdict: options.kwdict['indent'] = 2 if options.otype in handlers: if options.itype in handlers[options.otype]: markup = handlers[options.otype][options.itype](**options.kwdict) - markup.debug_level = options.debug markup.parse() print("%s" % str(markup)) exit(0) else: print("input type %s is not supported for %s output" % (options.itype, options.otype)) else: |