forked from platformio/platformio-core
Allow to load PlatformIO project using passed directory
This commit is contained in:
+13
-15
@@ -84,7 +84,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
|
||||
if board:
|
||||
fill_project_envs(
|
||||
ctx, join(project_dir, "platformio.ini"), board,
|
||||
ctx, project_dir, board,
|
||||
enable_auto_uploading, env_prefix, ide is not None
|
||||
)
|
||||
|
||||
@@ -121,25 +121,23 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
|
||||
|
||||
def get_first_board(project_dir):
|
||||
with util.cd(project_dir):
|
||||
config = util.get_project_config()
|
||||
for section in config.sections():
|
||||
if not section.startswith("env:"):
|
||||
continue
|
||||
elif config.has_option(section, "board"):
|
||||
return config.get(section, "board")
|
||||
config = util.load_project_config(project_dir)
|
||||
for section in config.sections():
|
||||
if not section.startswith("env:"):
|
||||
continue
|
||||
elif config.has_option(section, "board"):
|
||||
return config.get(section, "board")
|
||||
return None
|
||||
|
||||
|
||||
def init_base_project(project_dir):
|
||||
platformio_ini = join(project_dir, "platformio.ini")
|
||||
if not isfile(platformio_ini):
|
||||
if not util.is_platformio_project(project_dir):
|
||||
copyfile(join(util.get_source_dir(), "projectconftpl.ini"),
|
||||
platformio_ini)
|
||||
join(project_dir, "platformio.ini"))
|
||||
|
||||
lib_dir = join(project_dir, "lib")
|
||||
src_dir = join(project_dir, "src")
|
||||
config = util.get_project_config(platformio_ini)
|
||||
config = util.load_project_config(project_dir)
|
||||
if config.has_option("platformio", "src_dir"):
|
||||
src_dir = join(project_dir, config.get("platformio", "src_dir"))
|
||||
|
||||
@@ -277,14 +275,14 @@ def init_cvs_ignore(project_dir):
|
||||
|
||||
|
||||
def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
|
||||
ctx, platformio_ini, board_ids, enable_auto_uploading,
|
||||
ctx, project_dir, board_ids, enable_auto_uploading,
|
||||
env_prefix, force_download):
|
||||
installed_boards = PlatformManager().get_installed_boards()
|
||||
content = []
|
||||
used_boards = []
|
||||
used_platforms = []
|
||||
|
||||
config = util.get_project_config(platformio_ini)
|
||||
config = util.load_project_config(project_dir)
|
||||
for section in config.sections():
|
||||
if not all([section.startswith("env:"),
|
||||
config.has_option(section, "board")]):
|
||||
@@ -324,7 +322,7 @@ def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
|
||||
if not content:
|
||||
return
|
||||
|
||||
with open(platformio_ini, "a") as f:
|
||||
with open(join(project_dir, "platformio.ini"), "a") as f:
|
||||
content.append("")
|
||||
f.write("\n".join(content))
|
||||
|
||||
|
||||
+10
-11
@@ -55,7 +55,7 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
fg="yellow"
|
||||
)
|
||||
|
||||
config = util.get_project_config()
|
||||
config = util.load_project_config()
|
||||
env_default = None
|
||||
if config.has_option("platformio", "env_default"):
|
||||
env_default = [
|
||||
@@ -257,18 +257,17 @@ def print_header(label, is_error=False):
|
||||
|
||||
|
||||
def check_project_envs(project_dir, environments):
|
||||
with util.cd(project_dir):
|
||||
config = util.get_project_config()
|
||||
config = util.load_project_config(project_dir)
|
||||
|
||||
if not config.sections():
|
||||
raise exception.ProjectEnvsNotAvailable()
|
||||
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))
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ def cli(ctx, environment, skip, upload_port, project_dir, verbose):
|
||||
if not isdir(test_dir):
|
||||
raise exception.TestDirEmpty(test_dir)
|
||||
test_names = get_test_names(test_dir)
|
||||
projectconf = util.get_project_config()
|
||||
projectconf = util.load_project_config()
|
||||
|
||||
click.echo("Collected %d items" % len(test_names))
|
||||
click.echo()
|
||||
|
||||
@@ -46,16 +46,15 @@ class ProjectGenerator(object):
|
||||
@util.memoized
|
||||
def get_project_env(self):
|
||||
data = {"env_name": "PlatformIO"}
|
||||
with util.cd(self.project_dir):
|
||||
config = util.get_project_config()
|
||||
for section in config.sections():
|
||||
if not section.startswith("env:"):
|
||||
continue
|
||||
data = {"env_name": section[4:]}
|
||||
for k, v in config.items(section):
|
||||
data[k] = v
|
||||
if self.board == data.get("board"):
|
||||
break
|
||||
config = util.load_project_config(self.project_dir)
|
||||
for section in config.sections():
|
||||
if not section.startswith("env:"):
|
||||
continue
|
||||
data = {"env_name": section[4:]}
|
||||
for k, v in config.items(section):
|
||||
data[k] = v
|
||||
if self.board == data.get("board"):
|
||||
break
|
||||
return data
|
||||
|
||||
@util.memoized
|
||||
|
||||
+14
-7
@@ -81,6 +81,7 @@ class cd(object):
|
||||
|
||||
|
||||
class memoized(object):
|
||||
|
||||
'''
|
||||
Decorator. Caches a function's return value each time it is called.
|
||||
If called later with the same arguments, the cached value is returned
|
||||
@@ -148,7 +149,7 @@ def _get_projconf_option_dir(name, default=None):
|
||||
return os.getenv(_env_name)
|
||||
|
||||
try:
|
||||
config = get_project_config()
|
||||
config = load_project_config()
|
||||
if (config.has_section("platformio") and
|
||||
config.has_option("platformio", name)):
|
||||
option_dir = config.get("platformio", name)
|
||||
@@ -232,16 +233,22 @@ def get_projectdata_dir():
|
||||
)
|
||||
|
||||
|
||||
def get_project_config(ini_path=None):
|
||||
if not ini_path:
|
||||
ini_path = join(get_project_dir(), "platformio.ini")
|
||||
if not isfile(ini_path):
|
||||
raise exception.NotPlatformProject(get_project_dir())
|
||||
def load_project_config(project_dir=None):
|
||||
if not project_dir:
|
||||
project_dir = get_project_dir()
|
||||
if not is_platformio_project(project_dir):
|
||||
raise exception.NotPlatformProject(project_dir)
|
||||
cp = ConfigParser()
|
||||
cp.read(ini_path)
|
||||
cp.read(join(project_dir, "platformio.ini"))
|
||||
return cp
|
||||
|
||||
|
||||
def is_platformio_project(project_dir=None):
|
||||
if not project_dir:
|
||||
project_dir = get_project_dir()
|
||||
return isfile(join(project_dir, "platformio.ini"))
|
||||
|
||||
|
||||
def change_filemtime(path, time):
|
||||
os.utime(path, (time, time))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user