Fixed ugly generation of errors

This commit is contained in:
Stefan Ritter 2009-12-02 11:47:01 +01:00
parent e0c3504a30
commit e2b597fc1b
1 changed files with 24 additions and 33 deletions

View File

@ -28,16 +28,7 @@ def errorpage(string):
print ' <title>Error!</title>' print ' <title>Error!</title>'
print '</head>' print '</head>'
print '<body>' print '<body>'
if string == "entries_dir": print ' ' + string
print ' Directory <b>"' + entries_dir + '"</b> does not exist!'
elif string == "staticpages_dir":
print ' Directory <b>"' + staticpages_dir + '"</b> does not exist!'
elif string == "linklist":
print ' File <b>"linklist"</b> does not exist!'
elif string =="not writable entries_dir":
print ' Admin is a dumbass!!! Tell him to make his entries_dir writable.'
else:
print ' <b>' + string + '</b> is not set in configuration, please check your installation!'
print '</body>' print '</body>'
print '</html>' print '</html>'
sys.exit() sys.exit()
@ -66,64 +57,64 @@ configuration = ConfigParser.ConfigParser()
configuration.read('configuration') configuration.read('configuration')
try: blog_title = configuration.get('personal', 'blog_title') try: blog_title = configuration.get('personal', 'blog_title')
except: errorpage("blog_title") except: errorpage('"blog_title" is missing in configuration!')
try: blog_subtitle = configuration.get('personal', 'blog_subtitle') try: blog_subtitle = configuration.get('personal', 'blog_subtitle')
except: errorpage("blog_subtitle") except: errorpage('"blog_subtitle" is missing in configuration!')
try: blog_url = configuration.get('personal', 'blog_url') try: blog_url = configuration.get('personal', 'blog_url')
except: errorpage("blog_url") except: errorpage('"blog_url" is missing in configuration!')
try: keywords = configuration.get('personal', 'keywords') try: keywords = configuration.get('personal', 'keywords')
except: errorpage("keywords") except: errorpage('"keywords" is missing in configuration!')
try: entries_dir = configuration.get('personal', 'entries_dir') try: entries_dir = configuration.get('personal', 'entries_dir')
except: errorpage("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") 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") 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") 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") errorpage('"staticpages_dir" does not exist!')
try: style = configuration.get('look', 'style') try: style = configuration.get('look', 'style')
except: errorpage("style") except: errorpage('"style" is missing in configuration!')
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") except: errorpage('"entries_per_page" is missing in configuration!')
try: monthlist = configuration.get('look', 'monthlist') try: monthlist = configuration.get('look', 'monthlist')
except: errorpage("monthlist") except: errorpage('"monthlist" is missing in configuration!')
try: staticpages = configuration.get('look', 'staticpages') try: staticpages = configuration.get('look', 'staticpages')
except: errorpage("staticpages") except: errorpage('"staticpages" is missing in configuration!')
try: linklist = configuration.get('look', 'linklist') try: linklist = configuration.get('look', 'linklist')
except: errorpage("linklist") except: errorpage('"linklist" is missing in configuration!')
if not os.path.exists("linklist"): if not os.path.exists("linklist"):
errorpage("linklist") errorpage('"linklist" does not exist!')
try: permalinks = configuration.get('look', 'permalinks') try: permalinks = configuration.get('look', 'permalinks')
except: errorpage("permalinks") except: errorpage('"permalinks" is missing in configuration!')
try: comments = configuration.get('look', 'comments') try: comments = configuration.get('look', 'comments')
except: errorpage("comments") 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") 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") 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") 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") except: errorpage('"smtp_host" is missing in configuration!')
# Read POST Variables # Read POST Variables
action = cgi.FieldStorage() action = cgi.FieldStorage()
@ -177,7 +168,7 @@ if cname and ctext and ctitle:
content = open(entries_dir + ctitle + '.comments', "w") content = open(entries_dir + ctitle + '.comments', "w")
content.close() content.close()
except: except:
errorpage('Entries_directory not writable!') errorpage(entries_dir, 'isn\'t writable!')
comments_file = glob.glob(entries_dir + ctitle + '.comments') comments_file = glob.glob(entries_dir + ctitle + '.comments')
try: try:
content = open(comments_file[0], "a+") content = open(comments_file[0], "a+")
@ -194,7 +185,7 @@ if cname and ctext and ctitle:
smtp.sendmail(blog_title, mail_to, msg) smtp.sendmail(blog_title, mail_to, msg)
smtp.quit() smtp.quit()
except: except:
errorpage('Commentsfile not to be writable!') errorpage(comments_file, 'isn\'t writable!')
# Read entries and store their title and timestamp # Read entries and store their title and timestamp
entries = [] entries = []