def cli(ctx, environment, target, upload_port): config = get_project_config() if not config.sections(): raise exception.ProjectEnvsNotAvailable() unknown = set(environment) - set([s[4:] for s in config.sections()]) if unknown: raise exception.UnknownEnvNames(", ".join(unknown)) for section in config.sections(): # skip main configuration section if section == "platformio": continue elif section[:4] != "env:": raise exception.InvalidEnvName(section) envname = section[4:] if environment and envname not in environment: # echo("Skipped %s environment" % style(envname, fg="yellow")) continue click.echo("Processing %s environment:" % click.style(envname, fg="cyan")) options = {} for k, v in config.items(section): options[k] = v process_environment(ctx, envname, options, target, upload_port)
def cli( ctx, environment, target, upload_port, # pylint: disable=R0913,R0914 project_dir, verbose, disable_auto_clean): with util.cd(project_dir): config = util.get_project_config() if not config.sections(): raise exception.ProjectEnvsNotAvailable() known = set([s[4:] for s in config.sections() if s.startswith("env:")]) unknown = set(environment) - known if unknown: raise exception.UnknownEnvNames(", ".join(unknown), ", ".join(known)) # clean obsolete .pioenvs dir if not disable_auto_clean: try: _clean_pioenvs_dir(util.get_pioenvs_dir()) except: # pylint: disable=bare-except click.secho( "Can not remove temporary directory `%s`. Please remove " "`.pioenvs` directory from the project manually to avoid " "build issues" % util.get_pioenvs_dir(), fg="yellow") results = [] for section in config.sections(): # skip main configuration section if section == "platformio": continue if not section.startswith("env:"): raise exception.InvalidEnvName(section) envname = section[4:] if environment and envname not in environment: # echo("Skipped %s environment" % style(envname, fg="yellow")) continue if results: click.echo() options = {} for k, v in config.items(section): options[k] = v ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, verbose) results.append(ep.process()) if not all(results): raise exception.ReturnErrorCode()
def check_project_envs(config, environments): if not config.sections(): raise exception.ProjectEnvsNotAvailable() known = set([s[4:] for s in config.sections() if s.startswith("env:")]) unknown = set(environments) - known if unknown: raise exception.UnknownEnvNames(", ".join(unknown), ", ".join(known)) return True
def run( ctx=None, environment=(), target=(), upload_port=None, # pylint: disable=R0913,R0914 project_dir=os.getcwd(), verbose=3, disable_auto_clean=False): with util.cd(project_dir): config = util.get_project_config() if not config.sections(): raise exception.ProjectEnvsNotAvailable() known = set([s[4:] for s in config.sections() if s.startswith("env:")]) unknown = set(environment) - known if unknown: raise exception.UnknownEnvNames(", ".join(unknown), ", ".join(known)) # clean obsolete .pioenvs dir if not disable_auto_clean: try: _clean_pioenvs_dir(util.get_pioenvs_dir()) except Exception: raise exception.CleanPioenvsDirError(util.get_pioenvs_dir()) results = [] for section in config.sections(): # skip main configuration section if section == "platformio": continue if not section.startswith("env:"): raise exception.InvalidEnvName(section) envname = section[4:] if environment and envname not in environment: # echo("Skipped %s environment" % style(envname, fg="yellow")) continue if results: click.echo() options = {} for k, v in config.items(section): options[k] = v ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, verbose) results.append(ep.process( )) # [JORGE_GARCIA] modified to get process description return results
def validate(self, envs=None, silent=False): if not os.path.isfile(self.path): raise exception.NotPlatformIOProject(self.path) # check envs known = set(self.envs()) if not known: raise exception.ProjectEnvsNotAvailable() unknown = set(list(envs or []) + self.default_envs()) - known if unknown: raise exception.UnknownEnvNames(", ".join(unknown), ", ".join(known)) if not silent: for warning in self.warnings: click.secho("Warning! %s" % warning, fg="yellow") return True
def cli( ctx, environment, target, upload_port, # pylint: disable=R0913,R0914 project_dir, verbose): with util.cd(project_dir): config = util.get_project_config() if not config.sections(): raise exception.ProjectEnvsNotAvailable() unknown = set(environment) - set([s[4:] for s in config.sections()]) if unknown: raise exception.UnknownEnvNames(", ".join(unknown)) # clean obsolete .pioenvs dir _clean_pioenvs_dir() results = [] for section in config.sections(): # skip main configuration section if section == "platformio": continue if not section.startswith("env:"): raise exception.InvalidEnvName(section) envname = section[4:] if environment and envname not in environment: # echo("Skipped %s environment" % style(envname, fg="yellow")) continue if results: click.echo() options = {} for k, v in config.items(section): options[k] = v ep = EnvironmentProcessor(ctx, envname, options, target, upload_port, verbose) results.append(ep.process()) if not all(results): raise exception.ReturnErrorCode()
def cli(ctx, environment, target, upload_port): config = util.get_project_config() if not config.sections(): raise exception.ProjectEnvsNotAvailable() unknown = set(environment) - set([s[4:] for s in config.sections()]) if unknown: raise exception.UnknownEnvNames(", ".join(unknown)) # remove ".pioenvs" if project config is modified _pioenvs_dir = util.get_pioenvs_dir() if (isdir(_pioenvs_dir) and getmtime(join(util.get_project_dir(), "platformio.ini")) > getmtime(_pioenvs_dir)): rmtree(_pioenvs_dir) found_error = False _first_done = False for section in config.sections(): # skip main configuration section if section == "platformio": continue elif section[:4] != "env:": raise exception.InvalidEnvName(section) envname = section[4:] if environment and envname not in environment: # echo("Skipped %s environment" % style(envname, fg="yellow")) continue options = {} for k, v in config.items(section): options[k] = v if _first_done: click.echo() if not process_environment(ctx, envname, options, target, upload_port): found_error = True _first_done = True if found_error: raise exception.ReturnErrorCode()
def get_project_options(project_dir, environment): config = util.load_project_config(project_dir) if not config.sections(): return None known_envs = [s[4:] for s in config.sections() if s.startswith("env:")] if environment: if environment in known_envs: return config.items("env:%s" % environment) raise exception.UnknownEnvNames(environment, ", ".join(known_envs)) if not known_envs: return None if config.has_option("platformio", "env_default"): env_default = config.get("platformio", "env_default").split(", ")[0].strip() if env_default and env_default in known_envs: return config.items("env:%s" % env_default) return config.items("env:%s" % known_envs[0])