myapp.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from cement.core import foundation, controller, handler
  2. from cement.core.controller import CementBaseController, expose
  3. class BaseController(CementBaseController):
  4. class Meta:
  5. label = 'base'
  6. @expose()
  7. def base_cmd1(self):
  8. print("Inside BaseController.base_cmd1()")
  9. class EmbeddedController(CementBaseController):
  10. class Meta:
  11. label = 'embedded'
  12. description = "embedded with base namespace"
  13. stacked_on = 'base'
  14. stacked_type = 'embedded'
  15. @expose()
  16. def base_cmd2(self):
  17. print("Inside EmbeddedController.base_cmd2()")
  18. @expose()
  19. def embedded_cmd3(self):
  20. print("Inside EmbeddedController.embedded_cmd3()")
  21. class SecondLevelController(CementBaseController):
  22. class Meta:
  23. label = 'second'
  24. description = ''
  25. stacked_on = 'base'
  26. stacked_type = 'nested'
  27. @expose()
  28. def second_cmd4(self):
  29. print("Inside SecondLevelController.second_cmd4()")
  30. @expose()
  31. def second_cmd5(self):
  32. print("Inside SecondLevelController.second_cmd5()")
  33. class ThirdLevelController(CementBaseController):
  34. class Meta:
  35. label = 'third'
  36. description = ''
  37. stacked_on = 'second'
  38. stacked_type = 'nested'
  39. @expose()
  40. def third_cmd6(self):
  41. print("Inside ThirdLevelController.third_cmd6()")
  42. @expose()
  43. def third_cmd7(self):
  44. print("Inside ThirdLevelController.third_cmd7()")
  45. class MyApp(foundation.CementApp):
  46. class Meta:
  47. label = 'myapp'
  48. def main():
  49. try:
  50. # create the app
  51. app = MyApp()
  52. # register controllers to the app
  53. handler.register(BaseController)
  54. handler.register(EmbeddedController)
  55. handler.register(SecondLevelController)
  56. handler.register(ThirdLevelController)
  57. # setup the app
  58. app.setup()
  59. # run the app
  60. app.run()
  61. finally:
  62. # close the app
  63. app.close()
  64. if __name__ == '__main__':
  65. main()