Download this file

uprclcontrol.py    63 lines (52 with data), 2.0 kB

 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
# Copyright (C) 2017 J.F.Dockes
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
from __future__ import print_function
import os
import bottle
from uprclutils import uplog
import uprclinit
# Note that we start a separate server. There might be a way to serve
# both the audio files and the control app from the same server...
def runbottle(host='0.0.0.0', port=9278):
global datadir
datadir = os.path.dirname(__file__)
datadir = os.path.join(datadir, 'bottle')
bottle.TEMPLATE_PATH = (os.path.join(datadir, 'views'),)
bottle.run(host=host, port=port)
@bottle.route('/')
@bottle.post('/')
@bottle.view('main')
def main():
sub = bottle.request.forms.get('sub')
#uplog("Main: sub value is %s" % sub)
if uprclinit.updaterunning():
status = 'Updating'
else:
status = 'Ready'
if sub == 'Update Index':
uprclinit.start_update()
if sub:
headers = dict()
headers["Location"] = '/'
return bottle.HTTPResponse(status=302, **headers)
else:
return {'title':status, 'status':status,
'friendlyname':uprclinit.g_friendlyname}
@bottle.route('/static/<filepath:path>')
def static(filepath):
#uplog("control: static: filepath %s datadir %s" % (filepath, datadir))
return bottle.static_file(filepath, root=os.path.join(datadir, 'static'))