summaryrefslogtreecommitdiff
path: root/wiki-to-help/mw.py
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2012-09-01 09:51:27 -0500
committerNorbert Thiebaud <nthiebaud@gmail.com>2012-10-16 11:07:30 -0500
commit61173c1b58efa79c0ba6b08348d2796a249d0186 (patch)
tree00ebf544db18942e2a1ecfc5e5fa16931127d38f /wiki-to-help/mw.py
parent3dc2e7497f1798ae4ff6c5c8c562666bc10a393c (diff)
move help structure one directory up
Change-Id: Ie970e39fbb6795a92d9fdd13510409d7dcd071bc
Diffstat (limited to 'wiki-to-help/mw.py')
-rw-r--r--wiki-to-help/mw.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/wiki-to-help/mw.py b/wiki-to-help/mw.py
new file mode 100644
index 0000000000..f19ca15be8
--- /dev/null
+++ b/wiki-to-help/mw.py
@@ -0,0 +1,49 @@
+#import mwlib.cdbwiki, mwlib.apps.render, mwlib.apps
+import mwlib.apps
+import sys, os
+
+class MW(object):
+ """
+ Use this adapter class to call mwlib within python.
+ Example: import mw; MW.buildcdb("in.xml","out")
+ """
+
+ @staticmethod
+ def quietCall(function,args=(),showErr=True,showOutput=True):
+ """
+ Calls a python function and redirects parts to /dev/null.
+ This is platform independent.
+ """
+ saveout = sys.stdout
+ saveerr = sys.stderr
+
+ if not showErr: sys.stderr=nullerr=open(os.devnull,"w")
+ if not showOutput: sys.stdout=nullout=open(os.devnull,"w")
+ function(*args)
+ if not showErr: nullerr.close()
+ if not showOutput: nullout.close()
+
+ sys.stdout=saveout
+ sys.stderr=saveerr
+
+ @staticmethod
+ def _setArgs(function,args):
+ """ Set sys.argv for @function """
+ bak = sys.argv
+ args=("nothing",)+args
+ dec=[x.encode() for x in args]
+ sys.argv=dec
+ r=function()
+ sys.argv=bak
+ return r
+
+ @staticmethod
+ def buildcdb(source,dest):
+ args=("--input",source,"--output",dest)
+ return MW._setArgs(mwlib.apps.buildcdb,args)
+ #mwlib.cdbwiki.BuildWiki(*args)
+
+ @staticmethod
+ def render(*args):
+ import mwlib.apps.render
+ return MW._setArgs(mwlib.apps.render.Main(),args)