Code cleanup (inconsistency between " and ')

This commit is contained in:
Stefan Ritter 2010-12-14 09:42:38 +01:00
parent 6adce37ab0
commit cbf2032d78
1 changed files with 310 additions and 309 deletions

View File

@ -10,12 +10,9 @@
# Authors: Stefan Ritter <xeno@thehappy.de> # Authors: Stefan Ritter <xeno@thehappy.de>
# Adrian Vondendriesch <disco-stu@disco-stu.de> # Adrian Vondendriesch <disco-stu@disco-stu.de>
# Pascal Turbing <pascal@turbing.de> # Pascal Turbing <pascal@turbing.de>
#
# Description: A simple blogging software # Description: A simple blogging software
# TODO:
# * Complete Atom Feed (like RSS)
# * Fix broken charset in outgoing mails (needs some testing)
import os import os
import sys import sys
import time import time
@ -29,94 +26,96 @@ from glob import glob
from random import randint from random import randint
# A wonderful place for doing some regexp ;) # A wonderful place for doing some regexp ;)
no_break = re.compile('^\s*(<ul|</ul>|<li|</li>|<ol|</ol>|<table|</table>|<tr|</tr>|<td|</td>|<th|</th>|<p|</p>).*$') no_break = re.compile("^\s*(<ul|</ul>|<li|</li>|<ol|</ol>|<table|</table>|<tr|</tr>|<td|</td>|<th|</th>|<p|</p>).*$")
line_start_hyphen = re.compile('^-.*$') line_start_hyphen = re.compile("^-.*$")
line_start_plus = re.compile('^\+.*$') line_start_plus = re.compile("^\+.*$")
tab = "\t" tab = "\t"
def generate_uuid(string): def generate_uuid(string):
string_md5sum = newmd5(string).hexdigest() string_md5sum = newmd5(string).hexdigest()
string = str.join('-', (string_md5sum[0:8], string_md5sum[8:12], string_md5sum[12:16], string_md5sum[16:20], string_md5sum[20:32])) string = str.join("-", (string_md5sum[0:8], string_md5sum[8:12], string_md5sum[12:16], string_md5sum[16:20], string_md5sum[20:32]))
return string return string
def errorpage(string): def errorpage(string):
document_header('xhtml-strict') document_header("xhtml-strict")
print '<head><title>Error!</title></head>' print "<head><title>Error!</title></head>"
print '<body>' print "<body>"
print tab + string print tab + string
print '</body>' print "</body>"
print '</html>' print "</html>"
sys.exit() sys.exit()
def document_header(string): def document_header(string):
if string == "xhtml-transitional": if string == "xhtml-transitional":
print 'Content-type: text/html\n' print "Content-type: text/html\n"
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\""
print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' print " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
if string == "xhtml-strict": if string == "xhtml-strict":
print 'Content-type: text/html\n' print "Content-type: text/html\n"
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' print " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' print "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
if string == "atom": if string == "atom":
print 'Content-type: application/atom+xml\n' print "Content-type: application/atom+xml\n"
print '<?xml version="1.0" encoding="utf-8"?>' print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
print '<feed xmlns="http://www.w3.org/2005/Atom">' print "<feed xmlns=\"http://www.w3.org/2005/Atom\">"
if string == "rss": if string == "rss":
print 'Content-type: application/rss+xml\n' print "Content-type: application/rss+xml\n"
print '<?xml version="1.0" encoding="utf-8"?>' print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
print '<rss version="2.0">' print "<rss version=\"2.0\">"
# Parse configuration
configuration = ConfigParser() configuration = ConfigParser()
# Look for a configuration: for config in ["../blogthonrc", "../.blogthonrc", "configuration"]:
if os.path.exists('../blogthonrc'): if os.path.exists(config):
configuration.read('../blogthonrc') configuration.read(config)
elif os.path.exists('../.blogthonrc'): config = True
configuration.read('../.blogthonrc') break
elif os.path.exists('configuration'): else:
configuration.read('configuration') config = False
else:
errorpage('No suitable configuration found!')
sys.exit()
try: blog_title = configuration.get('personal', 'blog_title') if not config:
except: errorpage('"blog_title" is missing in configuration!') errorpage("No suitable configuration found!")
try: blog_subtitle = configuration.get('personal', 'blog_subtitle') try: blog_title = configuration.get("personal", "blog_title")
except: errorpage('"blog_subtitle" is missing in configuration!') except: errorpage("\"blog_title\" is missing in configuration!")
try: blog_url = configuration.get('personal', 'blog_url') try: blog_subtitle = configuration.get("personal", "blog_subtitle")
except: errorpage('"blog_url" is missing in configuration!') except: errorpage("\"blog_subtitle\" is missing in configuration!")
try: keywords = configuration.get('personal', 'keywords') try: blog_url = configuration.get("personal", "blog_url")
except: errorpage('"keywords" is missing in configuration!') except: errorpage("\"blog_url\" is missing in configuration!")
try: entries_dir = configuration.get('personal', 'entries_dir') try: keywords = configuration.get("personal", "keywords")
except: errorpage('"entries_dir" is missing in configuration!') except: errorpage("\"keywords\" is missing in configuration!")
try: entries_dir = configuration.get("personal", "entries_dir")
except: errorpage("\"entries_dir\" is missing in configuration!")
if not os.path.exists(entries_dir): if not os.path.exists(entries_dir):
errorpage('"entries_dir" does not exist!') errorpage("\"entries_dir\" does not exist!")
try: entries_suffix = configuration.get('personal', 'entries_suffix') try: entries_suffix = configuration.get("personal", "entries_suffix")
except: errorpage('"entries_suffix" is missing in configuration!') except: errorpage("\"entries_suffix\" is missing in configuration!")
try: staticpages_dir = configuration.get('personal', 'staticpages_dir') try: staticpages_dir = configuration.get("personal", "staticpages_dir")
except: errorpage('"staticpages_dir" is missing in configuration!') except: errorpage("\"staticpages_dir\" is missing in configuration!")
if not os.path.exists(staticpages_dir): if not os.path.exists(staticpages_dir):
errorpage('"staticpages_dir" does not exist!') errorpage("\"staticpages_dir\" does not exist!")
try: plugins_dir = configuration.get('personal', 'plugins_dir') try: plugins_dir = configuration.get("personal", "plugins_dir")
except: errorpage('"plugins_dir" is missing in configuration!') except: errorpage("\"plugins_dir\" is missing in configuration!")
if not os.path.exists(plugins_dir): if not os.path.exists(plugins_dir):
errorpage('"plugins_dir" does not exist!') errorpage("\"plugins_dir\" does not exist!")
try: style = configuration.get('look', 'style') try: style = configuration.get("look", "style")
except: errorpage('"style" is missing in configuration!') except: errorpage("\"style\" is missing in configuration!")
try: language = configuration.get('look', 'language') try: language = configuration.get("look", "language")
except: errorpage('"language" is missing in configuration!') except: errorpage("\"language\" is missing in configuration!")
if language == "de": if language == "de":
blog_locale = ("Seiten", "Monate", "Links", "Keine Kommentare", "Kommentare", "Alle Einträge anzeigen...", "Name", "Text", "Absenden") blog_locale = ("Seiten", "Monate", "Links", "Keine Kommentare", "Kommentare", "Alle Einträge anzeigen...", "Name", "Text", "Absenden")
locales_de = ("de_DE.UTF-8", "de_DE.@euro", "de_DE") locales_de = ("de_DE.UTF-8", "de_DE.@euro", "de_DE")
@ -137,53 +136,53 @@ else:
except: continue except: continue
else: locale.setlocale(locale.LC_TIME, None) else: locale.setlocale(locale.LC_TIME, None)
try: entries_per_page = configuration.getint('look', 'entries_per_page') try: entries_per_page = configuration.getint("look", "entries_per_page")
except: errorpage('"entries_per_page" is missing in configuration!') except: errorpage("\"entries_per_page\" is missing in configuration!")
try: monthlist = configuration.get('look', 'monthlist') try: monthlist = configuration.get("look", "monthlist")
except: errorpage('"monthlist" is missing in configuration!') except: errorpage("\"monthlist\" is missing in configuration!")
try: staticpages = configuration.get('look', 'staticpages') try: staticpages = configuration.get("look", "staticpages")
except: errorpage('"staticpages" is missing in configuration!') except: errorpage("\"staticpages\" is missing in configuration!")
try: linklist = configuration.get('look', 'linklist') try: linklist = configuration.get("look", "linklist")
except: errorpage('"linklist" is missing in configuration!') except: errorpage("\"linklist\" is missing in configuration!")
if not os.path.exists("linklist"): if not os.path.exists("linklist"):
errorpage('"linklist" does not exist!') errorpage("\"linklist\" does not exist!")
try: permalinks = configuration.get('look', 'permalinks') try: permalinks = configuration.get("look", "permalinks")
except: errorpage('"permalinks" is missing in configuration!') except: errorpage("\"permalinks\" is missing in configuration!")
try: comments = configuration.get('look', 'comments') try: comments = configuration.get("look", "comments")
except: errorpage('"comments" is missing in configuration!') except: errorpage("\"comments\" is missing in configuration!")
try: newest_first = configuration.get('look', 'newest_first') try: newest_first = configuration.get("look", "newest_first")
except: errorpage('"newest_first" is missing in configuration!') except: errorpage("\"newest_first\" is missing in configuration!")
try: new_comment_mail = configuration.get('smtp', 'new_comment_mail') try: new_comment_mail = configuration.get("smtp", "new_comment_mail")
except: errorpage('"new_comment_mail" is missing in configuration!') except: errorpage("\"new_comment_mail\" is missing in configuration!")
try: mail_to = configuration.get('smtp', 'mail_to') try: mail_to = configuration.get("smtp", "mail_to")
except: errorpage('"mail_to" is missing in configuration!') except: errorpage("\"mail_to\" is missing in configuration!")
try: smtp_host = configuration.get('smtp', 'smtp_host') try: smtp_host = configuration.get("smtp", "smtp_host")
except: errorpage('"smtp_host" is missing in configuration!') except: errorpage("\"smtp_host\" is missing in configuration!")
try: feed_preview = configuration.get('feed', 'feed_preview') try: feed_preview = configuration.get("feed", "feed_preview")
except: errorpage('"feed_preview" is missing or empty in configuration!') except: errorpage("\"feed_preview\" is missing or empty in configuration!")
# Read POST Variables # Read POST Variables
action = FieldStorage() action = FieldStorage()
month_display = action.getvalue('m') month_display = action.getvalue("m")
static_display = action.getvalue('s') static_display = action.getvalue("s")
if static_display: static_display = static_display.replace('/', '') if static_display: static_display = static_display.replace("/", "")
post_display = action.getvalue('p') post_display = action.getvalue("p")
if post_display: post_display = post_display.replace(' ', '-').replace('/', '') if post_display: post_display = post_display.replace(" ", "-").replace("/", "")
allentries_display = action.getvalue('a') allentries_display = action.getvalue("a")
feed_display = action.getvalue('feed') feed_display = action.getvalue("feed")
if not month_display: month_display = "" if not month_display: month_display = ""
if not post_display: post_display = "" if not post_display: post_display = ""
if not static_display: static_display = "" if not static_display: static_display = ""
@ -191,11 +190,11 @@ if not allentries_display: allentries_display = ""
if not feed_display: feed_display = "" if not feed_display: feed_display = ""
# Commentstuff # Commentstuff
ctitle = action.getvalue('ctitle') ctitle = action.getvalue("ctitle")
cname = action.getvalue('cname') cname = action.getvalue("cname")
ctext = action.getvalue('ctext') ctext = action.getvalue("ctext")
cquiz = action.getvalue('cquiz') cquiz = action.getvalue("cquiz")
cquizv = action.getvalue('cquizv') cquizv = action.getvalue("cquizv")
if not ctitle: ctitle = "" if not ctitle: ctitle = ""
if not cname: cname = "" if not cname: cname = ""
if not ctext: ctext = "" if not ctext: ctext = ""
@ -205,53 +204,55 @@ if not cquizv: cquizv = ""
# Comment to commit? # Comment to commit?
if cname and ctext and ctitle: if cname and ctext and ctitle:
# Prevent XSS hacks # Prevent XSS hacks
cname = cname.replace('<', '&lt;').replace('>', '&gt;').replace('\'', '&quot;') cname = cname.replace("<", "&lt;").replace(">", "&gt;").replace("\'", "&quot;")
ctext = ctext.replace('<', '&lt;').replace('>', '&gt;').replace('\'', '&quot;') ctext = ctext.replace("<", "&lt;").replace(">", "&gt;").replace("\'", "&quot;")
# Add comment # Add comment
if not cquiz == cquizv: if not cquiz == cquizv:
errorpage("Brainmode") errorpage("Brainmode")
else: else:
comments_file = glob(entries_dir + ctitle + '.comments') comments_file = os.path.join(entries_dir, ctitle + ".comments")
if not comments_file: if not os.path.exists(comments_file):
try: try:
content = open(entries_dir + ctitle + '.comments', "w") content = open(comments_file, "w")
content.close() content.close()
except: except:
errorpage('"' + entries_dir + '" isn\'t writable!') errorpage("\"" + entries_dir + "\" isn\'t writable!")
try: try:
content = open(entries_dir + ctitle + '.comments', "a") content = open(comments_file, "a")
content.write("-." + cname + "\n") content.write("-." + cname + "\n")
content.write("+." + time.strftime("%c", time.localtime()) + "\n") content.write("+." + time.strftime("%c", time.localtime()) + "\n")
ctext = ctext.split("\n") ctext = ctext.split("\n")
for line in ctext: for line in ctext:
content.write("." + line + "\n") content.write("." + line + "\n")
content.close() content.close()
# Send mail? # Send mail?
if not new_comment_mail == 'False': if not new_comment_mail == "False":
msg = 'From: Blogthon\nTo: ' + mail_to + '\nSubject: New comment on ' + blog_title + '\n\nSomeone wrote a comment to this entry: ' + blog_url + '?p=' + ctitle.replace(' ', '-') msg = "From: Blogthon\nTo: " + mail_to + "\nSubject: New comment on " + blog_title + "\n\nSomeone wrote a comment to this entry: " + blog_url + "?p=" + ctitle.replace(" ", "-")
smtp = SMTP(smtp_host) smtp = SMTP(smtp_host)
smtp.starttls() # TODO: some hosts need TLS, needs testing smtp.starttls()
smtp.sendmail(blog_title, mail_to, msg) smtp.sendmail(blog_title, mail_to, msg)
smtp.quit() smtp.quit()
except: except:
errorpage('Comment cannot be written!') errorpage("Comment cannot be written!")
# Read entries and store their title and timestamp # Read entries and store their title and timestamp
entries = [] entries = []
entries_list = glob(entries_dir + '*.' + entries_suffix) entries_list = glob(entries_dir + "*." + entries_suffix)
for entry in entries_list: for entry in entries_list:
title = entry.replace(entries_dir, '', 1) title = entry.replace(entries_dir, "", 1)
title = title.replace('.' + entries_suffix, '') title = title.replace("." + entries_suffix, "")
stampfile = os.path.join(entries_dir, title + '.stamp') stampfile = os.path.join(entries_dir, title + ".stamp")
if os.path.exists(stampfile): if os.path.exists(stampfile):
timestamp = os.stat(stampfile) timestamp = os.stat(stampfile)
else: else:
timestamp = os.stat(entry) timestamp = os.stat(entry)
stampfile = os.path.join(entries_dir, title + '.stamp') stampfile = os.path.join(entries_dir, title + ".stamp")
stamp = open(stampfile, 'w') stamp = open(stampfile, "w")
stamp.close() stamp.close()
utime = os.utime(stampfile, (os.stat(entry)[8], os.stat(entry)[8])) utime = os.utime(stampfile, (os.stat(entry)[8], os.stat(entry)[8]))
@ -270,207 +271,207 @@ if feed_display == "atom":
blog_title_md5sum = generate_uuid(blog_title) blog_title_md5sum = generate_uuid(blog_title)
# Append 0 to the beginning if len of integer is 1 (value<10) # Append 0 to the beginning if len of integer is 1 (value<10)
month = '%(#)02d' % {'#': int(date[1])} month = "%(#)02d" % {"#": int(date[1])}
day = '%(#)02d' % {'#': int(date[2])} day = "%(#)02d" % {"#": int(date[2])}
hour = '%(#)02d' % {'#':int(date[3])} hour = "%(#)02d" % {"#":int(date[3])}
min = '%(#)02d' % {'#': int(date[4])} min = "%(#)02d" % {"#": int(date[4])}
sec = '%(#)02d' % {'#': int(date[5])} sec = "%(#)02d" % {"#": int(date[5])}
document_header("atom") document_header("atom")
print '<link href="' + blog_url + '/?feed=atom" rel="self" type="application/atom+xml"/>' print "<link href=\"" + blog_url + "/?feed=atom\" rel=\"self\" type=\"application/atom+xml\"/>"
print tab + '<author>' print tab + "<author>"
print tab*2 + '<name>' + blog_title + '</name>' print tab*2 + "<name>" + blog_title + "</name>"
print tab + '</author>' print tab + "</author>"
print tab + '<title>' + blog_title + '</title>' print tab + "<title>" + blog_title + "</title>"
print tab + '<id>urn:uuid:' + blog_title_md5sum + '</id>' print tab + "<id>urn:uuid:" + blog_title_md5sum + "</id>"
print tab + '<updated>' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z</updated>' print tab + "<updated>" + str(date[0]) + "-" + month + "-" + day + "T" + hour + ":" + min + ":" + sec + "Z</updated>"
print '' print ""
j = len(entries) j = len(entries)
if j > 10: j = 10 if j > 10: j = 10
for i in xrange(0, j): for i in xrange(0, j):
title = str(entries[i][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '') title = str(entries[i][1]).replace(entries_dir, "", 1).replace("." + entries_suffix, "")
date = entries[i][0] date = entries[i][0]
title_md5sum = generate_uuid(title) title_md5sum = generate_uuid(title)
print tab*2 + '<entry>' print tab*2 + "<entry>"
print tab*3 + '<title>' + title + '</title>' print tab*3 + "<title>" + title + "</title>"
print tab*3 + '<link href="' + blog_url + '?p=' + title + '"/>' print tab*3 + "<link href=\"" + blog_url + "?p=" + title + "\"/>"
print tab*3 + '<id>urn:uuid:' + title_md5sum + '</id>' print tab*3 + "<id>urn:uuid:" + title_md5sum + "</id>"
print tab*3 + '<updated>' + str(date[0]) + '-' + month + '-' + day + 'T' + hour + ':' + min + ':' + sec + 'Z</updated>' print tab*3 + "<updated>" + str(date[0]) + "-" + month + "-" + day + "T" + hour + ":" + min + ":" + sec + "Z</updated>"
print tab*3 + '<summary>' print tab*3 + "<summary>"
content = open(str(entries[i][1]), 'r') content = open(str(entries[i][1]), "r")
for h in xrange(0, int(feed_preview)): for h in xrange(0, int(feed_preview)):
rss_line = content.readline().strip() rss_line = content.readline().strip()
if rss_line != '': if rss_line != "":
print ' ' + rss_line print tab*4 + rss_line
content.close() content.close()
print tab*3 + '</summary>' print tab*3 + "</summary>"
print tab*2 + '</entry>' print tab*2 + "</entry>"
print '</feed>' print "</feed>"
# Generate rss 2.0 feed # Generate rss 2.0 feed
elif feed_display == "rss": elif feed_display == "rss":
document_header("rss") document_header("rss")
print tab + '<channel>' print tab + "<channel>"
print tab*2 + '<title>' + blog_title + '</title>' print tab*2 + "<title>" + blog_title + "</title>"
print tab*2 + '<link>' + blog_url + '</link>' print tab*2 + "<link>" + blog_url + "</link>"
print tab*2 + '<description>' + blog_subtitle + '</description>' print tab*2 + "<description>" + blog_subtitle + "</description>"
date = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime(time.mktime(entries[0][0]))) date = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime(time.mktime(entries[0][0])))
print tab*2 + '<pubDate>' + date + '</pubDate>' print tab*2 + "<pubDate>" + date + "</pubDate>"
print '' print ""
j = len(entries) j = len(entries)
if j > 10: j = 10 if j > 10: j = 10
for i in xrange(0, j): for i in xrange(0, j):
title = str(entries[i][1]).replace('entries/', '', 1).replace('.' + entries_suffix, '') title = str(entries[i][1]).replace(entries_dir, "", 1).replace("." + entries_suffix, "")
date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime(time.mktime(entries[i][0]))) date = time.strftime("%a, %d %b %Y %H:%M:%S %z", time.gmtime(time.mktime(entries[i][0])))
print tab*2 + '<item>' print tab*2 + "<item>"
print tab*3 + '<title>' + title + '</title>' print tab*3 + "<title>" + title + "</title>"
print tab*3 + '<link>' + blog_url + '?p=' + title + '</link>' print tab*3 + "<link>" + blog_url + "?p=" + title + "</link>"
print tab*3 + '<guid>' + blog_url + '?p=' + title + '</guid>' print tab*3 + "<guid>" + blog_url + "?p=" + title + "</guid>"
print tab*3 + '<pubDate>' + date + '</pubDate>' print tab*3 + "<pubDate>" + date + "</pubDate>"
content = open(str(entries[i][1]), 'r') content = open(str(entries[i][1]), "r")
rss_description= '' rss_description= ""
for h in xrange(0, int(feed_preview)): for h in xrange(0, int(feed_preview)):
line = content.readline().strip() line = content.readline().strip()
if line: if line:
rss_description = rss_description + line + '<br />' rss_description = rss_description + line + "<br />"
content.close() content.close()
print tab*3 + '<description><![CDATA[' + rss_description + ']]></description>' print tab*3 + "<description><![CDATA[" + rss_description + "]]></description>"
print tab*2 + '</item>' print tab*2 + "</item>"
print tab + '</channel>' print tab + "</channel>"
print '</rss>' print "</rss>"
# Generate regular page # Generate regular page
else: else:
document_header("xhtml-strict") document_header("xhtml-strict")
print tab + '<head>' print tab + "<head>"
print tab*2 + '<title>' + blog_title + '</title>' print tab*2 + "<title>" + blog_title + "</title>"
print tab*2 + '<meta http-equiv="content-type" content="text/html; charset=utf-8" />' print tab*2 + "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"
print tab*2 + '<meta name="keywords" content="' + keywords + '" />' print tab*2 + "<meta name=\"keywords\" content=\"" + keywords + "\" />"
print tab*2 + '<meta name="description" content="' + blog_title + '" />' print tab*2 + "<meta name=\"description\" content=\"" + blog_title + "\" />"
print tab*2 + '<link rel="stylesheet" type="text/css" href="styles/' + style + '/' + style + '.css" />' print tab*2 + "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/" + style + "/" + style + ".css\" />"
print tab + '</head>' print tab + "</head>"
print tab + '<body>' print tab + "<body>"
print '' print ""
# Plugins # Plugins
sys.path.append(plugins_dir) sys.path.append(plugins_dir)
for plugin in glob(plugins_dir + '*.py'): for plugin in glob(plugins_dir + "*.py"):
__import__ (plugin.split('/')[1].replace('.py', '')) __import__ (plugin.split("/")[1].replace(".py", ""))
# Site header # Site header
print tab*2 + '<div class="header">' print tab*2 + "<div class=\"header\">"
print tab*3 + '<div class="header_title">' print tab*3 + "<div class=\"header_title\">"
print tab*4 + '<a href="?" class="header_link">' + blog_title + '</a>' print tab*4 + "<a href=\"?\" class=\"header_link\">" + blog_title + "</a>"
print tab*3 + '</div>' print tab*3 + "</div>"
print tab*3 + '<div class="header_subtitle">' print tab*3 + "<div class=\"header_subtitle\">"
print tab*4 + '<span class="header_subtitle">' + blog_subtitle + '</span>' print tab*4 + "<span class=\"header_subtitle\">" + blog_subtitle + "</span>"
print tab*3 + '</div>' print tab*3 + "</div>"
print tab*2 + '</div>' print tab*2 + "</div>"
print '' print ""
# RSS feed # RSS feed
print tab*2 + '<div class="rss">' print tab*2 + "<div class=\"rss\">"
print tab*3 + '<a href="?feed=rss" class="rss_link">rss</a>' print tab*3 + "<a href=\"?feed=rss\" class=\"rss_link\">rss</a>"
print tab*2 + '</div>' print tab*2 + "</div>"
print '' print ""
# Atom feed # Atom feed
print tab*2 + '<div class="atom">' print tab*2 + "<div class=\"atom\">"
print tab*3 + '<a href="?feed=atom" class="atom_link">atom</a>' print tab*3 + "<a href=\"?feed=atom\" class=\"atom_link\">atom</a>"
print tab*2 + '</div>' print tab*2 + "</div>"
print '' print ""
# Staticpages # Staticpages
if staticpages == "True": if staticpages == "True":
staticpages = [] staticpages = []
staticpages_list = glob(staticpages_dir + '*') staticpages_list = glob(staticpages_dir + "*")
staticpages_list.sort() staticpages_list.sort()
print tab*2 + '<div class="pages">' print tab*2 + "<div class=\"pages\">"
print tab*3 + '<div class="pages_title">' + blog_locale[0] + '</div>' print tab*3 + "<div class=\"pages_title\">" + blog_locale[0] + "</div>"
print tab*3 + '<div class="pages_list">' print tab*3 + "<div class=\"pages_list\">"
print tab*4 + '<ul class="pages_list">' print tab*4 + "<ul class=\"pages_list\">"
for staticpage in staticpages_list: for staticpage in staticpages_list:
file = open(staticpage, 'r') file = open(staticpage, "r")
header = file.readline() header = file.readline()
if header.split(':', 1)[0] == 'extern_link': if header.split(":", 1)[0] == "extern_link":
link = header.split(':', 1)[1].strip() link = header.split(":", 1)[1].strip()
else: else:
link = re.sub('\w+?\/', '', staticpage) link = re.sub("\w+?\/", "", staticpage)
link = '?s=' + link link = "?s=" + link
file.close() file.close()
title = re.sub('\w+?\/\d+?-', '', staticpage) title = re.sub("\w+?\/\d+?-", "", staticpage)
print tab*5 + '<li class="pages_list_entry"><a href="' + link + '" class="pages_list_entry">' + title + '</a></li>' print tab*5 + "<li class=\"pages_list_entry\"><a href=\"" + link + "\" class=\"pages_list_entry\">" + title + "</a></li>"
print tab*4 + '</ul>' print tab*4 + "</ul>"
print tab*3 + '</div>' print tab*3 + "</div>"
print tab*3 + '<div class="pages_footer"></div>' print tab*3 + "<div class=\"pages_footer\"></div>"
print tab*2 + '</div>' print tab*2 + "</div>"
print '' print ""
# Monthlist # Monthlist
if monthlist == "True": if monthlist == "True":
olddate = "" olddate = ""
print tab*2 + '<div class="months">' print tab*2 + "<div class=\"months\">"
print tab*3 + '<div class="months_title">' + blog_locale[1] + '</div>' print tab*3 + "<div class=\"months_title\">" + blog_locale[1] + "</div>"
print tab*3 + '<div class="months_list">' print tab*3 + "<div class=\"months_list\">"
print tab*4 + '<ul class="months_list">' print tab*4 + "<ul class=\"months_list\">"
for entry in entries: for entry in entries:
date = time.strftime("%m%Y", entry[0]) date = time.strftime("%m%Y", entry[0])
date_display = time.strftime("%h %Y", entry[0]) date_display = time.strftime("%h %Y", entry[0])
if not olddate == date: if not olddate == date:
print tab*5 + '<li class="months_list_entry"><a href="?m=' + date + '" class="months_list_entry">' + date_display + '</a></li>' print tab*5 + "<li class=\"months_list_entry\"><a href=\"?m=" + date + "\" class=\"months_list_entry\">" + date_display + "</a></li>"
olddate = date olddate = date
print tab*4 + '</ul>' print tab*4 + "</ul>"
print tab*3 + '</div>' print tab*3 + "</div>"
print tab*3 + '<div class="months_footer"></div>' print tab*3 + "<div class=\"months_footer\"></div>"
print tab*2 + '</div>' print tab*2 + "</div>"
print '' print ""
# Linklist # Linklist
if linklist == "True": if linklist == "True":
print tab*2 + '<div class="linklist">' print tab*2 + "<div class=\"linklist\">"
print tab*3 + '<div class="linklist_title">' + blog_locale[2] + '</div>' print tab*3 + "<div class=\"linklist_title\">" + blog_locale[2] + "</div>"
print tab*3 + '<div class="linklist_list">' print tab*3 + "<div class=\"linklist_list\">"
print tab*4 + '<ul class="linklist_list">' print tab*4 + "<ul class=\"linklist_list\">"
try: try:
content = open("linklist", "r") content = open("linklist", "r")
for line in content: for line in content:
if line.strip() is "": if line.strip() is "":
print '<br />' print "<br />"
else: else:
print tab*5 + '<li class="linklist_list_entry"><a href="' + line.split(" ")[0] + '" class="months_list_entry">' + line.split(" ", 1)[1].strip() + '</a></li>' print tab*5 + "<li class=\"linklist_list_entry\"><a href=\"" + line.split(" ")[0] + "\" class=\"months_list_entry\">" + line.split(" ", 1)[1].strip() + "</a></li>"
content.close() content.close()
except: except:
print '' print ""
print tab*4 + '</ul>' print tab*4 + "</ul>"
print tab*3 + '</div>' print tab*3 + "</div>"
print tab*3 + '<div class="linklist_footer"></div>' print tab*3 + "<div class=\"linklist_footer\"></div>"
print tab*2 + '</div>' print tab*2 + "</div>"
print '' print ""
print tab*2 + '<div class="entries">' print tab*2 + "<div class=\"entries\">"
print '' print ""
# Staticpage # Staticpage
if static_display != "": if static_display != "":
content = open(staticpages_dir + static_display, "r") content = open(staticpages_dir + static_display, "r")
print tab*3 + '<div class="entry">' print tab*3 + "<div class=\"entry\">"
print tab*4 + '<div class="entry_title">' + re.sub('^\.', '', re.sub('\d+?-', '', static_display)) + '</div>' print tab*4 + "<div class=\"entry_title\">" + re.sub("^\.", "", re.sub("\d+?-", "", static_display)) + "</div>"
print tab*4 + '<div class="entry_content">' print tab*4 + "<div class=\"entry_content\">"
print tab*5 + '<p>' print tab*5 + "<p>"
for line in content: for line in content:
if no_break.match(line): if no_break.match(line):
print tab*5 + line.strip() print tab*5 + line.strip()
else: else:
print tab*5 + line.strip() + '<br />' print tab*5 + line.strip() + "<br />"
print tab*5 + '</p>' print tab*5 + "</p>"
print tab*4 + '</div>' print tab*4 + "</div>"
print tab*4 + '<div class="entry_footer"></div>' print tab*4 + "<div class=\"entry_footer\"></div>"
print tab*4 + '<div class="entry_border_left"></div>' print tab*4 + "<div class=\"entry_border_left\"></div>"
print tab*4 + '<div class="entry_border_right"></div>' print tab*4 + "<div class=\"entry_border_right\"></div>"
print tab*4 + '<div class="entry_border_top"></div>' print tab*4 + "<div class=\"entry_border_top\"></div>"
print tab*4 + '<div class="entry_border_bottom"></div>' print tab*4 + "<div class=\"entry_border_bottom\"></div>"
print tab*3 + '</div>' print tab*3 + "</div>"
print '' print ""
content.close() content.close()
# Entry # Entry
@ -480,48 +481,48 @@ else:
date = time.strftime("%c", entry[0]) date = time.strftime("%c", entry[0])
date_to_compare = time.strftime("%m%Y", entry[0]) # Needed for permalinks date_to_compare = time.strftime("%m%Y", entry[0]) # Needed for permalinks
entry = entry[1] entry = entry[1]
title = entry.replace(entries_dir, '', 1) title = entry.replace(entries_dir, "", 1)
title = title.replace('.' + entries_suffix, '') title = title.replace("." + entries_suffix, "")
stampfile = os.path.join(entries_dir, title + '.stamp') stampfile = os.path.join(entries_dir, title + ".stamp")
if os.path.exists(stampfile): if os.path.exists(stampfile):
date = time.localtime(os.stat(stampfile)[8]) date = time.localtime(os.stat(stampfile)[8])
date = time.strftime("%c", date) date = time.strftime("%c", date)
if month_display == date_to_compare or not month_display: if month_display == date_to_compare or not month_display:
if post_display == title.replace(' ', '-') or not post_display: if post_display == title.replace(" ", "-") or not post_display:
if allentries_display == "1" or entry_counter < entries_per_page: if allentries_display == "1" or entry_counter < entries_per_page:
content = open(entry, "r") content = open(entry, "r")
print tab*3 + '<div class="entry">' print tab*3 + "<div class=\"entry\">"
if permalinks: if permalinks:
print tab*4 + '<div class="entry_title"><a href="?p=' + title.replace(' ', '-') + '" class="entry_title">' + title + '</a></div>' print tab*4 + "<div class=\"entry_title\"><a href=\"?p=" + title.replace(" ", "-") + "\" class=\"entry_title\">" + title + "</a></div>"
else: else:
print tab*4 + '<div class="entry_title">' + title + '</div>' print tab*4 + "<div class=\"entry_title\">" + title + "</div>"
print tab*4 + '<div class="entry_date">' + date + '</div>' print tab*4 + "<div class=\"entry_date\">" + date + "</div>"
print tab*4 + '<div class="entry_content">' print tab*4 + "<div class=\"entry_content\">"
for line in content: for line in content:
if no_break.match(line): if no_break.match(line):
print tab*5 + line.strip() print tab*5 + line.strip()
else: else:
print tab*5 + line.strip() + '<br />' print tab*5 + line.strip() + "<br />"
print tab*4 + '</div>' print tab*4 + "</div>"
print tab*4 + '<div class="entry_footer"></div>' print tab*4 + "<div class=\"entry_footer\"></div>"
print tab*4 + '<div class="entry_border_left"></div>' print tab*4 + "<div class=\"entry_border_left\"></div>"
print tab*4 + '<div class="entry_border_right"></div>' print tab*4 + "<div class=\"entry_border_right\"></div>"
print tab*4 + '<div class="entry_border_top"></div>' print tab*4 + "<div class=\"entry_border_top\"></div>"
print tab*4 + '<div class="entry_border_bottom"></div>' print tab*4 + "<div class=\"entry_border_bottom\"></div>"
# Comments... # Comments...
# ... are shown when post_display and comments_file isn't false # ... are shown when post_display and comments_file isn't false
comments_file = glob(entries_dir + title + '.comments') comments_file = glob(entries_dir + title + ".comments")
if post_display: if post_display:
if comments_file: if comments_file:
comments_file = glob(entries_dir + title + '.comments') comments_file = glob(entries_dir + title + ".comments")
comments_content = open(comments_file[0], "r") comments_content = open(comments_file[0], "r")
print tab*3 + '</div>' print tab*3 + "</div>"
print tab*2 + '</div>' print tab*2 + "</div>"
print '' print ""
print tab*2 + '<div class="comments">' print tab*2 + "<div class=\"comments\">"
notfirstline = 0 # Ugly fix for closing comment containers notfirstline = 0 # Ugly fix for closing comment containers
label_count = 0 label_count = 0
@ -529,83 +530,83 @@ else:
for line in comments_content: for line in comments_content:
if line_start_hyphen.match(line): if line_start_hyphen.match(line):
if notfirstline == 1: if notfirstline == 1:
print tab*4 + '</div>' print tab*4 + "</div>"
print tab*3 + '</div>' print tab*3 + "</div>"
notfirstline = 0; notfirstline = 0
print tab*3 + '<div class="comment">' print tab*3 + "<div class=\"comment\">"
#Label for each comment # Label for each comment
label_count += 1 label_count += 1
print tab*4 + '<a name="' + str(label_count) + '"></a>' print tab*4 + "<a name=\"" + str(label_count) + "\"></a>"
print tab*4 + '<div class="comment_author">' + line.split(".", 1)[1].strip() + '</div>' print tab*4 + "<div class=\"comment_author\">" + line.split(".", 1)[1].strip() + "</div>"
elif line_start_plus.match(line): elif line_start_plus.match(line):
print tab*4 + '<div class="comment_date">' + line.split(".", 1)[1].strip() + '</div>' print tab*4 + "<div class=\"comment_date\">" + line.split(".", 1)[1].strip() + "</div>"
print tab*4 + '<div class="comment_content">' print tab*4 + "<div class=\"comment_content\">"
else: else:
notfirstline = 1; notfirstline = 1
line = line.split(".", 1)[1] line = line.split(".", 1)[1]
print tab*5 + line.strip() + '<br />' print tab*5 + line.strip() + "<br />"
print '' print ""
print tab*4 + '</div>' print tab*4 + "</div>"
print tab*3 + '</div>' print tab*3 + "</div>"
comments_content.close() comments_content.close()
else: else:
print tab*3 + '</div>' print tab*3 + "</div>"
print tab*2 + '</div>' print tab*2 + "</div>"
print tab*2 + '<div class="comments">' print tab*2 + "<div class=\"comments\">"
# Form for adding comments # Form for adding comments
if comments == "True": if comments == "True":
random_int_a = randint(1,9) random_int_a = randint(1,9)
random_int_b = randint(1,9) random_int_b = randint(1,9)
cquizv = random_int_a + random_int_b cquizv = random_int_a + random_int_b
print tab*3 + '<div class="submit_comment">' print tab*3 + "<div class=\"submit_comment\">"
print tab*4 + '<form action="" method="post">' print tab*4 + "<form action=\"\" method=\"post\">"
print tab*5 + '<input type="hidden" name="ctitle" value="' + title + '" />' print tab*5 + "<input type=\"hidden\" name=\"ctitle\" value=\"" + title + "\" />"
print tab*5 + '<input type="hidden" name="cquizv" value="' + str(cquizv) + '" />' print tab*5 + "<input type=\"hidden\" name=\"cquizv\" value=\"" + str(cquizv) + "\" />"
print tab*5 + '<label class="submit_comment_name">' + blog_locale[6] + ':</label><input class="submit_comment_name_input" type="text" id="cname" name="cname" />' print tab*5 + "<label class=\"submit_comment_name\">" + blog_locale[6] + ":</label><input class=\"submit_comment_name_input\" type=\"text\" id=\"cname\" name=\"cname\" />"
print tab*5 + '<br /><label class="submit_comment_text">' + blog_locale[7] + ':</label><textarea class="submit_comment_textarea" id="ctext" name="ctext"></textarea>' print tab*5 + "<br /><label class=\"submit_comment_text\">" + blog_locale[7] + ":</label><textarea class=\"submit_comment_textarea\" id=\"ctext\" name=\"ctext\"></textarea>"
print tab*5 + '<br /><label class="submit_comment_quiz">' + str(random_int_a) + '+' + str(random_int_b) + '=</label><input class="submit_comment_quiz_input" type="text" id="cquiz" name="cquiz" />' print tab*5 + "<br /><label class=\"submit_comment_quiz\">" + str(random_int_a) + "+" + str(random_int_b) + "=</label><input class=\"submit_comment_quiz_input\" type=\"text\" id=\"cquiz\" name=\"cquiz\" />"
print tab*5 + '<br /><input class="submit_comment_button" type="submit" id="submit" value="' + blog_locale[8] + '" />' print tab*5 + "<br /><input class=\"submit_comment_button\" type=\"submit\" id=\"submit\" value=\"" + blog_locale[8] + "\" />"
print tab*4 + '</form>' print tab*4 + "</form>"
print tab*3 + '</div>' print tab*3 + "</div>"
else: else:
print tab*3 + '<div class="submit_border_bottom"></div>' print tab*3 + "<div class=\"submit_border_bottom\"></div>"
print '' print ""
if comments == "True": if comments == "True":
comments_file = glob(entries_dir + title + '.comments') comments_file = glob(entries_dir + title + ".comments")
if not comments_file and not post_display: if not comments_file and not post_display:
print tab*4 + '<div class="entry_comment">' print tab*4 + "<div class=\"entry_comment\">"
print tab*5 + '<a href="?p=' + title.replace(' ','-') + '" class="entry_comment">' + blog_locale[3] + '</a>' print tab*5 + "<a href=\"?p=" + title.replace(" " ,"-") + "\" class=\"entry_comment\">" + blog_locale[3] + "</a>"
print tab*4 + '</div>' print tab*4 + "</div>"
print tab*3 + '</div>' print tab*3 + "</div>"
print '' print ""
elif comments_file and not post_display: elif comments_file and not post_display:
comments_content = open(comments_file[0], "r") comments_content = open(comments_file[0], "r")
comments_counter = 0 comments_counter = 0
for line in comments_content: for line in comments_content:
if line.split(".", 1)[0] == "-": comments_counter += 1 if line.split(".", 1)[0] == "-": comments_counter += 1
print tab*4 + '<div class="entry_comment">' print tab*4 + "<div class=\"entry_comment\">"
print tab*5 + '<a href="?p=' + title.replace(' ', '-') + '" class="entry_comment">' + blog_locale[4] + ' (' + str(comments_counter) + ')</a>' print tab*5 + "<a href=\"?p=" + title.replace(" ", "-") + "\" class=\"entry_comment\">" + blog_locale[4] + " (" + str(comments_counter) + ")</a>"
print tab*4 + '</div>' print tab*4 + "</div>"
print tab*3 + '</div>' print tab*3 + "</div>"
print '' print ""
comments_content.close() comments_content.close()
else: else:
print tab*3 + '</div>' print tab*3 + "</div>"
print '' print ""
content.close() content.close()
entry_counter += 1 entry_counter += 1
if not month_display and not post_display and not allentries_display and entry_counter == entries_per_page: # Display pagelist if not month_display and not post_display and not allentries_display and entry_counter == entries_per_page: # Display pagelist
print tab*3 + '<div class="entry"><a href="?a=1">' + blog_locale[5] + '</a></div>' print tab*3 + "<div class=\"entry\"><a href=\"?a=1\">" + blog_locale[5] + "</a></div>"
print tab*2 + '</div>' print tab*2 + "</div>"
print '' print ""
print tab + '</body>' print tab + "</body>"
print '</html>' print "</html>"
# vim: set tw=0 ts=4: # vim: set tw=0 ts=4: