Switch to unified view

a b/src/mediaserver/cdplugins/uprcl/uprclcontrol.py
1
# Copyright (C) 2017 J.F.Dockes
2
#   This program is free software; you can redistribute it and/or modify
3
#   it under the terms of the GNU General Public License as published by
4
#   the Free Software Foundation; either version 2 of the License, or
5
#   (at your option) any later version.
6
#
7
#   This program is distributed in the hope that it will be useful,
8
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
#   GNU General Public License for more details.
11
#
12
#   You should have received a copy of the GNU General Public License
13
#   along with this program; if not, write to the
14
#   Free Software Foundation, Inc.,
15
#   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
#
17
18
from __future__ import print_function
19
20
import os
21
22
import bottle
23
24
from uprclutils import uplog
25
import uprclinit
26
27
# Note that we start a separate server. There might be a way to serve
28
# both the audio files and the control app from the same server...
29
def runbottle(host='0.0.0.0', port=9278):
30
    global datadir
31
    datadir = os.path.dirname(__file__)
32
    datadir = os.path.join(datadir, 'bottle')
33
    bottle.TEMPLATE_PATH = (os.path.join(datadir, 'views'),)
34
    bottle.run(host=host, port=port)
35
36
37
@bottle.route('/')
38
@bottle.post('/')
39
@bottle.view('main')
40
def main():
41
    sub =  bottle.request.forms.get('sub')
42
    #uplog("Main: sub value is %s" % sub)
43
    if uprclinit.updaterunning():
44
        status = 'Updating'
45
    else:
46
        status = 'Ready'
47
48
    if sub == 'Update Index':
49
        uprclinit.start_update()
50
51
    if sub:
52
        headers = dict()
53
        headers["Location"] = '/'
54
        return bottle.HTTPResponse(status=302, **headers)
55
    else:
56
        return {'title':status, 'status':status,
57
                'friendlyname':uprclinit.g_friendlyname}
58
59
@bottle.route('/static/<filepath:path>')
60
def static(filepath):
61
    #uplog("control: static: filepath %s datadir %s" % (filepath, datadir))
62
    return bottle.static_file(filepath, root=os.path.join(datadir, 'static'))