Commit 668b408d08ea7f9491935f46853fb83cf8cf9544
- Diff rendering mode:
- inline
- side by side
.gitignore
(1 / 0)
  | |||
1 | 1 | ||
2 | 2 | *.*~ | |
3 | 3 | *.pyc | |
4 | conf.py |
readConfig.py
(0 / 22)
  | |||
1 | #!/usr/bin/python | ||
2 | |||
3 | # Read Mouchak Configuration | ||
4 | |||
5 | |||
6 | import re | ||
7 | |||
8 | def 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)} |
sampleConf.py
(6 / 0)
  | |||
1 | # Rename this file to conf.py and adjust the following | ||
2 | # as required | ||
3 | DB = 'test_mouchak' | ||
4 | SITE_TITLE = 'Testing Mouchak' | ||
5 | HOST = '0.0.0.0' | ||
6 | PORT = 5000 |
server.py
(5 / 6)
  | |||
6 | 6 | import flask | |
7 | 7 | import pymongo | |
8 | 8 | import bson | |
9 | import readConfig | ||
9 | import conf | ||
10 | 10 | ||
11 | 11 | app = flask.Flask(__name__) | |
12 | 12 | ||
13 | 13 | ||
14 | config = readConfig.readConfig() | ||
15 | 14 | ||
16 | 15 | dbClient = pymongo.MongoClient() | |
17 | db = dbClient[config['db']] | ||
16 | db = dbClient[conf.DB] | ||
18 | 17 | siteContent = db['content'] | |
19 | 18 | siteMenu = db['menu'] | |
20 | 19 | if siteMenu.find_one() == None: | |
… | … | ||
43 | 43 | @app.route('/', methods=['GET']) | |
44 | 44 | def index(): | |
45 | 45 | return flask.render_template('index.html', content=getContent(), | |
46 | title=config['site_title']) | ||
46 | title=config.SITE_TITLE) | ||
47 | 47 | ||
48 | 48 | ||
49 | 49 | @app.route('/edit', methods=['GET']) | |
50 | 50 | def edit(): | |
51 | 51 | return flask.render_template('editor.html', content=getContent(), | |
52 | title=config['site_title']) | ||
52 | title=config) | ||
53 | 53 | ||
54 | 54 | ||
55 | 55 | @app.route('/page', methods=['POST']) | |
… | … | ||
118 | 118 | ||
119 | 119 | if __name__ == "__main__": | |
120 | 120 | print config | |
121 | app.run(debug=True, host=config['host'], port=config['port']) | ||
121 | app.run(debug=True, host=config.HOST, port=config.PORT) |