myapp.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from cement.core import foundation, handler
  2. from cement.core.controller import CementBaseController, expose
  3. # define application controllers
  4. class MyAppBaseController(CementBaseController):
  5. class Meta:
  6. label = 'base'
  7. class UsersController(CementBaseController):
  8. class Meta:
  9. label = 'users'
  10. description = "this is the users controller"
  11. stacked_on = 'base'
  12. stacked_type = 'nested'
  13. class HostsController(CementBaseController):
  14. class Meta:
  15. label = 'hosts'
  16. description = "this is the hosts controller"
  17. stacked_on = 'base'
  18. stacked_type = 'nested'
  19. class UsersListController(CementBaseController):
  20. class Meta:
  21. label = 'users_list'
  22. description = 'list all available users'
  23. aliases = ['list']
  24. aliases_only = True
  25. stacked_on = 'users'
  26. stacked_type = 'nested'
  27. @expose(hide=True)
  28. def default(self):
  29. print "Inside UsersListController.default()"
  30. class HostsListController(CementBaseController):
  31. class Meta:
  32. label = 'hosts_list'
  33. description = 'list all available hosts'
  34. aliases = ['list']
  35. aliases_only = True
  36. stacked_on = 'hosts'
  37. stacked_type = 'nested'
  38. @expose(hide=True)
  39. def default(self):
  40. print "Inside HostsListController.default()"
  41. def main():
  42. try:
  43. # create the application
  44. app = foundation.CementApp('myapp')
  45. # register non-base controllers
  46. handler.register(MyAppBaseController)
  47. handler.register(UsersController)
  48. handler.register(HostsController)
  49. handler.register(UsersListController)
  50. handler.register(HostsListController)
  51. # setup the application
  52. app.setup()
  53. # run it
  54. app.run()
  55. finally:
  56. # close it
  57. app.close()
  58. if __name__ == '__main__':
  59. main()