Move instance attribute defined into "__init__" method

1. Define instance attribute in instance method is not a good idea,
when invoke the method, it will set attribute, it is unnecessary,
this ps move the attribute defined into __init__ method, and
and let the list_engines() just list the engines.
2. Update the description of EngineManager.

Change-Id: I3c9af9cf265cb44d6db4d2f3690b6ddb92fdd61e
This commit is contained in:
caoyuan 2018-02-16 19:45:45 +08:00
parent 8088ecada5
commit 2c300b347e
1 changed files with 3 additions and 5 deletions

View File

@ -30,8 +30,8 @@ class EngineManager(object):
"""
EngineManager, this class handles engines.
Lists all available engines
Load an engine
Checks if an engine does exists or not
Load an engine
"""
def __init__(self):
"""
@ -40,7 +40,7 @@ class EngineManager(object):
"""
self.engine_name = CONF.engine_name
self.engine_store = os.path.abspath(os.path.dirname(__file__))
self.engines = []
self.engines = self.list_engines()
def load_engine(self, **kwargs):
""" Check if the engine exists or not. If not raise EngineNotFound
@ -59,8 +59,7 @@ class EngineManager(object):
)
def _check_engine_exists(self):
engines = self.list_engines()
if self.engine_name not in engines:
if self.engine_name not in self.engines:
return False
return True
@ -73,5 +72,4 @@ class EngineManager(object):
name for name in os.listdir(self.engine_store) if
os.path.isdir(os.path.join(self.engine_store, name))
]
self.engines = engines
return engines