myapp.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from cement.core.foundation import CementApp
  2. class MyApp(CementApp):
  3. class Meta:
  4. label = 'myapp'
  5. config_files = [
  6. './myapp.conf',
  7. ]
  8. def validate_config(self):
  9. if 'extensions' in self.config.keys('myapp'):
  10. exts = self.config.get('myapp', 'extensions')
  11. # convert a comma-separated string to a list
  12. if type(exts) is str:
  13. ext_list = exts.split(',')
  14. # clean up extra space if they had it inbetween commas
  15. ext_list = (x.strip() for x in ext_list)
  16. # set the new extensions value in the config
  17. self.config.set('myapp', 'extensions', ext_list)
  18. # otherwise, if it's a list (ConfigObj?)
  19. elif type(exts) is list:
  20. ext_list = exts
  21. for ext in ext_list:
  22. # load the extension
  23. self.ext.load_extension(ext)
  24. # add to meta data
  25. self._meta.extensions.append(ext)
  26. def main():
  27. app = MyApp()
  28. try:
  29. app.setup()
  30. app.run()
  31. finally:
  32. app.close()
  33. if __name__ == '__main__':
  34. main()