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.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
19import getopt 19import getopt
20from wiki2html import * 20from wiki2html import *
21from wiki2text import * 21from wiki2text import *
22from wiki2texi import *
22 23
23def usage(code=0): 24def usage(code=0):
24 print """ 25 print """
25usage: %s [-hvt] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val] 26usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val]
26 [--text] [--help] [--verbose] file 27 [--input-type=INTYPE] [--type=OUTTYPE] [--help] [--verbose] file
27""" % (sys.argv[0]) 28""" % (sys.argv[0])
28 sys.exit(code) 29 sys.exit(code)
29 30
31handlers = {
32 'html': {
33 'default': HtmlWikiMarkup,
34 'wiktionary': HtmlWiktionaryMarkup
35 },
36 'text': {
37 'default': TextWikiMarkup,
38 'wiktionary': TextWiktionaryMarkup
39 },
40 'texi': {
41 'default': TexiWikiMarkup
42 }
43}
44
30def main(): 45def main():
31 verbose_flag = 0 46 verbose_flag = 0
32 html = 1 47 itype = 'default'
48 otype = 'html'
33 lang = "pl" 49 lang = "pl"
34 kwdict = {} 50 kwdict = {}
35 debug = 0 51 debug = 0
36 52
37 try: 53 try:
38 opts, args = getopt.getopt(sys.argv[1:], "d:hl:o:tv", 54 opts, args = getopt.getopt(sys.argv[1:], "d:I:hl:o:t:v",
39 ["debug=", "help", "lang=", "option=", 55 ["debug=", "help", "lang=", "option=",
40 "text", "input-text", "verbose" ]) 56 "to", "type", "input-text", "input-type",
57 "verbose" ])
41 except getopt.GetoptError: 58 except getopt.GetoptError:
42 usage(1) 59 usage(1)
43 60
@@ -46,14 +63,16 @@ def main():
46 usage() 63 usage()
47 elif o in ("-v", "--verbose"): 64 elif o in ("-v", "--verbose"):
48 verbose_flag = verbose_flag + 1 65 verbose_flag = verbose_flag + 1
49 elif o in ("-t", "--text"): 66 elif o in ("-I", "--input-type"):
50 html = 0 67 itype = a
68 elif o in ("-t", "--to", "--type"):
69 otype = a
51 elif o in ("-l", "--lang"): 70 elif o in ("-l", "--lang"):
52 lang = a 71 lang = a
53 elif o in ("-o", "--option"): 72 elif o in ("-o", "--option"):
54 (kw,sep,val) = a.partition('=') 73 (kw,sep,val) = a.partition('=')
55 if val != '': 74 if val != '':
56 kwdict[kw] = eval(val) 75 kwdict[kw] = val
57 elif o == "--input-text": 76 elif o == "--input-text":
58 input_text = True 77 input_text = True
59 elif o in ("-d", "--debug"): 78 elif o in ("-d", "--debug"):
@@ -67,16 +86,20 @@ def main():
67 else: 86 else:
68 usage(1) 87 usage(1)
69 88
70 kwdict['lang']=lang 89 kwdict['lang']=lang
71 if html: 90
72 markup = HtmlWiktionaryMarkup(**kwdict) 91 if handlers.has_key(otype):
92 if handlers[otype].has_key(itype):
93 markup = handlers[otype][itype](**kwdict)
94 markup.debug_level = debug
95 markup.parse()
96 print str(markup)
97 exit(0)
98 else:
99 print "unsupported input type: %s" % (itype)
73 else: 100 else:
74 markup = TextWiktionaryMarkup(**kwdict) 101 print "unsupported output type: %s" % (otype)
75 markup.debug_level = debug 102 exit(1)
76 markup.parse()
77 print str(markup)
78# if verbose_flag > 0:
79# markup.output()
80 103
81if __name__ == '__main__': 104if __name__ == '__main__':
82 main() 105 main()

Return to:

Send suggestions and report system problems to the System administrator.