Beispiel #1
1
    def __init__(self, env, debug=False, output_path=None, ui_lang="en", verbosity=0, build_flags=None):
        Flask.__init__(self, "lektor.admin", static_url_path="/admin/static")
        self.lektor_info = LektorInfo(env, output_path, ui_lang, build_flags=build_flags, verbosity=verbosity)
        self.debug = debug
        self.config["PROPAGATE_EXCEPTIONS"] = True

        register_modules(self)
Beispiel #2
1
 def __init__(self, options, server):
     Flask.__init__(self, __name__)
     self._options = options
     self._server = server
     self.add_url_rule("/instance", "status", self._status)
     self.add_url_rule("/instance", "create-instance", self._create_instance, methods=["POST"])
     self.add_url_rule("/instance/<instance_id>", "destroy-instance", self._destroy_instance, methods=["DELETE"])
Beispiel #3
1
    def __init__(self, config):
        Flask.__init__(self, __name__)

        # TODO: deal with envvar and pyfile
        self.config.from_object(config)

        # Initialise helpers and services
        db.init_app(self)
        mail.init_app(self)

        # Babel
        babel.init_app(self)
        babel.localeselector(get_locale)

        # Assets (bundles are defined in the templates)
        assets = Environment(self)

        # Initialise filters
        init_filters(self)
        init_auth(self)

        from .apps.crm.frontend import CRM

        crm = CRM(self)

        self.register_blueprints()

        # Must come after all entity classes have been declared.
        self.register_services()
Beispiel #4
1
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop("startup_token", None)
        Flask.__init__(self, *args, **kwds)
        self.session_interface = OldSecureCookieSessionInterface()

        self.config["SESSION_COOKIE_HTTPONLY"] = False

        self.root_path = SAGENB_ROOT

        self.add_static_path("/css", os.path.join(DATA, "sage", "css"))
        self.add_static_path("/images", os.path.join(DATA, "sage", "images"))
        self.add_static_path("/javascript", DATA)
        self.add_static_path("/static", DATA)
        self.add_static_path("/java", DATA)
        self.add_static_path("/java/jmol", os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jmol"))
        import mimetypes

        mimetypes.add_type("text/plain", ".jmol")

        #######
        # Doc #
        #######
        # These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, "output", "html", "en")
        self.add_static_path("/pdf", os.path.join(SAGE_DOC, "output", "pdf"))
        self.add_static_path("/doc/static", DOC)
Beispiel #5
1
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop("startup_token", None)
        Flask.__init__(self, *args, **kwds)

        self.root_path = SAGENB_ROOT

        # I think it would make more sense just to have one /data/ path and not do one for every kind of file
        self.add_static_path("/data", os.path.join(DATA))

        # this one is special though since it points to SAGE_ROOT
        # self.add_static_path('/java/jmol', os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jmol"))

        import mimetypes

        mimetypes.add_type("text/plain", ".jmol")
        mimetypes.add_type("font/opentype", ".otf")
        mimetypes.add_type("application/font-woff", ".woff")

        #######
        # Doc #
        #######
        # These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, "output", "html", "en")
        self.add_static_path("/pdf", os.path.join(SAGE_DOC, "output", "pdf"))
        self.add_static_path("/doc/static", DOC)
Beispiel #6
1
    def __init__(self, name, dal, apis, mailer, *args, **kwargs):
        Flask.__init__(self, name, *args, **kwargs)
        self.dal = dal
        self.apis = apis
        self.mailer = mailer

        self._setup_routes()
Beispiel #7
0
    def __init__(self, config):
        Flask.__init__(self, __name__)

        # TODO: deal with envvar and pyfile
        self.config.from_object(config)

        # Initialise helpers and services
        db.init_app(self)
        mail.init_app(self)

        # Babel
        babel.init_app(self)
        babel.localeselector(get_locale)

        # DEBUG
        self.jinja_env.add_extension("jinja2.ext.i18n")
        self.jinja_env.install_gettext_callables(lambda x: x, lambda s, p, n: p, newstyle=True)

        # Assets (bundles are defined in the templates)
        assets = Environment(self)

        # Initialise filters
        init_filters(self)
        init_auth(self)

        from .apps.crm.frontend import CRM

        crm = CRM(self)

        self.register_blueprints()

        # Must come after all entity classes have been declared.
        self.register_services()
Beispiel #8
0
    def __init__(self, *args, **kwargs):
        """!
    	@brief Server app constructor. Includes Api constructor call.
    	"""
        Flask.__init__(self, *args, **kwargs)
        self.version = __version__
        # setup config
        import config

        self.config.from_object(config)
        self.config.from_pyfile("/etc/dnd/config.py", silent=True)
        # add favicon
        @self.route("/favicon")
        @self.route("/favicon.ico")
        @self.route("/static/favicon")
        @self.route("/static/favicon.ico")
        def favicon():
            return send_from_directory(
                os.path.join(app.root_path, "static/images"), "favicon.ico", mimetype="image/vnd.microsoft.icon"
            )

        @self.errorhandler(404)
        def not_found(error):
            return render_template("404.html", error=error), 404

        self.before_first_request(self.ensure_connection)
Beispiel #9
0
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop("startup_token", None)
        Flask.__init__(self, *args, **kwds)

        from sagenb.misc.misc import DATA

        self.add_static_path("/css", os.path.join(DATA, "sage", "css"))
        self.add_static_path("/images", os.path.join(DATA, "sage", "images"))
        self.add_static_path("/javascript/sage", os.path.join(DATA, "sage", "js"))
        self.add_static_path("/javascript", DATA)
        self.add_static_path("/static", DATA)
        self.add_static_path("/java", DATA)
        import mimetypes

        mimetypes.add_type("text/plain", ".jmol")

        #######
        # Doc #
        #######
        # These "should" be in doc.py
        from sagenb.misc.misc import SAGE_DOC

        DOC = os.path.join(SAGE_DOC, "output", "html", "en")
        self.add_static_path("/pdf", os.path.join(SAGE_DOC, "output", "pdf"))
        self.add_static_path("/doc/static", DOC)
        self.add_static_path("/doc/static/reference", os.path.join(SAGE_DOC, "en", "reference"))
Beispiel #10
0
 def __init__(self, import_name, *args, **kwargs):
     if module_is_package(import_name):
         # Flask.__init__ sets static path based on sys.modules.
         # As such, import the package here to ensure it's in sys.modules.
         __import__(import_name)
     Flask.__init__(self, import_name, *args, **kwargs)
     self.set_default_config()
     self.writers = {}
     self.register_default_writers()
Beispiel #11
0
    def __init__(self, name):
        Flask.__init__(self, name)

        status_view = CephStatusView.as_view("status")
        self.add_url_rule("/", view_func=status_view)

        # add custom error handler
        for code in default_exceptions.iterkeys():
            self.error_handler_spec[None][code] = self.make_json_error
Beispiel #12
0
    def __init__(self, name):
        Flask.__init__(self, name)
        logging.config.dictConfig(config["logging"])

        self.request_class = CustomRequestClass
        self.endpoints = ApiEndpoints()

        self._register_endpoints()
        self._register_error_handler()
        self._register_help_handler()
Beispiel #13
0
    def __init__(self, name):
        Flask.__init__(self, name)

        dhc_view = StateView.as_view("status")
        self.add_url_rule("/", defaults={"env": None}, view_func=dhc_view)
        self.add_url_rule("/<env>", view_func=dhc_view)

        # add custom error handler
        for code in default_exceptions.iterkeys():
            self.register_error_handler(code, self.make_json_error)
Beispiel #14
0
    def __init__(self, name):
        template_folder = os.path.join(os.path.dirname(__file__), "templates")
        static_folder = os.path.join(os.path.dirname(__file__), "static")
        Flask.__init__(self, name, template_folder=template_folder, static_folder=static_folder)

        status_view = CephStatusView.as_view("status")
        self.add_url_rule("/", view_func=status_view)

        # add custom error handler
        for code in default_exceptions.iterkeys():
            self.error_handler_spec[None][code] = self.make_json_error
Beispiel #15
0
    def __init__(self, name):
        Flask.__init__(self, name)
        self.__add_apis = False
        self.__add_views = False
        self.__name = name

        self.url_map.converters["regex"] = _RegexConverter
        self.__init_config()
        self.__init_log()
        self.__init_sched()
        self.db = Database(self)
        self.cache = SimpleCache()
        self.__init_signals()
Beispiel #16
0
    def __init__(self, *args, **kwargs):
        config = kwargs.pop("config", None)
        Flask.__init__(self, *args, **kwargs)

        self.config.from_object(DefaultConfig())

        if config is None:
            self.config.from_object(config)

        with Connection():
            self.queue = Queue()

        self.configure_extensions()

        self.register_blueprint(blueprint)
Beispiel #17
0
 def __init__(self, *args, **kwargs):
     self.endpoints = {}  # This is the storage property for the endpoints
     if settings.DEBUG:
         if "static_folder" not in kwargs and "folder" in settings.STATIC:
             kwargs["static_folder"] = settings.STATIC["folder"]
         if "static_url_path" not in kwargs and "path" in settings.STATIC:
             kwargs["static_url_path"] = settings.STATIC["path"]
     return Flask.__init__(self, *args, **kwargs)
Beispiel #18
0
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop("startup_token", None)
        Flask.__init__(self, *args, **kwds)
        self.session_interface = OldSecureCookieSessionInterface()

        self.config["SESSION_COOKIE_HTTPONLY"] = False

        self.root_path = SAGENB_ROOT

        self.add_static_path("/css", os.path.join(DATA, "sage", "css"))
        self.add_static_path("/images", os.path.join(DATA, "sage", "images"))
        self.add_static_path("/javascript", DATA)
        self.add_static_path("/static", DATA)
        self.add_static_path("/java", DATA)
        self.add_static_path("/java/jmol", os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jmol"))
        self.add_static_path("/jsmol", os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jsmol"))
        self.add_static_path("/jsmol/js", os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jsmol", "js"))
        self.add_static_path("/j2s", os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jsmol", "j2s"))
        self.add_static_path("/jsmol/j2s", os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jsmol", "j2s"))
        self.add_static_path(
            "/j2s/core", os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jsmol", "j2s", "core")
        )
        import mimetypes

        mimetypes.add_type("text/plain", ".jmol")

        #######
        # Doc #
        #######
        # These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, "output", "html", "en")
        self.add_static_path("/pdf", os.path.join(SAGE_DOC, "output", "pdf"))
        self.add_static_path("/doc/static", DOC)
        # self.add_static_path('/doc/static/reference', os.path.join(SAGE_DOC, 'reference'))

        # Template globals
        self.add_template_global(url_for)
        # Template filters
        self.add_template_filter(css_escape)
        self.add_template_filter(number_of_rows)
        self.add_template_filter(clean_name)
        self.add_template_filter(prettify_time_ago)
        self.add_template_filter(max)
        self.add_template_filter(lambda x: repr(unicode_str(x))[1:], name="repr_str")
        self.add_template_filter(dumps, "tojson")
Beispiel #19
0
    def __init__(self, port=5000, host="127.0.0.1", debug=True, name=__name__):
        template_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")

        self.port = port
        self.address = host
        self._debug = debug

        Flask.__init__(self, name, template_folder=template_folder)
        # self.config['debug'] = debug

        @self.route("/", methods=["GET"])
        def index():
            return render_template("base.html")

        @self.route("/image/<name>", methods=["GET"])
        def image(name):
            if name not in _images:
                return "404", 404

            fmt = request.args.get("format", "png")

            return _images[name].save(imagepy.RETURN_BYTES, format=fmt), 200, {"Content-Type": "image/" + fmt}
Beispiel #20
0
    def __init__(self, config):
        Flask.__init__(self, __name__)

        # TODO: deal with envvar and pyfile
        self.config.from_object(config)

        # Initialise helpers and services
        db.init_app(self)
        mail.init_app(self)

        # Babel (for i18n)
        babel.init_app(self)
        babel.localeselector(get_locale)

        # celery async service
        celery.config_from_object(config)

        # Initialise filters
        init_filters(self)
        # init_auth(self)

        self.register_services()
Beispiel #21
0
    def __init__(self):
        Flask.__init__(self, __name__)

        # Read configuration from file
        # If settings.py is founds, use it
        # If settings.py doesn't exists, use default_settings.py
        # If COLLECTOR_SETTINGS env variable is set use specified file it
        #
        # http://flask.pocoo.org/docs/config/#configuring-from-files
        try:
            self.config.from_object("settings")
        except:
            self.config.from_object("default_settings")

        try:
            self.config.from_envvar("COLLECTOR_SETTINGS")
        except:
            pass

        self.define_routes()
        self.register_error_handlers()

        init_logging(self)
Beispiel #22
0
    def __init__(self, import_name, *args, **kwargs):
        if module_is_package(import_name):
            # Flask.__init__ v0.9 sets static path based on sys.modules.
            # As such, import the package here to ensure it's in sys.modules.
            __import__(import_name)
        Flask.__init__(self, import_name, *args, **kwargs)
        self.set_default_config()
        self.writers = {}
        self.register_default_writers()

        if self.config.get("REQUEST_CLASS") is not None:
            self.request_class = self.config["REQUEST_CLASS"]

        if self.config.get("RESPONSE_CLASS") is not None:
            self.response_class = self.config["RESPONSE_CLASS"]

        # The writer to use when no writer is specified in the stash route.
        # Initialized as None here, as this is provided in config.py.
        #
        # Configure the default writer on first call to get_writer in order to
        # allow the default writer class to be configured in the application's
        # config after Tango instance creation.
        self.default_writer = None
Beispiel #23
0
 def __init__(self):
     Flask.__init__(self, "windpyfoam")
     self.process_manager = ProcessManager()
Beispiel #24
0
    def __init__(
        self,
        import_name,
        static_path=None,
        static_url_path=None,
        static_folder="html/static",
        template_folder="html/templates",
        instance_path=None,
        instance_relative_config=False,
        db_user=None,
        db_password=None,
        db_name=None,
    ):

        Flask.__init__(
            self,
            import_name,
            static_path,
            static_url_path,
            static_folder,
            template_folder,
            instance_path,
            instance_relative_config,
        )

        #: DB connector pool.
        self.dbPool = SeaIceConnectorPool(MAX_CONNECTIONS, db_user, db_password, db_name)

        # Id pools.
        db_con = self.dbPool.getScoped()

        self.userIdPool = IdPool(db_con, "Users")  #: Pool for user surrogate IDs.
        self.termIdPool = IdPool(db_con, "Terms")  #: Pool for term surrogate IDs.
        self.commentIdPool = IdPool(db_con, "Comments")  #: Pool for comment surrogate IDs.

        #: Live User data structures. This includes storage of notifications.
        self.SeaIceUsers = {}
        for row in db_con.getAllUsers():
            self.SeaIceUsers[row["id"]] = user.User(row["id"], row["first_name"].decode("utf-8"))

        # Load notifcations
        for (
            user_id,
            notif_class,
            T_notify,
            term_id,
            from_user_id,
            term_string,
            enotified,
        ) in db_con.getAllNotifications():

            if notif_class == "Base":
                notif = notify.BaseNotification(term_id, T_notify)
            elif notif_class == "Comment":
                notif = notify.Comment(term_id, from_user_id, term_string, T_notify)
            elif notif_class == "TermUpdate":
                notif = notify.TermUpdate(term_id, from_user_id, T_notify)
            elif notif_class == "TermRemoved":
                notif = notify.TermRemoved(from_user_id, term_string, T_notify)

            self.SeaIceUsers[user_id].notify(notif)
Beispiel #25
0
 def __init__(self, *args, **kwargs):
     Flask.__init__(self, *args, **kwargs)
     self.jinja_loader = GitLoader()
Beispiel #26
0
Datei: PMS.py Projekt: pjot/pms
 def __init__(self, name, port):
     self.name = name
     self.port = str(port)
     Flask.__init__(self, name)
     self.route("/api/ping", endpoint=self.ping)
Beispiel #27
0
    def __init__(self, *args, **kwargs):
        if not (len(args) > 0 or "import_name" in kwargs):
            # kwargs["import_name"] = __name__
            args += (__name__,)

        Flask.__init__(self, *args, **kwargs)
Beispiel #28
0
 def __init__(self, import_name):
     Flask.__init__(self, import_name, static_folder="public", static_url_path="")
Beispiel #29
0
    def __init__(self, *args, **kwargs):
        Flask.__init__(self, *args, **kwargs)

        self.config.from_object(DefaultConfig())
Beispiel #30
0
    def __init__(self, name=None, config=None, *args, **kwargs):
        kwargs.setdefault("instance_relative_config", True)
        name = name or __name__

        # used by make_config to determine if we try to load config from instance /
        # environment variable /...
        self._ABILIAN_INIT_TESTING_FLAG = getattr(config, "TESTING", False) if config else False
        Flask.__init__(self, name, *args, **kwargs)
        del self._ABILIAN_INIT_TESTING_FLAG

        self._setup_script_manager()
        appcontext_pushed.connect(self._install_id_generator)
        ServiceManager.__init__(self)
        PluginManager.__init__(self)
        self.default_view = ViewRegistry()
        self.js_api = dict()

        if config:
            self.config.from_object(config)

        # at this point we have loaded all external config files:
        # SQLALCHEMY_DATABASE_URI is definitively fixed (it cannot be defined in
        # database AFAICT), and LOGGING_FILE cannot be set in DB settings.
        self.setup_logging()

        configured = bool(self.config.get("SQLALCHEMY_DATABASE_URI"))
        self.config["CONFIGURED"] = configured

        if not self.testing:
            self.init_sentry()

        if not configured:
            # set fixed secret_key so that any unconfigured worker will use, so that
            # session can be used during setup even if multiple processes are
            # processing requests.
            self.config["SECRET_KEY"] = "abilian_setup_key"

        # time to load config bits from database: 'settings'
        # First init required stuff: db to make queries, and settings service
        extensions.db.init_app(self)
        settings_service.init_app(self)

        if configured:
            with self.app_context():
                try:
                    settings = self.services["settings"].namespace("config").as_dict()
                except sa.exc.DatabaseError as exc:
                    # we may get here if DB is not initialized and "settings" table is
                    # missing. Command "initdb" must be run to initialize db, but first we
                    # must pass app init
                    if not self.testing:
                        # durint tests this message will show up on every test, since db is
                        # always recreated
                        logging.error(exc.message)
                    self.db.session.rollback()
                else:
                    self.config.update(settings)

        if not self.config.get("FAVICO_URL"):
            self.config["FAVICO_URL"] = self.config.get("LOGO_URL")

        languages = self.config.get("BABEL_ACCEPT_LANGUAGES")
        if languages is None:
            languages = abilian.i18n.VALID_LANGUAGES_CODE
        else:
            languages = tuple(lang for lang in languages if lang in abilian.i18n.VALID_LANGUAGES_CODE)
        self.config["BABEL_ACCEPT_LANGUAGES"] = languages

        self._jinja_loaders = list()
        self.register_jinja_loaders(jinja2.PackageLoader("abilian.web", "templates"))

        js_filters = ("closure_js",) if self.config.get("PRODUCTION", False) else None

        self._assets_bundles = {
            "css": {"options": dict(filters=("less", "cssmin"), output="style-%(version)s.min.css")},
            "js-top": {"options": dict(output="top-%(version)s.min.js", filters=js_filters)},
            "js": {"options": dict(output="app-%(version)s.min.js", filters=js_filters)},
        }

        # bundles for JS translations
        for lang in languages:
            code = "js-i18n-" + lang
            filename = "lang-" + lang + "-%(version)s.min.js"
            self._assets_bundles[code] = {"options": dict(output=filename, filters=js_filters)}

        for http_error_code in (403, 404, 500):
            self.install_default_handler(http_error_code)

        with self.app_context():
            self.init_extensions()
            self.register_plugins()
            self.add_access_controller("static", allow_access_for_roles(Anonymous), endpoint=True)
            # debugtoolbar: this is needed to have it when not authenticated on a
            # private site. We cannot do this in init_debug_toolbar, since auth
            # service is not yet installed
            self.add_access_controller("debugtoolbar", allow_access_for_roles(Anonymous))
            self.add_access_controller("_debug_toolbar.static", allow_access_for_roles(Anonymous), endpoint=True)

        self.maybe_register_setup_wizard()
        self._finalize_assets_setup()
        # At this point all models should have been imported: time to configure
        # mappers. Normally Sqlalchemy does it when needed but mappers may be
        # configured inside sa.orm.class_mapper() which hides a misconfiguration: if
        # a mapper is misconfigured its exception is swallowed by
        # class_mapper(model) results in this laconic (and misleading) message:
        # "model is not mapped"
        sa.orm.configure_mappers()

        signals.components_registered.send(self)
        self.before_first_request(self._set_current_celery_app)
        self.before_first_request(lambda: signals.register_js_api.send(self))

        request_started.connect(self._setup_nav_and_breadcrumbs)

        # Initialize Abilian core services.
        # Must come after all entity classes have been declared.
        # Inherited from ServiceManager. Will need some configuration love later.
        if not self.config.get("TESTING", False):
            with self.app_context():
                self.start_services()