From ee4bbb1b3c9fe04d285e1d3cd5746b7a26043a5d Mon Sep 17 00:00:00 2001 From: James Meyer Date: Tue, 19 Aug 2014 13:55:16 -0500 Subject: supplemental-web: Add menu item for frontend status. The page takes a bit to load because it queries the frontends in real time, every time. We need to add a please wait screen or some other dialog box in the future. Also removed remyth from the menu because it's a dead product. refs #973 --- abs/core/supplemental-web/PKGBUILD | 2 +- abs/core/supplemental-web/contents/fe_status.py | 132 +++++++++++++++++++++ abs/core/supplemental-web/contents/fe_status.shtml | 12 ++ abs/core/supplemental-web/contents/header.html | 3 +- 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 abs/core/supplemental-web/contents/fe_status.py create mode 100644 abs/core/supplemental-web/contents/fe_status.shtml diff --git a/abs/core/supplemental-web/PKGBUILD b/abs/core/supplemental-web/PKGBUILD index 42bbf6a..3f9e8ef 100644 --- a/abs/core/supplemental-web/PKGBUILD +++ b/abs/core/supplemental-web/PKGBUILD @@ -1,7 +1,7 @@ pkgbase=supplemental-web pkgname=('supplemental-web' 'supplemental-web-slave') pkgver=8.0 -pkgrel=17 +pkgrel=18 arch=('i686' 'x86_64') license=('GPL') backup=('data/srv/httpd/cgi/extra.cfg.txt') diff --git a/abs/core/supplemental-web/contents/fe_status.py b/abs/core/supplemental-web/contents/fe_status.py new file mode 100644 index 0000000..49bbf95 --- /dev/null +++ b/abs/core/supplemental-web/contents/fe_status.py @@ -0,0 +1,132 @@ +#!/usr/bin/python2 + +import urllib2 +import xml.etree.ElementTree as ET +import socket +from MythTV import Frontend +import sys +#socket.setdefaulttimeout(1) +#socket.setdefaulttimeout(.00001) + +def msg(msg): + #if cmdargs.silent is False: + print "%s" %msg + + +def parse_xml(frontend): + temp_dict = {'state':" --- ", + 'title':" --- ", + 'location':" --- "} + url = "http://%s:6547/Frontend/GetStatus" %frontend + try: + request = urllib2.Request(url) + xml = urllib2.urlopen(request,timeout=1) + tree = ET.parse(xml) + root = tree.getroot() + except: + msg(" Couldn't connect to %s" %frontend) + return temp_dict + + lst = root.find("State") + for item in lst: + try: + keyitem = (item.find('Key').text).strip() + valueitem = (item.find('Value').text).strip() + except: + continue + if keyitem == "state": + temp_dict['state'] = valueitem + + elif keyitem == "title": + temp_dict['title'] = valueitem + + elif keyitem == "currentlocation": + temp_dict['location'] = valueitem + + return temp_dict + + +def mythfe_status(cursor,mythDB): + frontends=list(Frontend.fromUPNP()) + status_dict={} + #try: + #frontends = mythDB.getFrontends() #use cursor instead so it doesn't test connection + #cursor.execute("select hostname from settings where value = 'FrontendIdleTimeout'") + #frontends=cursor.fetchall() + #except: + #msg("Excptions") + #return + + for i in frontends: + try: + fe_hostname = socket.gethostbyaddr(i.host)[0] + except: + print "DNS lookup failed for %s" %i.host + fe_hostname = i.host + status_dict[fe_hostname] = parse_xml(i.host) + + return status_dict + + +def print_html(status_dict): + print '

' + print '

' + print '' + + #print "Current state of all online frontends" + #print '

' + + #print status_dict + row = ''' + + + + + + +''' + print row %(" Frontend "," State "," Title "," MythTV Location") + for fe in status_dict.keys(): + temp_dict = status_dict[fe] + print row %(fe, + temp_dict['state'], + temp_dict['title'], + temp_dict['location']) + + print "
%s %s %s %s
" + print '
' + + print ''' + +''' + + +def main(): + try: + from MythTV import MythDB + mythDB = MythDB() + cursor = mythDB.cursor() + db_conn=True + except: + msg("Couldn't connect to MythTV database.") + db_conn=False + + try: + from MythTV import MythBE + mythBE = MythBE() + be_conn=True + except: + msg("Couldn't connect to MythTV backend.") + be_conn=False + + if (db_conn): + status_dict = mythfe_status(cursor,mythDB) + print_html(status_dict) + + + +if __name__ == "__main__": + main() diff --git a/abs/core/supplemental-web/contents/fe_status.shtml b/abs/core/supplemental-web/contents/fe_status.shtml new file mode 100644 index 0000000..d821600 --- /dev/null +++ b/abs/core/supplemental-web/contents/fe_status.shtml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/abs/core/supplemental-web/contents/header.html b/abs/core/supplemental-web/contents/header.html index 032acd1..772cb52 100644 --- a/abs/core/supplemental-web/contents/header.html +++ b/abs/core/supplemental-web/contents/header.html @@ -59,9 +59,10 @@ function beStatus() -- cgit v0.12