Permalink
Browse files

updates and refactoring

  • Loading branch information...
1 parent ea4c115 commit c7a35a8b54f9a61a13f9f751a90cf7838effce25 @AndreCharbonneau AndreCharbonneau committed May 23, 2013
Showing with 27 additions and 11 deletions.
  1. +1 −1 wsgi/rpi_web.py
  2. +1 −4 wsgi/services/base.py
  3. +7 −1 wsgi/services/batch.py
  4. +18 −5 wsgi/services/utils.py
View
2 wsgi/rpi_web.py
@@ -58,7 +58,7 @@ def application(environ, start_response):
cherrypy.tree.mount(None, script_name='/wsgi/', config=conf)
return cherrypy.tree(environ, start_response)
- logging.info('rpi_web WSGI app started')
+ logging.info('rpi_web WSGI app started')
except Exception as e:
logging.exception('Error in rpi_web WSGI app.')
View
5 wsgi/services/base.py
@@ -192,7 +192,7 @@ def stats(self):
wraps around, please update this value accordingly.
"""
d = {}
- d['invocations'] = str(self.getInvocations())
+ d['invocations'] = self.getInvocations()
d['lastReset'] = str(self.getLastReset())
if self._should_return_json():
return json.dumps(d)
@@ -312,9 +312,6 @@ def getInvocations(self):
return self._getFromConfig('invocations', '')
def getLastReset(self):
- """
- Must return a datetime.datetime object.
- """
return self._getFromConfig('last_reset')
def getDoc(self):
View
8 wsgi/services/batch.py
@@ -1,15 +1,21 @@
from base import RpiService
import redis
+
+
class BatchService(RpiService):
+ """
+ This class implements the Batch Service.
+ It will query the redis database to get information about
+ the status of the service.
+ """
def __init__(self, d):
RpiService.__init__(self, d)
self.r = redis.StrictRedis(host='localhost', port=6379, db=0)
def getInvocations(self):
- #return self.r.get('nep52-client-boot')
values = {}
values['Number of Cloud Scheduler boots'] = self.r.get('nep52-cs-boot')
values['Cloud Scheduler hours'] = self.r.get('nep52-cs-clock')
View
23 wsgi/services/utils.py
@@ -1,4 +1,5 @@
import cgi
+import logging
class HtmlUtils():
"""
@@ -7,12 +8,24 @@ class HtmlUtils():
library or framework.
"""
def dictToPage(self, d, title=''):
+ """
+ Renders a dictionnary as a table in a HTML page.
+ """
return '<html><head><title>%s</title></head><body>%s</body></html>' % (title, self.dictToTable(d))
+
def dictToTable(self, d):
- html = '<table>'
- for key in d.keys():
- html += '<tr><th align=right>%s:</th><td>%s</td></tr>' % (cgi.escape(key), cgi.escape(d[key]))
- html += '</table>'
- return html
+ """
+ Renders a dictionary as a HTML <table> element.
+ Note that this method is recursive and will also render sub-dictionnaries
+ as HTML table elements.
+ """
+ if not isinstance(d, dict):
+ return cgi.escape(str(d))
+ else:
+ html = '<table>'
+ for key in d.keys():
+ html += '<tr><th align=right>%s:</th><td>%s</td></tr>' % (cgi.escape(key), self.dictToTable(d[key]))
+ html += '</table>'
+ return html

0 comments on commit c7a35a8

Please sign in to comment.