Allow to add more boards to existing platformio.ini // Resolve #167

This commit is contained in:
Ivan Kravets
2015-04-23 12:40:19 +01:00
parent 47b8a4dd69
commit 0d648074e4
3 changed files with 48 additions and 48 deletions

View File

@@ -11,6 +11,9 @@ Release History
(`issue #174 <https://github.com/platformio/platformio/issues/174>`_)
* Added global ``-f, --force`` option which will force to accept any
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
(`issue #168 <https://github.com/platformio/platformio/issues/168>`_)
* Disabled automatic updates by default for platforms, packages and libraries

View File

@@ -31,17 +31,6 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613
@click.option("--disable-auto-uploading", is_flag=True)
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
if board and app.get_setting("enable_prompts"):
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(" %s " % project_dir, fg="cyan", nl=False)
click.secho(
"will be used for the new project.\n"
"will be used for project.\n"
"You can specify another project directory via\n"
"`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.",
fg="yellow"
@@ -72,49 +61,63 @@ def cli(project_dir, board, disable_auto_uploading):
click.echo("%s - Put here project specific or 3-rd party libraries" %
click.style("lib", fg="cyan"))
if (not app.get_setting("enable_prompts") or
click.confirm("Do you want to continue?")):
for d in (src_dir, lib_dir):
if not isdir(d):
makedirs(d)
if not isfile(project_file):
copyfile(join(get_source_dir(), "projectconftpl.ini"),
project_file)
if board:
fill_project_envs(project_file, board, disable_auto_uploading)
click.secho(
"\nProject has been successfully initialized!\nUseful commands:\n"
"`platformio run` - process/build project from the current "
"directory\n"
"`platformio run --target upload` or `platformio run -t upload` "
"- upload firmware to embedded board\n"
"`platformio run --target clean` - clean project (remove compiled "
"files)",
fg="green"
)
else:
if (app.get_setting("enable_prompts") and
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):
if not isdir(d):
makedirs(d)
if not isfile(project_file):
copyfile(join(get_source_dir(), "projectconftpl.ini"),
project_file)
if board:
fill_project_envs(project_file, board, disable_auto_uploading)
click.secho(
"\nProject has been successfully initialized!\nUseful commands:\n"
"`platformio run` - process/build project from the current "
"directory\n"
"`platformio run --target upload` or `platformio run -t upload` "
"- upload firmware to embedded board\n"
"`platformio run --target clean` - clean project (remove compiled "
"files)",
fg="green"
)
def fill_project_envs(project_file, board_types, disable_auto_uploading):
builtin_boards = get_boards()
content = []
for type_ in board_types:
if type_ not in builtin_boards:
continue
else:
content.append("")
used_envs = []
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_]
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
frameworks = data.get("frameworks")
content.append("[env:autogen_%s]" % type_)
content.append("platform = %s" % data['platform'])
if frameworks:
content.append("framework = %s" % frameworks[0])
content.append("board = %s" % type_)
content.append("board = %s" % type_)
content.append("%stargets = upload" % ("# " if disable_auto_uploading
else ""))

View File

@@ -96,12 +96,6 @@ class UnsupportedArchiveType(PlatformioException):
MESSAGE = "Can not unpack file '%s'"
class ProjectInitialized(PlatformioException):
MESSAGE = ("Project is already initialized. "
"Process it with `platformio run` command")
class ProjectEnvsNotAvailable(PlatformioException):
MESSAGE = "Please setup environments in `platformio.ini` file."