summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Richter <timo@iera.de>2011-07-14 19:09:20 +0200
committerAndras Timar <atimar@suse.com>2011-07-14 19:09:20 +0200
commit3aabd79dd9dd86d125fa73052bcf3de642767b88 (patch)
treead22f1e5a04c6d083da87120b807765acdb2074d
parent791e6a841bf80a4c3843f093c392211c82118d9c (diff)
Usage of wine depends on platform
Mwlib is being run internally to make it faster
-rw-r--r--helpcontent2/wiki-to-help/README27
-rwxr-xr-xhelpcontent2/wiki-to-help/convert.py79
-rw-r--r--helpcontent2/wiki-to-help/hhc.py64
-rw-r--r--helpcontent2/wiki-to-help/mw.py26
4 files changed, 151 insertions, 45 deletions
diff --git a/helpcontent2/wiki-to-help/README b/helpcontent2/wiki-to-help/README
new file mode 100644
index 0000000000..cf95023977
--- /dev/null
+++ b/helpcontent2/wiki-to-help/README
@@ -0,0 +1,27 @@
+Conversion of an XML-Dump to platformspecific help files
+----------------------------------------------------
+1 INSTALLATION
+
+The following programs are requiered:
+ - mwlib
+ - python
+ - python-lxml
+ - xsltproc
+
+1.1 On GNU and UNIX
+
+ - Install wine
+ - Execute HHC/install_hhc.sh
+
+1.2 On Windows
+
+ - Install HHC from http://go.microsoft.com/fwlink/?LinkId=14188
+
+2 USAGE
+
+3 LICENSE
+
+The following applies to all files if not stated differently
+
+ - Licensed under GNU GPLv3
+ - Copyright 2011 Timo Richter
diff --git a/helpcontent2/wiki-to-help/convert.py b/helpcontent2/wiki-to-help/convert.py
index 0298391364..89cdac428e 100755
--- a/helpcontent2/wiki-to-help/convert.py
+++ b/helpcontent2/wiki-to-help/convert.py
@@ -17,45 +17,15 @@ Microsoft HHC: http://go.microsoft.com/fwlink/?LinkId=14188
import xml.dom.minidom as minidom
import subprocess, tempfile, os, shutil
-class Wine(object):
- #driveletter="j:" #final
-
- def __init__(self,workingDir,driveletter):
- """ Setup the wine environment. Granting access so that wine is able to output files to @workingDir.
- @workingDir will be accessable via @driveletter
- E.g. Wine("/tmp/dir","j:") """
- homedir = os.path.expanduser('~')
- wineprefix=os.path.join(homedir,".wine")
- drive=os.path.join(wineprefix,"dosdevices",driveletter)
- if os.path.lexists(drive):
- self.driveBak = drive+".bak"
- shutil.move(drive,self.driveBak)
- os.symlink(workingDir,drive)
- self.drive = drive
- #self.driveBak = driveBak
-
- def ex(self,*cmd):
- """ execute something with wine """
- cmd = [elem for elem in cmd]
- cmd = ["/usr/bin/wine"]+cmd
- r= (subprocess.Popen(cmd).wait())
- return r
-
- def __call__(self,*cmd):
- return self.ex(*cmd)
-
- def __del__(self):
- os.remove(self.drive)
- if hasattr(self,'driveBak'):
- shutil.move(self.driveBak,self.drive)
-
-
+from hhc import HHC
+from mw import MW
+scriptpath=os.path.dirname(os.path.realpath(__file__) )
class Main(object):
workingDir = "./test" # final
- mwpath='/usr/local/bin/' # final
- style='/usr/share/xml/docbook/stylesheet/docbook-xsl/htmlhelp/htmlhelp.xsl' # final
+ #mwpath='/usr/local/bin/' # final
+ style=os.path.join(scriptpath,'xsl/htmlhelp/htmlhelp.xsl') # final
tmp=None
@@ -75,30 +45,49 @@ class Main(object):
self.workingDir = os.path.abspath(self.workingDir)
self.style = os.path.abspath(self.style)
- self.wine = Wine(self.tmp,"j:")
+ self.hhc = HHC()
self.convert("test2.xml",self.workingDir)
- def convert(self,source,dest):
+ def convert(self,source,dest,startpage=None):
"""
Create the converted files.
@source XML-Dump-file
@dest Directory for output
+ @startpage Path to an html file
"""
tmp = self.tmp
try:
os.mkdir(dest)
except OSError:
pass
-
names = self.getArtNames(source)
- self.ex(self.mwpath+"mw-buildcdb","--input",source,"--output",tmp) \
- and self.ex(
- self.mwpath+"mw-render","--config=%s/wikiconf.txt"%(tmp),
- "-w","docbook","-o",tmp+"/docbook.xml",*names) \
- and (shutil.copy(tmp+'/docbook.xml',dest) or True) \
+ MW.buildcdb(source,tmp)
+ MW.render("--config=%s/wikiconf.txt"%(tmp),
+ "-w","docbook","-o",tmp+"/docbook.xml",*names)
+
+ #and mwlib.apps.render
+ #self.ex(self.mwpath+"mw-buildcdb","--input",source,"--output",tmp) and \
+ #self.ex(
+ # self.mwpath+"mw-render","--config=%s/wikiconf.txt"%(tmp),
+ # "-w","docbook","-o",tmp+"/docbook.xml",*names) \
+ (shutil.copy(tmp+'/docbook.xml',dest) or True) \
and self.ex("/usr/bin/xsltproc","--nonet","--novalid","-o",tmp+'/',self.style,tmp+'/docbook.xml') \
- and (self.wine("c:\\htmlhelp\\hhc.exe","j:\\htmlhelp.hhp") or True) \
- and (shutil.copy(tmp+'/htmlhelp.chm',dest) or True)
+ and self.setStartpage(startpage) \
+ and (self.hhc(tmp) or True) \
+ and (shutil.copy(os.path.join(tmp,'htmlhelp.chm'),dest) or True)
+
+ def setStartpage(self,startpage):
+ """
+ Private.
+ Copies @startpage to our tmp dir so that it will be used as the start page.
+ @return False if @startpage doesnt exist, otherwise True.
+ """
+ if startpage is None: return True
+ filename="index.html"
+ if not os.path.exist(startpage): return False
+ os.remove(os.path.join(self.tmp,filename))
+ shutil.copy(startpage, os.path.join(self.tmp,filename))
+ return True
def __del__(self):
shutil.rmtree(self.tmp) # remove temp files
diff --git a/helpcontent2/wiki-to-help/hhc.py b/helpcontent2/wiki-to-help/hhc.py
new file mode 100644
index 0000000000..d2d8302604
--- /dev/null
+++ b/helpcontent2/wiki-to-help/hhc.py
@@ -0,0 +1,64 @@
+import platform, os, subprocess
+
+class HHC(object):
+ """ Class for execution of Html Help Compiler """
+ hhcexe="c:\\htmlhelp\\hhc.exe"
+
+ def __init__(self):
+ pass
+
+ def exWindows(self,source):
+ """ Private. Compile @source calling HHC natively under Windows """
+ cmd=[self.hhcexe,os.path.join(source,"htmlhelp.hhp")]
+ r = (subprocess.Popen(cmd).wait())
+ return r
+
+ def exWine(self,source):
+ """ Private. Compile @source calling HHC via Wine """
+ #dirname = os.path.dirname(source)
+ wine = Wine(source,"j:")
+ r = wine(self.hhcexe,"j:\\htmlhelp.hhp")
+ del wine
+ return r
+
+ def __call__(self,source):
+ """
+ Converts @source with HHC
+ @source path to input directory that contains htmlhelp.hhp
+ """
+ windows=(platform.system()=="Windows")
+ if windows is False:
+ self.exWine(source)
+ else:
+ self.exWindows(source)
+
+class Wine(object):
+ # TODO: this should be a singleton
+ def __init__(self,workingDir,driveletter):
+ """ Setup the wine environment. Granting access so that wine is able to output files to @workingDir.
+ @workingDir will be accessable via @driveletter
+ E.g. Wine("/tmp/dir","j:") """
+ homedir = os.path.expanduser('~')
+ wineprefix=os.path.join(homedir,".wine")
+ drive=os.path.join(wineprefix,"dosdevices",driveletter)
+ if os.path.lexists(drive):
+ self.driveBak = drive+".bak"
+ shutil.move(drive,self.driveBak)
+ os.symlink(workingDir,drive)
+ self.drive = drive
+ #self.driveBak = driveBak
+
+ def ex(self,*cmd):
+ """ execute something with wine """
+ cmd = [elem for elem in cmd]
+ cmd = ["/usr/bin/wine"]+cmd
+ r= (subprocess.Popen(cmd).wait())
+ return r
+
+ def __call__(self,*cmd):
+ return self.ex(*cmd)
+
+ def __del__(self):
+ os.remove(self.drive)
+ if hasattr(self,'driveBak'):
+ shutil.move(self.driveBak,self.drive)
diff --git a/helpcontent2/wiki-to-help/mw.py b/helpcontent2/wiki-to-help/mw.py
new file mode 100644
index 0000000000..d2709cc6bc
--- /dev/null
+++ b/helpcontent2/wiki-to-help/mw.py
@@ -0,0 +1,26 @@
+import mwlib.cdbwiki, mwlib.apps.render, mwlib.apps
+import sys
+
+class MW(object):
+ """ This is the proxy class for mwlib """
+
+ @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):
+ return MW._setArgs(mwlib.apps.render.Main(),args)