From 668b408d08ea7f9491935f46853fb83cf8cf9544 Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Mon, 1 Jul 2013 16:28:21 +0530 Subject: [PATCH] Simplified configuration file Using a simplified version of configuration file. No need to parse config files anymore. Just store the as strings in a python file. --- .gitignore | 1 + readConfig.py | 22 ---------------------- sampleConf.py | 6 ++++++ server.py | 12 ++++++------ 4 files changed, 13 insertions(+), 28 deletions(-) delete mode 100644 readConfig.py create mode 100644 sampleConf.py diff --git a/.gitignore b/.gitignore index 2538ed7..30ba916 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.*~ *.pyc +conf.py diff --git a/readConfig.py b/readConfig.py deleted file mode 100644 index e0f5936..0000000 --- a/readConfig.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/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)} diff --git a/sampleConf.py b/sampleConf.py new file mode 100644 index 0000000..7dfaf2f --- /dev/null +++ b/sampleConf.py @@ -0,0 +1,6 @@ +# 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 diff --git a/server.py b/server.py index 6e6f154..25ee45a 100644 --- 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 @@ def getContent(): @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,4 +118,5 @@ def updateMenu(_id): 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) + -- 1.7.10.4