diff --git a/digimarks/__init__.py b/digimarks/__init__.py new file mode 100644 index 0000000..fcef2ab --- /dev/null +++ b/digimarks/__init__.py @@ -0,0 +1,29 @@ +import os + +from flask import Flask + + +def create_app(test_config=None): + # create our flask app and a database wrapper + app = Flask(__name__) + app.config.from_object(__name__) + + if test_config is None: + # load the instance config, if it exists, when not testing + app.config.from_pyfile('settings.py', silent=True) + else: + # load the test config if passed in + app.config.from_mapping(test_config) + + # Strip unnecessary whitespace due to jinja2 codeblocks + app.jinja_env.trim_blocks = True + app.jinja_env.lstrip_blocks = True + + # set custom url for the app, for example '/bookmarks' + try: + # TODO: get settings from ENV vars + app.config['APPLICATION_ROOT'] = settings.APPLICATION_ROOT + except AttributeError: + pass + + return app diff --git a/digimarks/marks.py b/digimarks/marks.py index b07fdd1..c7fd17f 100644 --- a/digimarks/marks.py +++ b/digimarks/marks.py @@ -30,21 +30,6 @@ DATABASE = { #PHANTOM = '/usr/local/bin/phantomjs' #SCRIPT = os.path.join(APP_ROOT, 'screenshot.js') -# create our flask app and a database wrapper -app = Flask(__name__) -app.config.from_object(__name__) -database = SqliteDatabase(os.path.join(APP_ROOT, 'bookmarks.db')) - -# Strip unnecessary whitespace due to jinja2 codeblocks -app.jinja_env.trim_blocks = True -app.jinja_env.lstrip_blocks = True - -# set custom url for the app, for example '/bookmarks' -try: - app.config['APPLICATION_ROOT'] = settings.APPLICATION_ROOT -except AttributeError: - pass - # Cache the tags all_tags = {} usersettings = {} @@ -640,6 +625,7 @@ def findmissingfavicons(systemkey): # Initialisation == create the bookmark, user and public tag tables if they do not exist +# TODO: move to __init__.py Bookmark.create_table(True) User.create_table(True) PublicTag.create_table(True) @@ -650,8 +636,3 @@ for user in users: all_tags[user.key] = get_tags_for_user(user.key) usersettings[user.key] = {'theme': user.theme} print(user.key) - -# Run when called standalone -if __name__ == '__main__': - # run the application - app.run(host='0.0.0.0', port=9999, debug=True)