Fix config command

This commit is contained in:
allegroai 2019-10-27 00:43:19 +03:00
parent bb36219806
commit cefdea78ac
4 changed files with 26 additions and 3 deletions

View File

@ -20,7 +20,9 @@ from .interface import get_parser
def run_command(parser, args, command_name):
debug = args.debug
if len(command_name.split('.')) < 2:
if command_name and command_name.lower() == 'config':
command_class = commands.Config
elif len(command_name.split('.')) < 2:
command_class = commands.Worker
elif hasattr(args, 'func') and getattr(args, 'func'):
command_class = getattr(commands, command_name.capitalize())

View File

@ -1,3 +1,4 @@
from __future__ import print_function
from .worker import Worker
from .check_config import Config

View File

@ -0,0 +1,15 @@
from trains_agent.commands.base import ServiceCommandSection
class Config(ServiceCommandSection):
def __init__(self, *args, **kwargs):
super(Config, self).__init__(*args, only_load_config=True, **kwargs)
def config(self, **_):
return self._session.print_configuration()
@property
def service(self):
""" The name of the REST service used by this command """
return 'config'

View File

@ -72,7 +72,11 @@ class Session(_Session):
os.environ[LOCAL_CONFIG_FILE_OVERRIDE_VAR] = config_file
if not Path(config_file).is_file():
raise ValueError("Could not open configuration file: {}".format(config_file))
super(Session, self).__init__(*args, **kwargs)
if kwargs.get('only_load_config'):
from trains_agent.backend_api.config import load
self.config = load()
else:
super(Session, self).__init__(*args, **kwargs)
self.log = self.get_logger(__name__)
self.trace = kwargs.get('trace', False)
self._config_file = kwargs.get('config_file') or \
@ -120,7 +124,8 @@ class Session(_Session):
if not worker_name.get():
worker_name.set(platform.node())
self.create_cache_folders()
if not kwargs.get('only_load_config'):
self.create_cache_folders()
@staticmethod
def get_logger(name):