summaryrefslogtreecommitdiffabout
path: root/wikicvt.py
Side-by-side diff
Diffstat (limited to 'wikicvt.py') (more/less context) (ignore whitespace changes)
-rwxr-xr-xwikicvt.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/wikicvt.py b/wikicvt.py
index e61e28b..c8ca887 100755
--- a/wikicvt.py
+++ b/wikicvt.py
@@ -14,24 +14,37 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import getopt
+import StringIO
from wiki2html import *
from wiki2text import *
from wiki2texi import *
+class DumpWikiMarkup (WikiMarkup):
+ def __str__(self):
+ if self.tree:
+ s = StringIO.StringIO()
+ self.dump(self.tree, 0, s)
+ return s.getvalue()
+ else:
+ return ""
+
def usage(code=0):
print """
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 = {
+ 'dump': {
+ 'default': DumpWikiMarkup
+ },
'html': {
'default': HtmlWikiMarkup,
'wiktionary': HtmlWiktionaryMarkup
},
'text': {
'default': TextWikiMarkup,
@@ -48,15 +61,16 @@ def main():
otype = 'html'
lang = "pl"
kwdict = {}
debug = 0
try:
- opts, args = getopt.getopt(sys.argv[1:], "d:I:hl:o:t:v",
- ["debug=", "help", "lang=", "option=",
- "to", "type", "input-text", "input-type",
+ opts, args = getopt.getopt(sys.argv[1:], "Dd:I:hl:o:t:v",
+ ["dump",
+ "debug=", "help", "lang=", "option=",
+ "to=", "type=", "input-text", "input-type=",
"verbose" ])
except getopt.GetoptError:
usage(1)
for o, a in opts:
if o in ("-h", "--help"):
@@ -74,25 +88,27 @@ def main():
if val != '':
kwdict[kw] = val
elif o == "--input-text":
input_text = True
elif o in ("-d", "--debug"):
debug = eval(a)
+ elif o in ("-D", "--dump"):
+ otype = 'dump'
if len(args) == 1:
if args[0] == '-':
kwdict['file'] = sys.stdin
else:
kwdict['filename'] = args[0]
else:
usage(1)
kwdict['lang']=lang
- if handlers.has_key(otype):
- if handlers[otype].has_key(itype):
+ if otype in handlers:
+ if itype in handlers[otype]:
markup = handlers[otype][itype](**kwdict)
markup.debug_level = debug
markup.parse()
print str(markup)
exit(0)
else:

Return to:

Send suggestions and report system problems to the System administrator.