예제 #1
0
def test_get_local_config_file():
    config_file = get_local_config_file()

    assert config_file is None

    os.environ["BENTOML_CONFIG"] = "/tmp/bentoml.cfg"
    config_file = get_local_config_file()

    assert config_file == "/tmp/bentoml.cfg"

    del os.environ["BENTOML_CONFIG"]
예제 #2
0
def test_get_local_config_file():
    config_file = get_local_config_file()

    assert config_file == os.path.join(BENTOML_HOME, "bentoml.cfg")

    os.environ["BENTOML_CONFIG"] = "/tmp/bentoml.cfg"
    config_file = get_local_config_file()

    assert config_file == "/tmp/bentoml.cfg"

    del os.environ["BENTOML_CONFIG"]
예제 #3
0
파일: config.py 프로젝트: zhentan/BentoML
    def set_command(updates):
        track_cli('config-set')
        local_config = ConfigParser()
        local_config_file = get_local_config_file()
        local_config.read(local_config_file, encoding='utf-8')

        try:
            for update in updates:
                item, value = update.split('=')
                if '.' in item:
                    sec, opt = item.split('.')
                else:
                    sec = 'core'  # default section
                    opt = item

                if not local_config.has_section(sec):
                    local_config.add_section(sec)
                local_config.set(sec.strip(), opt.strip(), value.strip())

            local_config.write(open(local_config_file, 'w'))
            return
        except ValueError:
            _echo('Wrong config format: %s' % str(updates), CLI_COLOR_ERROR)
            _echo(EXAMPLE_CONFIG_USAGE)
            return
예제 #4
0
 def reset():
     local_config_file = get_local_config_file()
     if os.path.isfile(local_config_file):
         logger.info("Removing existing BentoML config file: %s", local_config_file)
         os.remove(local_config_file)
     create_local_config_file_if_not_found()
     return
예제 #5
0
    def view():
        track_cli('config-view')
        local_config = ConfigParser()
        with open(get_local_config_file(), 'rb') as config_file:
            local_config.read_string(config_file.read().decode('utf-8'))

        local_config.write(sys.stdout)
        return
예제 #6
0
 def reset():
     track_cli('config-reset')
     local_config_file = get_local_config_file()
     if os.path.isfile(local_config_file):
         LOG.info("Removing existing BentoML config file: %s",
                  local_config_file)
         os.remove(local_config_file)
     create_local_config_file_if_not_found()
     return
예제 #7
0
    def unset(updates):
        local_config = ConfigParser()
        local_config_file = get_local_config_file()
        local_config.read(local_config_file, encoding=CONFIG_FILE_ENCODING)

        try:
            for update in updates:
                if '.' in update:
                    sec, opt = update.split('.')
                else:
                    sec = 'core'  # default section
                    opt = update

                if not local_config.has_section(sec):
                    local_config.add_section(sec)
                local_config.remove_option(sec.strip(), opt.strip())

            local_config.write(open(local_config_file, 'w'))
            return
        except ValueError:
            raise CLIException(
                f'Wrong config format: {str(updates)}{EXAMPLE_CONFIG_USAGE}'
            )
예제 #8
0
    def unset(updates):
        track_cli('config-unset')
        local_config = ConfigParser()
        local_config_file = get_local_config_file()
        with open(local_config_file, 'rb') as config_file:
            local_config.read_string(config_file.read().decode('utf-8'))
        try:
            for update in updates:
                if '.' in update:
                    sec, opt = update.split('.')
                else:
                    sec = 'core'  # default section
                    opt = update

                if not local_config.has_section(sec):
                    local_config.add_section(sec)
                local_config.remove_option(sec.strip(), opt.strip())

            local_config.write(open(local_config_file, 'w'))
            return
        except ValueError:
            _echo('Wrong config format: %s' % str(updates), CLI_COLOR_ERROR)
            _echo(EXAMPLE_CONFIG_USAGE)
            return
예제 #9
0
파일: config.py 프로젝트: zhentan/BentoML
 def view():
     track_cli('config-view')
     local_config = ConfigParser()
     local_config.read(get_local_config_file(), encoding='utf-8')
     local_config.write(sys.stdout)
     return
예제 #10
0
파일: config.py 프로젝트: zhentan/BentoML
def create_local_config_file_if_not_found():
    local_config_file = get_local_config_file()
    if not os.path.isfile(local_config_file):
        logger.info("Creating local BentoML config file at: %s",
                    local_config_file)
        shutil.copyfile(DEFAULT_CONFIG_FILE, local_config_file)
예제 #11
0
 def view():
     local_config = ConfigParser()
     local_config.read(get_local_config_file(), encoding=CONFIG_FILE_ENCODING)
     local_config.write(sys.stdout)
     return