Some code cleanup
This commit is contained in:
parent
9a8023158b
commit
6575010157
44
blogthon.cgi
44
blogthon.cgi
@ -16,17 +16,17 @@
|
|||||||
# * Complete Atom Feed (like RSS)
|
# * Complete Atom Feed (like RSS)
|
||||||
# * Fix broken charset in outgoing mails (needs some testing)
|
# * Fix broken charset in outgoing mails (needs some testing)
|
||||||
|
|
||||||
import ConfigParser
|
from ConfigParser import ConfigParser
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import locale
|
import locale
|
||||||
import re
|
import re
|
||||||
import cgi
|
import cgi
|
||||||
import glob
|
from smtplib import SMTP
|
||||||
import md5
|
from md5 import new as newmd5
|
||||||
import random
|
from glob import glob
|
||||||
import smtplib
|
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>).*$')
|
||||||
@ -36,18 +36,13 @@ line_start_plus = re.compile('^\+.*$')
|
|||||||
tab = "\t"
|
tab = "\t"
|
||||||
|
|
||||||
def generate_uuid(string):
|
def generate_uuid(string):
|
||||||
string_md5sum = md5.new(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):
|
||||||
print 'Content-type: text/html\n'
|
document_header('xhtml-strict')
|
||||||
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
|
print '<head><title>Error!</title></head>'
|
||||||
print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
|
||||||
print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'
|
|
||||||
print '<head>'
|
|
||||||
print tab + '<title>Error!</title>'
|
|
||||||
print '</head>'
|
|
||||||
print '<body>'
|
print '<body>'
|
||||||
print tab + string
|
print tab + string
|
||||||
print '</body>'
|
print '</body>'
|
||||||
@ -74,7 +69,7 @@ def document_header(string):
|
|||||||
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">'
|
||||||
|
|
||||||
configuration = ConfigParser.ConfigParser()
|
configuration = ConfigParser()
|
||||||
|
|
||||||
# Look for a configuration:
|
# Look for a configuration:
|
||||||
if os.path.exists('../blogthonrc'):
|
if os.path.exists('../blogthonrc'):
|
||||||
@ -217,7 +212,7 @@ if cname and ctext and ctitle:
|
|||||||
if not cquiz == cquizv:
|
if not cquiz == cquizv:
|
||||||
errorpage("Brainmode")
|
errorpage("Brainmode")
|
||||||
else:
|
else:
|
||||||
comments_file = glob.glob(entries_dir + ctitle + '.comments')
|
comments_file = glob(entries_dir + ctitle + '.comments')
|
||||||
if not comments_file:
|
if not comments_file:
|
||||||
try:
|
try:
|
||||||
content = open(entries_dir + ctitle + '.comments', "w")
|
content = open(entries_dir + ctitle + '.comments', "w")
|
||||||
@ -235,7 +230,8 @@ if cname and ctext and ctitle:
|
|||||||
# 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 = smtplib.SMTP(smtp_host)
|
smtp = SMTP(smtp_host)
|
||||||
|
smtp.starttls() # TODO: some hosts need TLS, needs testing
|
||||||
smtp.sendmail(blog_title, mail_to, msg)
|
smtp.sendmail(blog_title, mail_to, msg)
|
||||||
smtp.quit()
|
smtp.quit()
|
||||||
except:
|
except:
|
||||||
@ -243,7 +239,7 @@ if cname and ctext and ctitle:
|
|||||||
|
|
||||||
# Read entries and store their title and timestamp
|
# Read entries and store their title and timestamp
|
||||||
entries = []
|
entries = []
|
||||||
entries_list = glob.glob(entries_dir + '*.' + entries_suffix)
|
entries_list = glob(entries_dir + '*.' + entries_suffix)
|
||||||
|
|
||||||
for entry in entries_list:
|
for entry in entries_list:
|
||||||
timestamp = os.stat(entry)
|
timestamp = os.stat(entry)
|
||||||
@ -346,7 +342,7 @@ else:
|
|||||||
|
|
||||||
# Plugins
|
# Plugins
|
||||||
sys.path.append(plugins_dir)
|
sys.path.append(plugins_dir)
|
||||||
for plugin in glob.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
|
||||||
@ -375,7 +371,7 @@ else:
|
|||||||
# Staticpages
|
# Staticpages
|
||||||
if staticpages == "True":
|
if staticpages == "True":
|
||||||
staticpages = []
|
staticpages = []
|
||||||
staticpages_list = glob.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>'
|
||||||
@ -500,10 +496,10 @@ else:
|
|||||||
|
|
||||||
# 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.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.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>'
|
||||||
@ -544,8 +540,8 @@ else:
|
|||||||
|
|
||||||
# Form for adding comments
|
# Form for adding comments
|
||||||
if comments == "True":
|
if comments == "True":
|
||||||
random_int_a = random.randint(1,9)
|
random_int_a = randint(1,9)
|
||||||
random_int_b = random.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">'
|
||||||
@ -562,7 +558,7 @@ else:
|
|||||||
print ''
|
print ''
|
||||||
|
|
||||||
if comments == "True":
|
if comments == "True":
|
||||||
comments_file = glob.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>'
|
||||||
|
Loading…
Reference in New Issue
Block a user