forked from platformio/platformio-core
Improve project initialisation
This commit is contained in:
@ -93,10 +93,24 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
|||||||
|
|
||||||
if board:
|
if board:
|
||||||
fill_project_envs(
|
fill_project_envs(
|
||||||
ctx, project_file, board, enable_auto_uploading, env_prefix)
|
ctx, project_file, board, enable_auto_uploading, env_prefix,
|
||||||
|
ide is not None
|
||||||
|
)
|
||||||
|
|
||||||
if ide:
|
if ide:
|
||||||
pg = ProjectGenerator(project_dir, ide, board[0] if board else None)
|
if not board:
|
||||||
|
raise exception.BoardNotDefined()
|
||||||
|
if len(board) > 1:
|
||||||
|
click.secho(
|
||||||
|
"Warning! You have initialised project with more than 1 board"
|
||||||
|
" for the specified IDE.\n"
|
||||||
|
"However, the IDE features (code autocompletion, syntax lint)"
|
||||||
|
" have been configured for the first board '%s' from your list"
|
||||||
|
" '%s'." % (board[0], ", ".join(board)),
|
||||||
|
fg="yellow"
|
||||||
|
)
|
||||||
|
pg = ProjectGenerator(
|
||||||
|
project_dir, ide, board[0])
|
||||||
pg.generate()
|
pg.generate()
|
||||||
|
|
||||||
click.secho(
|
click.secho(
|
||||||
@ -113,7 +127,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
|||||||
|
|
||||||
|
|
||||||
def fill_project_envs(ctx, project_file, board_types, enable_auto_uploading,
|
def fill_project_envs(ctx, project_file, board_types, enable_auto_uploading,
|
||||||
env_prefix):
|
env_prefix, force_download):
|
||||||
builtin_boards = get_boards()
|
builtin_boards = get_boards()
|
||||||
content = []
|
content = []
|
||||||
used_envs = []
|
used_envs = []
|
||||||
@ -144,7 +158,8 @@ def fill_project_envs(ctx, project_file, board_types, enable_auto_uploading,
|
|||||||
if enable_auto_uploading:
|
if enable_auto_uploading:
|
||||||
content.append("targets = upload")
|
content.append("targets = upload")
|
||||||
|
|
||||||
_install_dependent_platforms(ctx, used_platforms)
|
if force_download and used_platforms:
|
||||||
|
_install_dependent_platforms(ctx, used_platforms)
|
||||||
|
|
||||||
if not content:
|
if not content:
|
||||||
return
|
return
|
||||||
|
@ -48,6 +48,13 @@ class PlatformNotInstalledYet(PlatformioException):
|
|||||||
"Use `platformio platforms install` command"
|
"Use `platformio platforms install` command"
|
||||||
|
|
||||||
|
|
||||||
|
class BoardNotDefined(PlatformioException):
|
||||||
|
|
||||||
|
MESSAGE = "You need to specify board type using `-b` or `--board` "\
|
||||||
|
"option. Supported boards list is available via "\
|
||||||
|
" `platformio boards` command"
|
||||||
|
|
||||||
|
|
||||||
class UnknownBoard(PlatformioException):
|
class UnknownBoard(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "Unknown board type '%s'"
|
MESSAGE = "Unknown board type '%s'"
|
||||||
|
@ -20,12 +20,12 @@ from os.path import abspath, basename, expanduser, isdir, join, relpath
|
|||||||
import bottle
|
import bottle
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import util
|
from platformio import exception, util
|
||||||
|
|
||||||
|
|
||||||
class ProjectGenerator(object):
|
class ProjectGenerator(object):
|
||||||
|
|
||||||
def __init__(self, project_dir, ide, board=None):
|
def __init__(self, project_dir, ide, board):
|
||||||
self.project_dir = project_dir
|
self.project_dir = project_dir
|
||||||
self.ide = ide
|
self.ide = ide
|
||||||
self.board = board
|
self.board = board
|
||||||
@ -50,7 +50,7 @@ class ProjectGenerator(object):
|
|||||||
data = {"env_name": section[4:]}
|
data = {"env_name": section[4:]}
|
||||||
for k, v in config.items(section):
|
for k, v in config.items(section):
|
||||||
data[k] = v
|
data[k] = v
|
||||||
if self.board and self.board == data.get("board"):
|
if self.board == data.get("board"):
|
||||||
break
|
break
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -68,16 +68,15 @@ class ProjectGenerator(object):
|
|||||||
["platformio", "-f", "run", "-t", "idedata",
|
["platformio", "-f", "run", "-t", "idedata",
|
||||||
"-e", envdata['env_name'], "-d", self.project_dir]
|
"-e", envdata['env_name'], "-d", self.project_dir]
|
||||||
)
|
)
|
||||||
|
|
||||||
if result['returncode'] != 0 or '"includes":' not in result['out']:
|
if result['returncode'] != 0 or '"includes":' not in result['out']:
|
||||||
return data
|
raise exception.PlatformioException(
|
||||||
|
"\n".join([result['out'], result['err']]))
|
||||||
|
|
||||||
output = result['out']
|
output = result['out']
|
||||||
try:
|
start_index = output.index('\n{"')
|
||||||
start_index = output.index('\n{"')
|
stop_index = output.rindex('}')
|
||||||
stop_index = output.rindex('}')
|
data = json.loads(output[start_index + 1:stop_index + 1])
|
||||||
data = json.loads(output[start_index + 1:stop_index + 1])
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user