summaryrefslogtreecommitdiff
path: root/wikicvt.py
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-07-07 16:19:56 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2015-07-07 16:19:56 +0300
commit323ba4ba7d144f3da5cf70ad64b3366eebca5f20 (patch)
tree922fc74662a809ecf4a416e5570dc3d6e7994492 /wikicvt.py
parentedd43da79765b81d3f1b51c8d132196cb1429fff (diff)
downloadwikitrans-323ba4ba7d144f3da5cf70ad64b3366eebca5f20.tar.gz
wikitrans-323ba4ba7d144f3da5cf70ad64b3366eebca5f20.tar.bz2
Initial implementation of Texinfo translator class
* wiki2html.py (str_pre): Don't add <pre> tags if nested * wiki2texi.py: New file. * wikicvt.py: Add --type (--to, -t) and --input-type (-I) options. * wikimarkup.py (BaseWikiMarkup): Use new object style. (tokread): Remove 'extra' keyword for the sake of parse_env
Diffstat (limited to 'wikicvt.py')
-rwxr-xr-xwikicvt.py51
1 files changed, 37 insertions, 14 deletions
diff --git a/wikicvt.py b/wikicvt.py
index 4806045..e61e28b 100755
--- a/wikicvt.py
+++ b/wikicvt.py
@@ -19,25 +19,42 @@ import sys
import getopt
from wiki2html import *
from wiki2text import *
+from wiki2texi import *
def usage(code=0):
print """
-usage: %s [-hvt] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val]
- [--text] [--help] [--verbose] file
+usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val]
+ [--input-type=INTYPE] [--type=OUTTYPE] [--help] [--verbose] file
""" % (sys.argv[0])
sys.exit(code)
+handlers = {
+ 'html': {
+ 'default': HtmlWikiMarkup,
+ 'wiktionary': HtmlWiktionaryMarkup
+ },
+ 'text': {
+ 'default': TextWikiMarkup,
+ 'wiktionary': TextWiktionaryMarkup
+ },
+ 'texi': {
+ 'default': TexiWikiMarkup
+ }
+}
+
def main():
verbose_flag = 0
- html = 1
+ itype = 'default'
+ otype = 'html'
lang = "pl"
kwdict = {}
debug = 0
try:
- opts, args = getopt.getopt(sys.argv[1:], "d:hl:o:tv",
+ opts, args = getopt.getopt(sys.argv[1:], "d:I:hl:o:t:v",
["debug=", "help", "lang=", "option=",
- "text", "input-text", "verbose" ])
+ "to", "type", "input-text", "input-type",
+ "verbose" ])
except getopt.GetoptError:
usage(1)
@@ -46,14 +63,16 @@ def main():
usage()
elif o in ("-v", "--verbose"):
verbose_flag = verbose_flag + 1
- elif o in ("-t", "--text"):
- html = 0
+ elif o in ("-I", "--input-type"):
+ itype = a
+ elif o in ("-t", "--to", "--type"):
+ otype = a
elif o in ("-l", "--lang"):
lang = a
elif o in ("-o", "--option"):
(kw,sep,val) = a.partition('=')
if val != '':
- kwdict[kw] = eval(val)
+ kwdict[kw] = val
elif o == "--input-text":
input_text = True
elif o in ("-d", "--debug"):
@@ -68,15 +87,19 @@ def main():
usage(1)
kwdict['lang']=lang
- if html:
- markup = HtmlWiktionaryMarkup(**kwdict)
- else:
- markup = TextWiktionaryMarkup(**kwdict)
+
+ if handlers.has_key(otype):
+ if handlers[otype].has_key(itype):
+ markup = handlers[otype][itype](**kwdict)
markup.debug_level = debug
markup.parse()
print str(markup)
-# if verbose_flag > 0:
-# markup.output()
+ exit(0)
+ else:
+ print "unsupported input type: %s" % (itype)
+ else:
+ print "unsupported output type: %s" % (otype)
+ exit(1)
if __name__ == '__main__':
main()

Return to:

Send suggestions and report system problems to the System administrator.