From 7d50eb1e4b024f374d5ae11796a38f3766065959 Mon Sep 17 00:00:00 2001 From: Stefan Ritter Date: Fri, 10 Apr 2009 12:05:01 +0200 Subject: Added an errorhandler for the configuration file --- blogthon.cgi | 58 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/blogthon.cgi b/blogthon.cgi index 33aa7e9..58be8ab 100755 --- a/blogthon.cgi +++ b/blogthon.cgi @@ -9,7 +9,7 @@ # Author: Stefan Ritter # Description: A simple blogging software -import cgi, os, time, glob, re, md5 +import cgi, os, time, glob, re, md5, sys import ConfigParser def generate_uuid(string): @@ -22,25 +22,51 @@ def generate_uuid(string): string = string_md5sum_1 + '-' + string_md5sum_2 + '-' + string_md5sum_3 + '-' + string_md5sum_4 + '-' + string_md5sum_5 return string +def errorpage(string): + print 'Content-type: text/html\n' + print '' + print '' + print '' + print ' Error!' + print '' + print '' + print ' ' + string + ' is not set in configuration, please check your installation!' + print '' + print '' + sys.exit() -# Read configuration. TODO: a human readable errorhandler configuration = ConfigParser.ConfigParser() configuration.read('configuration') -blog_title = configuration.get('personal', 'blog_title') -blog_url = configuration.get('personal', 'blog_url') -keywords = configuration.get('personal', 'keywords') -entries_dir = configuration.get('personal', 'entries_dir') -entries_suffix = configuration.get('personal', 'entries_suffix') -staticpages_dir = configuration.get('personal', 'staticpages_dir') -style = configuration.get('look', 'style') -entries_per_page = configuration.getint('look', 'entries_per_page') -monthlist = configuration.get('look', 'monthlist') -staticpages = configuration.get('look', 'staticpages') -linklist = configuration.get('look', 'linklist') -permalinks = configuration.get('look', 'permalinks') -comments = configuration.get('look', 'comments') -newest_first = configuration.get('look', 'newest_first') +try: blog_title = configuration.get('personal', 'blog_title') +except: errorpage("blog_title") +try: blog_url = configuration.get('personal', 'blog_url') +except: errorpage("blog_url") +try: keywords = configuration.get('personal', 'keywords') +except: errorpage("keywords") +try: entries_dir = configuration.get('personal', 'entries_dir') +except: errorpage("entries_dir") +try: entries_suffix = configuration.get('personal', 'entries_suffix') +except: errorpage("entries_suffix") +try: staticpages_dir = configuration.get('personal', 'staticpages_dir') +except: errorpage("staticpages_dir") +try: style = configuration.get('look', 'style') +except: errorpage("style") +try: entries_per_page = configuration.getint('look', 'entries_per_page') +except: errorpage("entries_per_page") +try: monthlist = configuration.get('look', 'monthlist') +except: errorpage("monthlist") +try: staticpages = configuration.get('look', 'staticpages') +except: errorpage("staticpages") +try: linklist = configuration.get('look', 'linklist') +except: errorpage("linklist") +try: permalinks = configuration.get('look', 'permalinks') +except: errorpage("permalinks") +try: comments = configuration.get('look', 'comments') +except: errorpage("comments") +try: newest_first = configuration.get('look', 'newest_first') +except: errorpage("newest_first") # Read POST Variables action = cgi.FieldStorage() -- cgit v1.2.3