myapp.py 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from cement.core.foundation import CementApp
  2. from cement.core.controller import CementBaseController, expose
  3. def append_config_path(app):
  4. if app.pargs.config_path:
  5. app._meta.config_files.append(app.pargs.config_path)
  6. #app.config.parse_file(app.pargs.config_path)
  7. app._setup_config_handler()
  8. class Base(CementBaseController):
  9. class Meta:
  10. label = 'base'
  11. arguments = [
  12. (['-C'],
  13. dict(help='append path to config files',
  14. dest='config_path',
  15. action='store',
  16. metavar='CONFIG')),
  17. ]
  18. @expose(hide=True)
  19. def default(self):
  20. print("Config Paths => %s" % self.app._meta.config_files)
  21. print("Foo => %s" % self.app.config.get('myapp', 'foo'))
  22. class MyApp(CementApp):
  23. class Meta:
  24. label = 'myapp'
  25. handlers = [Base]
  26. hooks = [
  27. ('post_argument_parsing', append_config_path),
  28. ]
  29. with MyApp() as app:
  30. app.run()