summaryrefslogtreecommitdiff
path: root/wikicvt.py
diff options
context:
space:
mode:
Diffstat (limited to 'wikicvt.py')
-rwxr-xr-xwikicvt.py57
1 files changed, 40 insertions, 17 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"):
@@ -67,16 +86,20 @@ def main():
else:
usage(1)
- kwdict['lang']=lang
- if html:
- markup = HtmlWiktionaryMarkup(**kwdict)
+ kwdict['lang']=lang
+
+ 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)
+ exit(0)
+ else:
+ print "unsupported input type: %s" % (itype)
else:
- markup = TextWiktionaryMarkup(**kwdict)
- markup.debug_level = debug
- markup.parse()
- print str(markup)
-# if verbose_flag > 0:
-# markup.output()
+ print "unsupported output type: %s" % (otype)
+ exit(1)
if __name__ == '__main__':
main()

Return to:

Send suggestions and report system problems to the System administrator.