]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/__init__.py
653474c6304dba59240d46618b6baffa677d03c4
[ceph.git] / ceph / src / pybind / mgr / dashboard / __init__.py
1 # -*- coding: utf-8 -*-
2 # pylint: disable=wrong-import-position,global-statement,protected-access
3 """
4 ceph dashboard module
5 """
6
7 import os
8
9 import cherrypy
10
11 if 'COVERAGE_ENABLED' in os.environ:
12 import coverage # pylint: disable=import-error
13 __cov = coverage.Coverage(config_file="{}/.coveragerc".format(os.path.dirname(__file__)),
14 data_suffix=True)
15 __cov.start()
16 cherrypy.engine.subscribe('after_request', __cov.save)
17 cherrypy.engine.subscribe('stop', __cov.stop)
18
19 if 'UNITTEST' not in os.environ:
20 class _ModuleProxy(object):
21 def __init__(self):
22 self._mgr = None
23
24 def init(self, module_inst):
25 self._mgr = module_inst
26
27 def __getattr__(self, item):
28 if self._mgr is None:
29 raise AttributeError("global manager module instance not initialized")
30 return getattr(self._mgr, item)
31
32 mgr = _ModuleProxy()
33
34 else:
35 import logging
36 logging.basicConfig(level=logging.DEBUG)
37 logging.root.handlers[0].setLevel(logging.DEBUG)
38 import sys
39
40 # Used to allow the running of a tox-based yml doc generator from the dashboard directory
41 if os.path.abspath(sys.path[0]) == os.getcwd():
42 sys.path.pop(0)
43
44 from tests import mock # type: ignore
45
46 mgr = mock.Mock()
47 mgr.get_frontend_path.return_value = os.path.abspath(os.path.join(
48 os.path.dirname(__file__),
49 'frontend/dist'))
50
51 # DO NOT REMOVE: required for ceph-mgr to load a module
52 from .module import Module, StandbyModule # noqa: F401