forked from platformio/platformio-core
Allow to add more boards to existing platformio.ini // Resolve #167
This commit is contained in:
@@ -11,6 +11,9 @@ Release History
|
|||||||
(`issue #174 <https://github.com/platformio/platformio/issues/174>`_)
|
(`issue #174 <https://github.com/platformio/platformio/issues/174>`_)
|
||||||
* Added global ``-f, --force`` option which will force to accept any
|
* Added global ``-f, --force`` option which will force to accept any
|
||||||
confirmation prompts (`issue #152 <https://github.com/platformio/platformio/issues/152>`_)
|
confirmation prompts (`issue #152 <https://github.com/platformio/platformio/issues/152>`_)
|
||||||
|
* Allowed to add more boards to existing
|
||||||
|
`platformio.ini <http://docs.platformio.org/en/latest/projectconf.html>`__
|
||||||
|
(`issue #167 <https://github.com/platformio/platformio/issues/167>`_)
|
||||||
* Allowed to choose which library to update
|
* Allowed to choose which library to update
|
||||||
(`issue #168 <https://github.com/platformio/platformio/issues/168>`_)
|
(`issue #168 <https://github.com/platformio/platformio/issues/168>`_)
|
||||||
* Disabled automatic updates by default for platforms, packages and libraries
|
* Disabled automatic updates by default for platforms, packages and libraries
|
||||||
|
@@ -31,17 +31,6 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613
|
|||||||
@click.option("--disable-auto-uploading", is_flag=True)
|
@click.option("--disable-auto-uploading", is_flag=True)
|
||||||
def cli(project_dir, board, disable_auto_uploading):
|
def cli(project_dir, board, disable_auto_uploading):
|
||||||
|
|
||||||
project_file = join(project_dir, "platformio.ini")
|
|
||||||
src_dir = join(project_dir, "src")
|
|
||||||
lib_dir = join(project_dir, "lib")
|
|
||||||
if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]):
|
|
||||||
raise exception.ProjectInitialized()
|
|
||||||
|
|
||||||
builtin_boards = set(get_boards().keys())
|
|
||||||
if board and not set(board).issubset(builtin_boards):
|
|
||||||
raise exception.UnknownBoard(
|
|
||||||
", ".join(set(board).difference(builtin_boards)))
|
|
||||||
|
|
||||||
# ask about auto-uploading
|
# ask about auto-uploading
|
||||||
if board and app.get_setting("enable_prompts"):
|
if board and app.get_setting("enable_prompts"):
|
||||||
disable_auto_uploading = not click.confirm(
|
disable_auto_uploading = not click.confirm(
|
||||||
@@ -56,7 +45,7 @@ def cli(project_dir, board, disable_auto_uploading):
|
|||||||
click.secho("\nThe current working directory", fg="yellow", nl=False)
|
click.secho("\nThe current working directory", fg="yellow", nl=False)
|
||||||
click.secho(" %s " % project_dir, fg="cyan", nl=False)
|
click.secho(" %s " % project_dir, fg="cyan", nl=False)
|
||||||
click.secho(
|
click.secho(
|
||||||
"will be used for the new project.\n"
|
"will be used for project.\n"
|
||||||
"You can specify another project directory via\n"
|
"You can specify another project directory via\n"
|
||||||
"`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
|
"`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
|
||||||
fg="yellow"
|
fg="yellow"
|
||||||
@@ -72,17 +61,25 @@ def cli(project_dir, board, disable_auto_uploading):
|
|||||||
click.echo("%s - Put here project specific or 3-rd party libraries" %
|
click.echo("%s - Put here project specific or 3-rd party libraries" %
|
||||||
click.style("lib", fg="cyan"))
|
click.style("lib", fg="cyan"))
|
||||||
|
|
||||||
if (not app.get_setting("enable_prompts") or
|
if (app.get_setting("enable_prompts") and
|
||||||
click.confirm("Do you want to continue?")):
|
not click.confirm("Do you want to continue?")):
|
||||||
|
raise exception.AbortedByUser()
|
||||||
|
|
||||||
|
project_file = join(project_dir, "platformio.ini")
|
||||||
|
src_dir = join(project_dir, "src")
|
||||||
|
lib_dir = join(project_dir, "lib")
|
||||||
|
|
||||||
for d in (src_dir, lib_dir):
|
for d in (src_dir, lib_dir):
|
||||||
if not isdir(d):
|
if not isdir(d):
|
||||||
makedirs(d)
|
makedirs(d)
|
||||||
|
|
||||||
if not isfile(project_file):
|
if not isfile(project_file):
|
||||||
copyfile(join(get_source_dir(), "projectconftpl.ini"),
|
copyfile(join(get_source_dir(), "projectconftpl.ini"),
|
||||||
project_file)
|
project_file)
|
||||||
|
|
||||||
if board:
|
if board:
|
||||||
fill_project_envs(project_file, board, disable_auto_uploading)
|
fill_project_envs(project_file, board, disable_auto_uploading)
|
||||||
|
|
||||||
click.secho(
|
click.secho(
|
||||||
"\nProject has been successfully initialized!\nUseful commands:\n"
|
"\nProject has been successfully initialized!\nUseful commands:\n"
|
||||||
"`platformio run` - process/build project from the current "
|
"`platformio run` - process/build project from the current "
|
||||||
@@ -93,28 +90,34 @@ def cli(project_dir, board, disable_auto_uploading):
|
|||||||
"files)",
|
"files)",
|
||||||
fg="green"
|
fg="green"
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise exception.AbortedByUser()
|
|
||||||
|
|
||||||
|
|
||||||
def fill_project_envs(project_file, board_types, disable_auto_uploading):
|
def fill_project_envs(project_file, board_types, disable_auto_uploading):
|
||||||
builtin_boards = get_boards()
|
builtin_boards = get_boards()
|
||||||
content = []
|
content = []
|
||||||
for type_ in board_types:
|
used_envs = []
|
||||||
if type_ not in builtin_boards:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
content.append("")
|
|
||||||
|
|
||||||
|
with open(project_file) as f:
|
||||||
|
used_envs = [l.strip() for l in f.read().splitlines() if
|
||||||
|
l.strip().startswith("[env:")]
|
||||||
|
|
||||||
|
for type_ in board_types:
|
||||||
data = builtin_boards[type_]
|
data = builtin_boards[type_]
|
||||||
|
env_name = "[env:autogen_%s]" % type_
|
||||||
|
|
||||||
|
if env_name in used_envs:
|
||||||
|
continue
|
||||||
|
|
||||||
|
content.append("")
|
||||||
|
content.append(env_name)
|
||||||
|
content.append("platform = %s" % data['platform'])
|
||||||
|
|
||||||
# find default framework for board
|
# find default framework for board
|
||||||
frameworks = data.get("frameworks")
|
frameworks = data.get("frameworks")
|
||||||
content.append("[env:autogen_%s]" % type_)
|
|
||||||
content.append("platform = %s" % data['platform'])
|
|
||||||
if frameworks:
|
if frameworks:
|
||||||
content.append("framework = %s" % frameworks[0])
|
content.append("framework = %s" % frameworks[0])
|
||||||
content.append("board = %s" % type_)
|
|
||||||
|
|
||||||
|
content.append("board = %s" % type_)
|
||||||
content.append("%stargets = upload" % ("# " if disable_auto_uploading
|
content.append("%stargets = upload" % ("# " if disable_auto_uploading
|
||||||
else ""))
|
else ""))
|
||||||
|
|
||||||
|
@@ -96,12 +96,6 @@ class UnsupportedArchiveType(PlatformioException):
|
|||||||
MESSAGE = "Can not unpack file '%s'"
|
MESSAGE = "Can not unpack file '%s'"
|
||||||
|
|
||||||
|
|
||||||
class ProjectInitialized(PlatformioException):
|
|
||||||
|
|
||||||
MESSAGE = ("Project is already initialized. "
|
|
||||||
"Process it with `platformio run` command")
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectEnvsNotAvailable(PlatformioException):
|
class ProjectEnvsNotAvailable(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "Please setup environments in `platformio.ini` file."
|
MESSAGE = "Please setup environments in `platformio.ini` file."
|
||||||
|
Reference in New Issue
Block a user