summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2012-09-16 20:58:01 +0200
committerChristian Franke <nobody@nowhere.ws>2012-09-16 22:01:45 +0200
commit1c3c306f45f3e18cc0174cd1ea9cca36f37696dc (patch)
treebb67c4cc3b3d8d37237523ea5b26b4b345d82557 /scripts
parent722bde297e6ed7fb3978b8e785ffcbd6cd19d4f6 (diff)
Add some stuff for the wiki
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/template.py10
-rwxr-xr-xscripts/wikitemplate.py94
2 files changed, 101 insertions, 3 deletions
diff --git a/scripts/template.py b/scripts/template.py
index 2cfdf79..f6b073e 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -27,9 +27,11 @@ class Page:
data = {"content.html":"", "keywords":"", "desc_de":"", "desc_en":""}
for c in data:
- f = open(os.path.join(pagepath, name, c), "r")
- data[c] = f.read()
- f.close
+ try:
+ with open(os.path.join(pagepath, name, c), "r") as f:
+ data[c] = f.read()
+ except Exception:
+ sys.excepthook(*sys.exc_info())
self._data = plugin.plugin_manager.process_content(data)
@@ -104,6 +106,8 @@ if __name__ == '__main__':
if __name__ == '__main__':
for page in os.listdir(pagepath):
+ if page.endswith('_template'):
+ continue
Page(page).render_and_save()
if verbose:
print "%s.html written" % page
diff --git a/scripts/wikitemplate.py b/scripts/wikitemplate.py
new file mode 100755
index 0000000..612219e
--- /dev/null
+++ b/scripts/wikitemplate.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+#Filename: newtemp.py
+#Author: stayawake@lavabit.com
+# ---
+# Copyright (C) 2011 Christian Franke <nobody@nowhere.ws>
+#
+# Permission is hereby granted to use and distribute this
+# file for any purpose, provided the above copyright notice
+# is kept in place.
+#
+
+import imp
+import os
+import os.path
+import sys
+import getopt
+import time
+import datetime
+from string import Template
+import ConfigParser
+
+import plugin
+import template
+
+class WikiTemplate(template.Page):
+ def __init__(self):
+ template.Page.__init__(self, 'wiki_template')
+
+ @property
+ def html(self):
+ #create template-string
+ htmltext = Template(htmltemplate)
+ htmltext = htmltext.substitute(
+ template_date = '', #<TMPL_VAR MTIME>',
+ template_chattopic = topic,
+ template_keywords = self._data["keywords"],
+ template_content = self._data["content.html"],
+ template_desc_de = self._data["desc_de"],
+ template_desc_en = self._data["desc_en"]
+ )
+ return htmltext
+
+configfile = "template.conf"
+verbose = False
+opts, args = getopt.getopt(sys.argv[1:], "c:vh", ["config=", "verbose", "help"])
+for opt, arg in opts:
+ if opt in ("-c", "--config"):
+ configfile = arg
+ elif opt in ("-v", "--verbose"):
+ verbose = True
+ elif opt in ("-h", "--help"):
+ print >>sys.stderr, "Please read the non-existing man page for further assistance"
+ sys.exit(0)
+
+basedir = os.path.dirname(os.path.abspath(__file__))
+
+def makeabs(path):
+ if not os.path.isabs(path):
+ return os.path.join(basedir, path)
+ return path
+
+configfile = makeabs(configfile)
+config = ConfigParser.ConfigParser()
+config.read(configfile)
+
+path = makeabs(config.get("Default", "path"))
+targetdir = makeabs(config.get("Default", "target"))
+pagepath = os.path.join(path, "pages")
+templatepath = os.path.join(path, "template")
+topicpath = os.path.join(path, "topic")
+
+#set template
+htmltemplate = open(os.path.join(templatepath, "template.html"), "r").read()
+topic = open(os.path.join(topicpath, "topic"), "r").read()
+datenow = time.strftime("%Y-%m-%dT%H:%M:%S +0100")
+
+if __name__ == '__main__':
+ if verbose:
+ print >>sys.stderr, "Pagepath: %s" % pagepath
+ print >>sys.stderr, "Templatepath: %s" % templatepath
+ print >>sys.stderr, "topicpath: %s" % topicpath
+ print >>sys.stderr, "datenow: %s" % datenow
+
+ pluginlist = config.items('Plugins')
+ for pluginname, pluginarg in pluginlist:
+ modinfo = imp.find_module(pluginname)
+ try:
+ imp.load_module(pluginname, *modinfo)
+ finally:
+ modinfo[0].close()
+
+ print WikiTemplate().html
+
+# vi: noexpandtab:tabstop=8:shiftwidth=8