summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2015-07-16 10:20:06 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2015-07-16 10:26:15 (GMT)
commiteaf9325ddcff786f3fcd5b9047327ef6e397e778 (patch) (side-by-side diff)
tree2f0336efbb1deab9651c5eeb1b5dd753538a5c8e
parent8e11d7f20459697c883df1e421df02006f749792 (diff)
downloadwikitrans-eaf9325ddcff786f3fcd5b9047327ef6e397e778.tar.gz
wikitrans-eaf9325ddcff786f3fcd5b9047327ef6e397e778.tar.bz2
Restructure the package.
The idea is to switch from using this project as a git submodule to having it distributed via PyPI. Since the name 'wit' is already registered there, the package is renamed to 'wikitrans'. * setup.py: Use setuptools Rename package to wikitrans. * wikicvt.py: Remove. Replaced with: * bin/wikitrans: New file. * __init__.py: Move to WikiTrans/__init__.py * wiki2html.py: Move to WikiTrans/wiki2html.py * wiki2texi.py: Move to WikiTrans/wiki2texi.py * wiki2text.py: Move to WikiTrans/wiki2text.py * wikimarkup.py: Move to WikiTrans/wikimarkup.py * wikins.py: Move to WikiTrans/wikins.py * test.py: Move to tests/test.py * MANIFEST.in: New file. * README.rst: New file. * .gitignore: Update.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--.gitignore4
-rw-r--r--MANIFEST.in1
-rw-r--r--README.rst3
-rw-r--r--WikiTrans/__init__.py (renamed from __init__.py)2
-rw-r--r--WikiTrans/wiki2html.py (renamed from wiki2html.py)2
-rw-r--r--WikiTrans/wiki2texi.py (renamed from wiki2texi.py)0
-rw-r--r--WikiTrans/wiki2text.py (renamed from wiki2text.py)0
-rw-r--r--WikiTrans/wikimarkup.py (renamed from wikimarkup.py)0
-rw-r--r--WikiTrans/wikins.py (renamed from wikins.py)0
-rwxr-xr-xbin/wikitrans129
-rw-r--r--setup.py21
-rw-r--r--testdata/boldit2.html1
-rw-r--r--tests/test.py (renamed from test.py)0
-rwxr-xr-xwikicvt.py125
14 files changed, 153 insertions, 135 deletions
diff --git a/.gitignore b/.gitignore
index aff6316..5f2763b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,7 @@
*~
*.pyc
.emacs.desktop
+build/
+dist/
+tmp/
+*.egg-info/
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..207b54e
--- a/dev/null
+++ b/MANIFEST.in
@@ -0,0 +1 @@
+exclude .gitignore
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..587526a
--- a/dev/null
+++ b/README.rst
@@ -0,0 +1,3 @@
+MediaWiki Markup Translator
+===========================
+FIXME
diff --git a/__init__.py b/WikiTrans/__init__.py
index b839db8..ad99ce3 100644
--- a/__init__.py
+++ b/WikiTrans/__init__.py
@@ -15,4 +15,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-__all__ = [ "wiki2html", "wiki2text" ]
+__all__ = [ "wikimarkup", "wiki2html", "wiki2text", "wiki2texi", "wikins" ]
diff --git a/wiki2html.py b/WikiTrans/wiki2html.py
index 05d4642..754fa9b 100644
--- a/wiki2html.py
+++ b/WikiTrans/wiki2html.py
@@ -23,6 +23,8 @@ try:
except ImportError:
from urllib.parse import quote as url_quote
+__all__ = [ "HtmlWikiMarkup", "HtmlWiktionaryMarkup" ]
+
class HtmlWikiMarkup (WikiMarkup):
"""
A (hopefully) general-purpose Wiki->HTML translator class.
diff --git a/wiki2texi.py b/WikiTrans/wiki2texi.py
index 6e32c56..6e32c56 100644
--- a/wiki2texi.py
+++ b/WikiTrans/wiki2texi.py
diff --git a/wiki2text.py b/WikiTrans/wiki2text.py
index 916391e..916391e 100644
--- a/wiki2text.py
+++ b/WikiTrans/wiki2text.py
diff --git a/wikimarkup.py b/WikiTrans/wikimarkup.py
index 2ef6be1..2ef6be1 100644
--- a/wikimarkup.py
+++ b/WikiTrans/wikimarkup.py
diff --git a/wikins.py b/WikiTrans/wikins.py
index 4fb5315..4fb5315 100644
--- a/wikins.py
+++ b/WikiTrans/wikins.py
diff --git a/bin/wikitrans b/bin/wikitrans
new file mode 100755
index 0000000..0cb26a4
--- a/dev/null
+++ b/bin/wikitrans
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2008,2015 Sergey Poznyakoff
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import print_function
+import sys
+from optparse import OptionParser
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+from WikiTrans.wiki2html import HtmlWikiMarkup, HtmlWiktionaryMarkup
+from WikiTrans.wiki2text import TextWikiMarkup, TextWiktionaryMarkup
+from WikiTrans.wiki2texi import TexiWikiMarkup
+from WikiTrans.wikimarkup import WikiMarkup
+
+class DumpWikiMarkup (WikiMarkup):
+ def __str__(self):
+ if self.tree:
+ s = StringIO()
+ self.dump(self.tree, 0, s)
+ return s.getvalue()
+ else:
+ return ""
+
+handlers = {
+ 'dump': {
+ 'default': DumpWikiMarkup
+ },
+ 'html': {
+ 'default': HtmlWikiMarkup,
+ 'wiktionary': HtmlWiktionaryMarkup
+ },
+ 'text': {
+ 'default': TextWikiMarkup,
+ 'wiktionary': TextWiktionaryMarkup
+ },
+ 'texi': {
+ 'default': TexiWikiMarkup
+ }
+}
+
+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 main():
+ usage = '%prog [OPTIONS] FILE'
+ version = '%prog 1.0'
+ description = """Translates MediaWiki documents markup to various other formats.
+"""
+ epilog = "Report bugs to: <gray+wikitrans@gnu.org.ua>"
+
+ parser = OptionParser(usage=usage,
+ version=version,
+ description=description,
+ epilog=epilog)
+ parser.add_option('-v', '--verbose',
+ action="count", dest="verbose",
+ help="verbose operation")
+ parser.add_option('-I', '--input-type',
+ action='store', type='string', dest='itype',
+ default='default',
+ help='set input document type')
+ parser.add_option('-t', '--to', '--type',
+ action='store', type='string', dest='otype',
+ default='html',
+ help='set output document type')
+ parser.add_option('-l', '--lang',
+ action='store', type='string', dest='lang',
+ default='pl',
+ help='set input document language')
+ parser.add_option('-o', '--option',
+ action='callback', callback=setkw,
+ type='string', dest='kwdict',
+ default={},
+ help='set keyword option for the parser class')
+ parser.add_option('-d', '--debug',
+ action='store', type='int', dest='debug',
+ default=0,
+ 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')
+
+ (options, args) = parser.parse_args()
+
+ if len(args) == 1:
+ if args[0] == '-':
+ options.kwdict['file'] = sys.stdin
+ else:
+ options.kwdict['filename'] = args[0]
+ else:
+ parser.error("bad number of arguments")
+
+ options.kwdict['lang'] = options.lang # FIXME
+
+ 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("unsupported input type: %s" % options.itype)
+ else:
+ print("unsupported output type: %s" % options.otype)
+ exit(1)
+
+if __name__ == '__main__':
+ main()
diff --git a/setup.py b/setup.py
index ec97901..c6fb4a6 100644
--- a/setup.py
+++ b/setup.py
@@ -15,26 +15,29 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from distutils.core import setup
-import wikimarkup
+from setuptools import setup, find_packages
+from codecs import open
-setup(name='wit',
+setup(name='wikitrans',
version='0.1',
author='Sergey Poznyakoff',
- author_email='gray@gnu.org.ua',
- url='http://gray.gnu.org.ua/',
- package_dir = {'wit': ''},
- packages=['wit'],
+ author_email='gray@gnu.org',
+ url='http://www.gnu.org.ua/projects/wit',
+# package_dir = {'src': ''},
+ packages = find_packages(exclude=['contrib', 'docs', 'tests*']),
+ scripts=['bin/wikitrans'],
license='GPL License',
description='Wiki markup translator.',
+ long_description='Translates MediaWiki documents markup to various other formats',
platforms=['any'],
classifiers=[
- 'Development Status :: 3 - Alpha',
+ 'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Text Processing :: Markup'
- ]
+ ],
+ keywords = 'mediawiki markup translation',
)
diff --git a/testdata/boldit2.html b/testdata/boldit2.html
new file mode 100644
index 0000000..cbe21ab
--- a/dev/null
+++ b/testdata/boldit2.html
@@ -0,0 +1 @@
+<p><b><i>a b</i> c d</b></p>
diff --git a/test.py b/tests/test.py
index 9c72832..9c72832 100644
--- a/test.py
+++ b/tests/test.py
diff --git a/wikicvt.py b/wikicvt.py
deleted file mode 100755
index 41bba2f..0000000
--- a/wikicvt.py
+++ b/dev/null
@@ -1,125 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-# Copyright (C) 2008,2015 Sergey Poznyakoff
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-from __future__ import print_function
-import sys
-import getopt
-try:
- from StringIO import StringIO
-except ImportError:
- from io import StringIO
-from wiki2html import *
-from wiki2text import *
-from wiki2texi import *
-
-class DumpWikiMarkup (WikiMarkup):
- def __str__(self):
- if self.tree:
- s = 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,
- 'wiktionary': TextWiktionaryMarkup
- },
- 'texi': {
- 'default': TexiWikiMarkup
- }
-}
-
-def main():
- verbose_flag = 0
- itype = 'default'
- otype = 'html'
- lang = "pl"
- kwdict = {}
- debug = 0
-
- try:
- 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"):
- usage()
- elif o in ("-v", "--verbose"):
- verbose_flag = verbose_flag + 1
- 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] = 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 otype in handlers:
- if itype in handlers[otype]:
- markup = handlers[otype][itype](**kwdict)
- markup.debug_level = debug
- markup.parse()
- print("%s" % str(markup))
- 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.