summaryrefslogtreecommitdiff
path: root/scripts/template.py
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2011-10-08 15:32:26 +0200
committerChristian Franke <nobody@nowhere.ws>2011-10-08 15:32:26 +0200
commit1019adda9a8e8a76aa712b7416cad26d47010b3b (patch)
treeeab08bb826834346816d64995d95695117a789d7 /scripts/template.py
parent01614fc0305d34c4f9ffd87a98a4addd2c687dee (diff)
place new template script
Diffstat (limited to 'scripts/template.py')
-rwxr-xr-xscripts/template.py136
1 files changed, 91 insertions, 45 deletions
diff --git a/scripts/template.py b/scripts/template.py
index 4da5fc2..748df8c 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -1,71 +1,117 @@
-#!/usr/bin/python
+#!/usr/bin/env python
+#Filename: newtemp.py
+#Author: stayawake@lavabit.com
-import string
+
+import os
+import os.path
+import sys
+import getopt
import time
import datetime
from string import Template
+import ConfigParser
-def readfiles(prefix):
+def readdir(directory):
- #set globals
global content
- global keywords
- global desc_de
- global desc_en
-
- #set content
- f = open(prefix + ".content.html", "r")
- content = f.read()
- f.close
-
- #set keywords
- f = open(prefix + ".keywords", "r")
- keywords = f.read()
- f.close
+ content= {"content.html":"", "keywords":"", "desc_de":"", "desc_en":""}
- #set german description
- f = open(prefix + ".desc_de", "r")
- desc_de = f.read()
- f.close
-
- #set english description
- f = open(prefix + ".desc_en", "r")
- desc_en = f.read()
- f.close
+ for c in content:
+ f = open(os.path.join(directory, c), "r")
+ content[c] = f.read()
+ f.close
+
-def substitute(target, prefix, htmltemplate, datenow, chattopic, keywords, content, desc_de, desc_en):
+def substitute(target, prefix, htmltemplate, datenow, topic, content):
#create template-string
htmltext = Template(htmltemplate)
- htmltext = htmltext.substitute(template_date = datenow, template_chattopic = chattopic, template_keywords = keywords, template_content = content, template_desc_de = desc_de, template_desc_en = desc_en)
+ htmltext = htmltext.substitute(
+ template_date = datenow,
+ template_chattopic = topic,
+ template_keywords = content["keywords"],
+ template_content = content["content.html"],
+ template_desc_de = content["desc_de"],
+ template_desc_en = content["desc_en"]
+ )
- #write it to the outpufile
- outputfile = open(target + prefix + ".html", "w")
+ #write it to the outputfile
+ outputfile = open(os.path.join(target, page + ".html"), "w")
outputfile.write(htmltext)
outputfile.close()
-contentpath = "../template/"
-target = "../public/"
+
+def readarguments(argv):
+
+ global configfile
+ global verbose
+
+ try:
+ opts, args = getopt.getopt(argv, "c:vh", ["config=", "verbose", "help"])
+ except getopt.GetoptError:
+ print "There is a problem with your argument(s)"
+ sys.exit(2)
+ 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 "Please read the non-existing man page for further assistance"
+ sys.exit(0)
+
+
+configfile = "template.conf"
+verbose = False
+basedir = os.path.dirname(os.path.abspath(__file__))
+
+readarguments(sys.argv[1:])
+
+config = ConfigParser.ConfigParser()
+if not os.path.isabs(configfile):
+ configfile = os.path.join(basedir, configfile)
+config.read(configfile)
+path = config.get("Default", "path")
+if not os.path.isabs(path):
+ path = os.path.join(basedir, path)
+
+target = config.get("Default", "target")
+if not os.path.isabs(target):
+ target = os.path.join(basedir, target)
+
+pagepath = os.path.join(path, "pages")
+templatepath = os.path.join(path, "template")
+topicpath = os.path.join(path, "topic")
+
+if verbose:
+ print "Pagepath: %s" % pagepath
+ print "Templatepath: %s" % templatepath
+ print "topicpath: %s" % topicpath
#set template
-f = open(contentpath + "template.html", "r")
+f = open(os.path.join(templatepath, "template.html"), "r")
htmltemplate = f.read()
f.close
-print ("template read")
+if verbose:
+ print "template read"
-#set chattopic
-f = open(contentpath + "chattopic", "r")
-chattopic = f.read()
+#set topic
+f = open(os.path.join(topicpath, "topic"), "r")
+topic = f.read()
f.close
-print ("chattopic read")
+if verbose:
+ print "topic read"
#set date
datenow = time.strftime("%Y-%m-%dT%H:%M:%S +0100")
-print ("Set date: " + datenow)
-
-prefixes = ['index', 'neues', 'termine', 'raeume', 'lage', 'kontakt', 'verein', 'impressum', 'webcam', 'zensusinfo', '404', 'subforum', 'kaffeeklatsch', 'sublounge', 'medien']
+if verbose:
+ print "Set date: " + datenow
-for prefix in prefixes:
- readfiles(contentpath + prefix)
- substitute(target, prefix, htmltemplate, datenow, chattopic, keywords, content, desc_de, desc_en)
- print(prefix + ".html written")
+for page in os.listdir(pagepath):
+ prefix = os.path.join(pagepath, page)
+ readdir(prefix)
+ substitute(target, prefix, htmltemplate, datenow, topic, content)
+ if verbose:
+ print "%s.html written" % prefix
+# vi: noexpandtab:tabstop=8:shiftwidth=8