Commit 668b408d08ea7f9491935f46853fb83cf8cf9544

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 / 0)
  
11
22*.*~
33*.pyc
4conf.py
  
1#!/usr/bin/python
2
3# Read Mouchak Configuration
4
5
6import re
7
8def readConfig():
9 confFile = 'mouchak.conf'
10 fh = open(confFile, 'r')
11 contents = fh.read()
12
13 match = re.search('DB=(.*)', contents)
14 dbName = match.group(1)
15 match = re.search('SITE_TITLE=(.*)', contents)
16 title = match.group(1)
17 match = re.search('HOST=(.*)', contents)
18 host = match.group(1)
19 match = re.search('PORT=(.*)', contents)
20 port = match.group(1)
21
22 return {'db': dbName, 'site_title': title, 'host': host, 'port': int(port)}
  
1# Rename this file to conf.py and adjust the following
2# as required
3DB = 'test_mouchak'
4SITE_TITLE = 'Testing Mouchak'
5HOST = '0.0.0.0'
6PORT = 5000
server.py
(5 / 6)
  
66import flask
77import pymongo
88import bson
9import readConfig
9import conf
1010
1111app = flask.Flask(__name__)
1212
1313
14config = readConfig.readConfig()
1514
1615dbClient = pymongo.MongoClient()
17db = dbClient[config['db']]
16db = dbClient[conf.DB]
1817siteContent = db['content']
1918siteMenu = db['menu']
2019if siteMenu.find_one() == None:
4343@app.route('/', methods=['GET'])
4444def index():
4545 return flask.render_template('index.html', content=getContent(),
46 title=config['site_title'])
46 title=config.SITE_TITLE)
4747
4848
4949@app.route('/edit', methods=['GET'])
5050def edit():
5151 return flask.render_template('editor.html', content=getContent(),
52 title=config['site_title'])
52 title=config)
5353
5454
5555@app.route('/page', methods=['POST'])
118118
119119if __name__ == "__main__":
120120 print config
121 app.run(debug=True, host=config['host'], port=config['port'])
121 app.run(debug=True, host=config.HOST, port=config.PORT)