示例#1
0
    def __init__(self):
        self.location = os.path.dirname(os.path.abspath(__file__))
        if self.location.endswith(__package__):
            self.location = self.location[: -len(__package__) - 1]

        self._log = alogger.getLogger(__name__, default_level="error")  # initial logger
        self._config_path = self.normalize_path("%s/%s" % (self.location, self._config_path))
        self.load()
示例#2
0
 def load(self):
     """
  Load application configuration
 """
     try:
         self._json = json.loads(self._load_from_configs(self._main_config))
         self._log = alogger.getLogger(__name__, cfg=self)  # reload logger using loaded configuration
         self._log.info("Loaded main settings: %s", self._main_config)
         self._load_modules()
         # parse command line, currently used for re-assign settings in configuration, but can't be used as replacement
         self._load_from_commandline()
     except Exception as err:
         self._json = None
         self._log.error("Error in parsing or open config file: %s", err)
         raise err
示例#3
0
  def __init__(self):
    self.cfg = Configuration.get_instance()
    self._log = alogger.getLogger(__name__, cfg=self.cfg)
    self._apply_settings()
    self._flask = Flask(__name__)
    self._flask.register_error_handler(404, self._error_404_handler)
    self._flask.register_error_handler(405, self._error_405_handler)
    self._flask.register_error_handler(500, self._error_500_handler)
    self._response_wrapper = ResponseWrapperFactory.get_wrapper(self._settings["output"])

    # serve static content, please use that possibility only for testing.
    # in production please use nginx, apache, etc for this.
    if self._settings["static_enabled"]:
      self._log.info("Static content serving enabled, serving \"%s\" at mountpoint \"%s\"" %
                     (self._settings["static_path"], self._settings["static_endpoint"]))
      self._flask.static_folder = self._settings["static_path"]
      self.serve_static_content()
示例#4
0
def load(allowed_views: list = None, disabled_views: list = None):
    """
  Dynamic sub-modules loading routine

  Replaces __ALL__ = [] construction and makes that automatically with logging possibility

  Compatible: Python 2.7, 3.x
  """
    import os
    import types
    from alist.logger import alogger
    from alist.config import Configuration

    view_extension = ".py"

    cfg = Configuration.get_instance()
    log = alogger.getLogger(__name__, cfg=cfg)
    mod_list = get_modules(os.path.dirname(__file__), view_extension)

    # load only allowed views
    if allowed_views is not None and len(allowed_views) != 0:
        mod_list = list(filter(lambda x: x in allowed_views, mod_list))

    # filter views from to be loaded
    if disabled_views is not None and len(disabled_views) != 0:
        mod_list = list(filter(lambda x: x not in disabled_views, mod_list))

    log.debug("Loading filtered list of views in the namespace %s: %s", __name__, mod_list)

    #  append namespace to module
    mod_list = list(map(lambda x: "%s.%s" % (__name__, x), mod_list))
    for mod in mod_list:
        module = get_loaded_module(__import__(mod, globals(), [], []), mod)
        # Call view init method if present
        if (
            module is not None
            and "__init__" in module.__dict__
            and isinstance(module.__dict__["__init__"], types.FunctionType)
        ):
            module.__init__()
 def __init__(self, auto_update=True, time: str="0:0:30"):
   self._log = alogger.getLogger(__name__, Configuration.get_instance())
   self._storage_list_url = "{0}?q=list"
   self._storage_view_url = "{0}?q=view&storage={1}"
   super(StorageApiProvider, self).__init__(auto_update, time)