-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashing.py
executable file
·72 lines (57 loc) · 2.38 KB
/
dashing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -------------------------------------------------------------------------------------------------
# Copyright 2013 Jonas Rabbe
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -------------------------------------------------------------------------------------------------
#
# The main application file for dashing.
#
from flask import Flask, json, request, make_response
from dashing.settings.config import Config
from dashing.settings.settings import Settings
from dashing.plugin.pluginloader import PluginLoader
config = Config()
app = Flask(__name__, static_url_path='/assets', static_folder='public')
settings = Settings(config.getConfig('db'))
availablePlugins = PluginLoader('plugins')
# API endpoints
@app.route('/api/plugins')
def plugins():
"""Function for getting information about plugins. Invoked through the route /api/plugins.
Invoking the route directly with a get request simply retrieves the settings for all icons
and returns that as JSON.
There are two available query parameters, name which is used to retrieve information about a
specific plugin, and icon (used together with Name) to retrieve the icon for a specific icon."""
name = request.args.get('name', None)
icon = request.args.get('icon', False)
print 'name = ', name
print 'icon = ', icon
if name is None:
return json.dumps(availablePlugins.getPlugins())
else:
if icon == False:
return json.dumps(availablePlugins.getPlugin(name))
else:
resp = make_response(availablePlugins.getIcon(name))
resp.headers['Content-Type'] = 'image/png'
return resp
@app.route('/api/settings')
def settings():
return "TBC"
# Catch all endpoint serving the index page
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
return app.send_static_file('index.html')
if __name__ == "__main__":
app.run(debug=True)