class Application (BaseObject): app_name = "UnnamedApp" app_version = "0" short_cmdline_args = None long_cmdline_args = None options = { 'exception_hook' : _except_hook, } def __init__ (self, **kw): """constructor""" super(Application, self).__init__() self._parse_options(Application.options, kw) if hasattr(self, 'config_files'): self.app_config = self.config_files elif hasattr(self, 'config_file'): self.app_config = str(self.config_file) else: self.app_config = "%s.conf" % self.app_name global _app_inst, _app_name, _app_version _app_inst = self _app_name = self.app_name _app_version = self.app_version if self.exception_hook is not None: sys.excepthook = self.exception_hook def start (self): try: self.config = Config(self.app_config, sys.argv, short_arguments=self.short_cmdline_args, long_arguments=self.long_cmdline_args, command_line_handler=self.cmdline_handler) # Default logging setup, if there is a 'logging' section in # the configuration file. Otherwise you are on your own to # setup the logging subsystem if 'logging' in self.config.get_sections(): configurelog(self.config) self.setup() self.run() self.cleanup() return except KeyboardInterrupt: self.abort('Aborted by user (keyboard interrupt)', errorcode=0) except ConfigError, o: self.abort('Configuration error: %s' % (o), errorcode=2) except OperationError, o: self.abort('Error: %s' % (o), errorcode=3)
def create_app(): app = Flask(__name__) config_object = Config() app.config.from_object(config_object) # Import here and with context manualy pushed so it can access context with app.app_context(): from myapp.rabbit_views import blueprint as rabbit_bp from myapp.redis_views import blueprint as redis_bp from myapp.celery_views import blueprint as celery_bp app.register_blueprint(rabbit_bp) app.register_blueprint(redis_bp) app.register_blueprint(celery_bp) @app.route("/", methods=["GET"]) def index(): print("INDEX") return render_template("index.html") return app
def start (self): try: self.config = Config(self.app_config, sys.argv, short_arguments=self.short_cmdline_args, long_arguments=self.long_cmdline_args, command_line_handler=self.cmdline_handler) # Default logging setup, if there is a 'logging' section in # the configuration file. Otherwise you are on your own to # setup the logging subsystem if 'logging' in self.config.get_sections(): configurelog(self.config) self.setup() self.run() self.cleanup() return except KeyboardInterrupt: self.abort('Aborted by user (keyboard interrupt)', errorcode=0) except ConfigError, o: self.abort('Configuration error: %s' % (o), errorcode=2)