# -*- coding: iso-8859-1 -*- """ MoinMoin - Dump a MoinMoin wiki to static pages based on "moin.py export dump" command """ import sys, os, time, StringIO, codecs, shutil, re, errno from MoinMoin import config, wikiutil, Page from MoinMoin.request import RequestCLI from MoinMoin.action import AttachFile HTML_SUFFIX = ".html" page_template = u'''
'
page_front_page = u"Welcome"
interwikiname = 'damaris'
data_dir = '%(pwd)s/wikidata/'
data_underlay_dir = '%(pwd)s/wikiunderlay'
url_prefix = '/damaris/wiki'
theme_default = 'modern'
"""%{"pwd": os.curdir, "underlay": "/home/achim/underlay" }
config_file = open("wikiconfig.py","w")
print >>config_file, wikiconfig_template
config_file.close()
# start with wiki entry page
request = RequestCLI(pagename="Welcome")
# fix url_prefix so we get relative paths in output html
url_prefix = "."
request.cfg.url_prefix = url_prefix
pages = request.rootpage.getPageList(user='') # get list of all pages in wiki
pages.sort()
# extract a list of pages to be extracted
# trial session to fat!!!
try:
pages_match = re.compile("^(Tutorial|auxiliary tools|overview|installation|code snippets)")
pages = [page for page in pages if pages_match.match(page)]
except:
print "did not find suitable pages"
raise
wikiutil.quoteWikinameURL = lambda pagename, qfn=wikiutil.quoteWikinameFS: (qfn(pagename) + HTML_SUFFIX)
AttachFile.getAttachUrl = lambda pagename, filename, request, addts=0, escaped=0: (_attachment(request, pagename, filename, outputdir))
errfile = os.path.join(outputdir, 'error.log')
errlog = open(errfile, 'w')
errcnt = 0
page_front_page = wikiutil.getSysPage(request, request.cfg.page_front_page).page_name
page_title_index = wikiutil.getSysPage(request, 'TitleIndex').page_name
page_word_index = wikiutil.getSysPage(request, 'WordIndex').page_name
navibar_html = ''
for p in [page_front_page, page_title_index, page_word_index]:
navibar_html += ' [%s]' % (wikiutil.quoteWikinameURL(p), wikiutil.escape(p))
urlbase = request.url # save wiki base url
for pagename in pages:
# we have the same name in URL and FS
file = wikiutil.quoteWikinameURL(pagename)
print ('Writing "%s"...' % file)
try:
pagehtml = ''
request.url = urlbase + pagename # add current pagename to url base
page = Page.Page(request, pagename)
request.page = page
try:
request.reset()
pagehtml = request.redirectedOutput(page.send_page, request, count_hit=0, content_only=1)
except:
errcnt = errcnt + 1
print >>sys.stderr, "*** Caught exception while writing page!"
print >>errlog, "~" * 78
print >>errlog, file # page filename
import traceback
traceback.print_exc(None, errlog)
finally:
timestamp = time.strftime("%Y-%m-%d %H:%M")
filepath = os.path.join(outputdir, file)
fileout = codecs.open(filepath, 'w', config.charset)
logo_html = '
'
fileout.write(page_template % {
'charset': config.charset,
'pagename': pagename,
'pagehtml': pagehtml,
'logo_html': logo_html,
'navibar_html': navibar_html,
'timestamp': timestamp,
'theme': request.cfg.theme_default,
})
fileout.close()
# ToDo: insert style sheets and logo
errlog.close()
if errcnt:
print >>sys.stderr, "*** %d error(s) occurred, see '%s'!" % (errcnt, errfile)
if __name__=="__main__":
PluginScript().mainloop()