--- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.*~ *.pyc +conf.py --- a/readConfig.py +++ /dev/null @@ -1,23 +1 @@ -#!/usr/bin/python - -# Read Mouchak Configuration - - -import re - -def readConfig(): - confFile = 'mouchak.conf' - fh = open(confFile, 'r') - contents = fh.read() - - match = re.search('DB=(.*)', contents) - dbName = match.group(1) - match = re.search('SITE_TITLE=(.*)', contents) - title = match.group(1) - match = re.search('HOST=(.*)', contents) - host = match.group(1) - match = re.search('PORT=(.*)', contents) - port = match.group(1) - - return {'db': dbName, 'site_title': title, 'host': host, 'port': int(port)} --- /dev/null +++ b/sampleConf.py @@ -1 +1,7 @@ +# Rename this file to conf.py and adjust the following +# as required +DB = 'test_mouchak' +SITE_TITLE = 'Testing Mouchak' +HOST = '0.0.0.0' +PORT = 5000 --- a/server.py +++ b/server.py @@ -6,15 +6,14 @@ import flask import pymongo import bson -import readConfig +import conf app = flask.Flask(__name__) -config = readConfig.readConfig() dbClient = pymongo.MongoClient() -db = dbClient[config['db']] +db = dbClient[conf.DB] siteContent = db['content'] siteMenu = db['menu'] if siteMenu.find_one() == None: @@ -44,13 +43,13 @@ @app.route('/', methods=['GET']) def index(): return flask.render_template('index.html', content=getContent(), - title=config['site_title']) + title=config.SITE_TITLE) @app.route('/edit', methods=['GET']) def edit(): return flask.render_template('editor.html', content=getContent(), - title=config['site_title']) + title=config) @app.route('/page', methods=['POST']) @@ -119,5 +118,5 @@ if __name__ == "__main__": print config - app.run(debug=True, host=config['host'], port=config['port']) + app.run(debug=True, host=config.HOST, port=config.PORT)