comparison tincan.py @ 18:e88ab99914cf draft

More improvements to the error reportage.
author David Barts <n5jrn@me.com>
date Mon, 20 May 2019 08:40:56 -0700
parents 8186de188daf
children 5d9a1b82251a
comparison
equal deleted inserted replaced
17:8186de188daf 18:e88ab99914cf
338 return self._template.render(obj.export()).lstrip('\n') 338 return self._template.render(obj.export()).lstrip('\n')
339 except bottle.HTTPResponse as e: 339 except bottle.HTTPResponse as e:
340 return e 340 return e
341 except Exception as e: 341 except Exception as e:
342 traceback.print_exc() 342 traceback.print_exc()
343 # Bottle doesn't allow error handlers to themselves cause
344 # errors, most likely as a measure to prevent looping. So
345 # this will cause a "Critical error while processing request"
346 # page to be displayed, and any installed error pages to be
347 # ignored.
343 raise bottle.HTTPError(status=500, exception=e) 348 raise bottle.HTTPError(status=500, exception=e)
344 349
345 class _TinCanRoute(object): 350 class _TinCanRoute(object):
346 """ 351 """
347 A route created by the TinCan launcher. 352 A route created by the TinCan launcher.
594 Does the actual work of launching something. XXX - modifies sys.path 599 Does the actual work of launching something. XXX - modifies sys.path
595 and never un-modifies it. 600 and never un-modifies it.
596 """ 601 """
597 # Sanity checks 602 # Sanity checks
598 if not self.urlroot.startswith("/"): 603 if not self.urlroot.startswith("/"):
599 raise TinCanError("urlroot must be absolute") 604 self.errors = 1
605 self.logger("urlroot not absolute: {0!r}".format(self.urlroot))
606 return self
600 if not os.path.isdir(self.fsroot): 607 if not os.path.isdir(self.fsroot):
601 raise TinCanError("no such directory: {0!r}".format(self.fsroot)) 608 self.errors = 1
602 # Make WEB-INF, if needed 609 self.logger("no such directory: {0!r}".format(self.fsroot))
610 return self
611 # Make any needed directories. Refuse to launch things that don't
612 # contain WEB-INF, to prevent accidental launches of undesired
613 # directory trees containing sensitive files.
603 winf = os.path.join(self.fsroot, _WINF) 614 winf = os.path.join(self.fsroot, _WINF)
615 if not os.path.isdir(winf):
616 self.errors = 1
617 self.logger("no WEB-INF directory in {0!r}".format(self.fsroot))
618 return self
604 lib = os.path.join(winf, "lib") 619 lib = os.path.join(winf, "lib")
605 for i in [ winf, lib ]: 620 for i in [ lib ]:
606 if not os.path.isdir(i): 621 if not os.path.isdir(i):
607 os.mkdir(i) 622 os.mkdir(i)
608 # Add our private lib directory to sys.path 623 # Add our private lib directory to sys.path
609 sys.path.insert(1, os.path.abspath(lib)) 624 sys.path.insert(1, os.path.abspath(lib))
610 # Do what we gotta do 625 # Do what we gotta do