Switch to the new ProjectConfig API
This commit is contained in:
@@ -16,13 +16,14 @@
|
||||
# pylint: disable=too-many-locals, too-many-branches
|
||||
|
||||
import os
|
||||
from os.path import isfile
|
||||
from os.path import isfile, join
|
||||
|
||||
import click
|
||||
|
||||
from platformio import exception, util
|
||||
from platformio.commands.debug import helpers
|
||||
from platformio.managers.core import inject_contrib_pysite
|
||||
from platformio.project.config import ProjectConfig
|
||||
|
||||
|
||||
@click.command(
|
||||
@@ -69,10 +70,12 @@ def cli(ctx, project_dir, project_conf, environment, verbose, interface,
|
||||
project_dir = os.getenv("CWD")
|
||||
|
||||
with util.cd(project_dir):
|
||||
env_name = helpers.check_env_name(project_conf or project_dir,
|
||||
environment)
|
||||
env_options = helpers.get_env_options(project_conf or project_dir,
|
||||
env_name)
|
||||
config = ProjectConfig.get_instance(
|
||||
project_conf or join(project_dir, "platformio.ini"))
|
||||
config.validate(envs=[environment] if environment else None)
|
||||
|
||||
env_name = environment or helpers.get_default_debug_env(config)
|
||||
env_options = config.items(env=env_name, as_dict=True)
|
||||
if not set(env_options.keys()) >= set(["platform", "board"]):
|
||||
raise exception.ProjectEnvsNotAvailable()
|
||||
debug_options = helpers.validate_debug_options(ctx, env_options)
|
||||
|
||||
@@ -46,29 +46,9 @@ def escape_path(path):
|
||||
return path.replace("\\", "/")
|
||||
|
||||
|
||||
def check_env_name(project_conf, environment):
|
||||
config = util.load_project_config(project_conf)
|
||||
envs = []
|
||||
for section in config.sections():
|
||||
if section.startswith("env:"):
|
||||
envs.append(section[4:])
|
||||
if not envs:
|
||||
raise exception.ProjectEnvsNotAvailable()
|
||||
if not environment and config.has_option("platformio", "env_default"):
|
||||
environment = config.get("platformio", "env_default").split(", ")[0]
|
||||
if environment:
|
||||
if environment in envs:
|
||||
return environment
|
||||
raise exception.UnknownEnvNames(environment, envs)
|
||||
return envs[0]
|
||||
|
||||
|
||||
def get_env_options(project_conf, environment):
|
||||
config = util.load_project_config(project_conf)
|
||||
options = {}
|
||||
for k, v in config.items("env:%s" % environment):
|
||||
options[k] = v
|
||||
return options
|
||||
def get_default_debug_env(config):
|
||||
default_envs = config.default_envs()
|
||||
return default_envs[0] if default_envs else config.envs()[0]
|
||||
|
||||
|
||||
def validate_debug_options(cmd_ctx, env_options):
|
||||
|
||||
Reference in New Issue
Block a user