mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-10 04:02:17 +00:00
Improved application factory a bit
This commit is contained in:
parent
b7f0494361
commit
28852c1de1
17
main.py
17
main.py
@ -19,19 +19,12 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import config
|
import sys
|
||||||
import os.path, sys
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if not config.check():
|
from web import create_application
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not os.path.exists(config.get('base', 'cache_dir')):
|
app = create_application()
|
||||||
os.makedirs(config.get('base', 'cache_dir'))
|
if app:
|
||||||
|
app.run(host = sys.argv[1] if len(sys.argv) > 1 else None, debug = True)
|
||||||
import db
|
|
||||||
from web import app
|
|
||||||
|
|
||||||
db.init_db()
|
|
||||||
app.run(host = sys.argv[1] if len(sys.argv) > 1 else None, debug = True)
|
|
||||||
|
|
||||||
|
15
main.wsgi
15
main.wsgi
@ -18,18 +18,9 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os.path, sys
|
import os.path
|
||||||
sys.path.insert(0, '/path/to/the/supysonic/app')
|
sys.path.insert(0, '/path/to/the/supysonic/app')
|
||||||
|
|
||||||
import config
|
from web import create_application
|
||||||
if not config.check():
|
application = create_application()
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not os.path.exists(config.get('base', 'cache_dir')):
|
|
||||||
os.makedirs(config.get('base', 'cache_dir'))
|
|
||||||
|
|
||||||
import db
|
|
||||||
db.init_db()
|
|
||||||
|
|
||||||
from web import app as application
|
|
||||||
|
|
||||||
|
75
web.py
75
web.py
@ -18,23 +18,11 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os.path
|
||||||
from flask import Flask, request, session, flash, render_template, redirect, url_for
|
from flask import Flask, request, session, flash, render_template, redirect, url_for
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
app.secret_key = '?9huDM\\H'
|
|
||||||
|
|
||||||
import config
|
import config
|
||||||
if config.get('base', 'log_file'):
|
|
||||||
import logging
|
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
|
||||||
handler = TimedRotatingFileHandler(config.get('base', 'log_file'), when = 'midnight')
|
|
||||||
handler.setLevel(logging.WARNING)
|
|
||||||
app.logger.addHandler(handler)
|
|
||||||
|
|
||||||
import db
|
|
||||||
from managers.user import UserManager
|
|
||||||
|
|
||||||
@app.before_request
|
|
||||||
def login_check():
|
def login_check():
|
||||||
if request.path.startswith('/rest/'):
|
if request.path.startswith('/rest/'):
|
||||||
return
|
return
|
||||||
@ -51,15 +39,9 @@ def login_check():
|
|||||||
flash('Please login')
|
flash('Please login')
|
||||||
return redirect(url_for('login', returnUrl = request.script_root + request.url[len(request.url_root)-1:]))
|
return redirect(url_for('login', returnUrl = request.script_root + request.url[len(request.url_root)-1:]))
|
||||||
|
|
||||||
@app.teardown_request
|
|
||||||
def teardown(exception):
|
def teardown(exception):
|
||||||
db.session.remove()
|
db.session.remove()
|
||||||
|
|
||||||
@app.template_filter('str')
|
|
||||||
def to_string(obj):
|
|
||||||
return str(obj)
|
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def index():
|
def index():
|
||||||
stats = {
|
stats = {
|
||||||
'artists': db.Artist.query.count(),
|
'artists': db.Artist.query.count(),
|
||||||
@ -68,17 +50,48 @@ def index():
|
|||||||
}
|
}
|
||||||
return render_template('home.html', stats = stats, admin = UserManager.get(session.get('userid'))[1].admin)
|
return render_template('home.html', stats = stats, admin = UserManager.get(session.get('userid'))[1].admin)
|
||||||
|
|
||||||
import user
|
def create_application():
|
||||||
import folder
|
global app, db, UserManager
|
||||||
import playlist
|
|
||||||
|
|
||||||
import api.system
|
if not config.check():
|
||||||
import api.browse
|
return None
|
||||||
import api.user
|
|
||||||
import api.albums_songs
|
if not os.path.exists(config.get('base', 'cache_dir')):
|
||||||
import api.media
|
os.makedirs(config.get('base', 'cache_dir'))
|
||||||
import api.annotation
|
|
||||||
import api.chat
|
import db
|
||||||
import api.search
|
db.init_db()
|
||||||
import api.playlists
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.secret_key = '?9huDM\\H'
|
||||||
|
|
||||||
|
if config.get('base', 'log_file'):
|
||||||
|
import logging
|
||||||
|
from logging.handlers import TimedRotatingFileHandler
|
||||||
|
handler = TimedRotatingFileHandler(config.get('base', 'log_file'), when = 'midnight')
|
||||||
|
handler.setLevel(logging.WARNING)
|
||||||
|
app.logger.addHandler(handler)
|
||||||
|
|
||||||
|
from managers.user import UserManager
|
||||||
|
|
||||||
|
app.before_request(login_check)
|
||||||
|
app.teardown_request(teardown)
|
||||||
|
app.add_template_filter(str)
|
||||||
|
app.add_url_rule('/', view_func = index)
|
||||||
|
|
||||||
|
import user
|
||||||
|
import folder
|
||||||
|
import playlist
|
||||||
|
|
||||||
|
import api.system
|
||||||
|
import api.browse
|
||||||
|
import api.user
|
||||||
|
import api.albums_songs
|
||||||
|
import api.media
|
||||||
|
import api.annotation
|
||||||
|
import api.chat
|
||||||
|
import api.search
|
||||||
|
import api.playlists
|
||||||
|
|
||||||
|
return app
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user