diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-11-17 10:22:33 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-11-17 10:22:33 +0000 |
commit | 689174532cc4920d2ef96bcebeb8a1adaf985804 (patch) | |
tree | 6391e7df464371b7a55aac8c1fc35b7b4b9d5d29 /lorrycontroller/showlorry.py | |
parent | e15d8f5c2a6ea406b4cc8b60b2fd79dc36aeecd2 (diff) | |
parent | c491acc03665213e01e40fc9ef81f5e326cf9ff9 (diff) | |
download | lorry-controller-689174532cc4920d2ef96bcebeb8a1adaf985804.tar.gz |
Merge remote-tracking branch 'origin/baserock/liw/lc-list-failed-jobs'
Reviewed-By: Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
Reviewed-By: Sam Thursfield <sam.thursfield@codethink.co.uk>
Diffstat (limited to 'lorrycontroller/showlorry.py')
-rw-r--r-- | lorrycontroller/showlorry.py | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/lorrycontroller/showlorry.py b/lorrycontroller/showlorry.py index fc336a5..19f9429 100644 --- a/lorrycontroller/showlorry.py +++ b/lorrycontroller/showlorry.py @@ -24,32 +24,43 @@ import bottle import lorrycontroller -class ShowLorry(lorrycontroller.LorryControllerRoute): +class ShowLorryBase(object): + + def get_lorry_info_with_job_lists(self, statedb, path): + obj= statedb.get_lorry_info(path) + obj['jobs'] = statedb.get_jobs_for_lorry(path) + obj['failed_jobs'] = statedb.get_failed_jobs_for_lorry(path) + return obj + + +class ShowLorry(ShowLorryBase, lorrycontroller.LorryControllerRoute): http_method = 'GET' path = '/1.0/lorry/<path:path>' def run(self, **kwargs): logging.info('%s %s called', self.http_method, self.path) - statedb = self.open_statedb() - try: - return statedb.get_lorry_info(kwargs['path']) - except lorrycontroller.LorryNotFoundError as e: - bottle.abort(404, str(e)) + with self.open_statedb() as statedb: + try: + return self.get_lorry_info_with_job_lists(statedb, kwargs['path']) + except lorrycontroller.LorryNotFoundError as e: + bottle.abort(404, str(e)) -class ShowLorryHTML(lorrycontroller.LorryControllerRoute): +class ShowLorryHTML(ShowLorryBase, lorrycontroller.LorryControllerRoute): http_method = 'GET' path = '/1.0/lorry-html/<path:path>' def run(self, **kwargs): logging.info('%s %s called', self.http_method, self.path) - statedb = self.open_statedb() - try: - lorry_info = statedb.get_lorry_info(kwargs['path']) - except lorrycontroller.LorryNotFoundError as e: - bottle.abort(404, str(e)) + + with self.open_statedb() as statedb: + try: + lorry_info = self.get_lorry_info_with_job_lists( + statedb, kwargs['path']) + except lorrycontroller.LorryNotFoundError as e: + bottle.abort(404, str(e)) renderer = lorrycontroller.StatusRenderer() shower = lorrycontroller.JobShower() |