forked from platformio/platformio-core
Format code with pep8 style
This commit is contained in:
1 parent
0c9d539a92
commit
87d0ead203
27 files changed
+514
-446
No files matched your search
@@ -48,15 +48,21 @@ def cli(query, installed, json_output): # pylint: disable=R0912
|
||||
click.echo("Platform: ", nl=False)
|
||||
click.secho(platform, bold=True)
|
||||
click.echo("-" * terminal_width)
|
||||
click.echo(BOARDLIST_TPL.format(
|
||||
type=click.style("ID", fg="cyan"), mcu="MCU",
|
||||
frequency="Frequency", flash="Flash", ram="RAM", name="Name"))
|
||||
click.echo(
|
||||
BOARDLIST_TPL.format(
|
||||
type=click.style(
|
||||
"ID", fg="cyan"),
|
||||
mcu="MCU",
|
||||
frequency="Frequency",
|
||||
flash="Flash",
|
||||
ram="RAM",
|
||||
name="Name"))
|
||||
click.echo("-" * terminal_width)
|
||||
|
||||
for board in sorted(pboards, key=lambda b: b['id']):
|
||||
if query:
|
||||
search_data = "%s %s" % (
|
||||
board['id'], json.dumps(board).lower())
|
||||
search_data = "%s %s" % (board['id'],
|
||||
json.dumps(board).lower())
|
||||
if query.lower() not in search_data.lower():
|
||||
continue
|
||||
|
||||
@@ -71,11 +77,15 @@ def cli(query, installed, json_output): # pylint: disable=R0912
|
||||
else:
|
||||
ram_size = "%dB" % ram_size
|
||||
|
||||
click.echo(BOARDLIST_TPL.format(
|
||||
type=click.style(board['id'], fg="cyan"),
|
||||
mcu=board['mcu'],
|
||||
frequency="%dMhz" % (board['fcpu'] / 1000000),
|
||||
flash=flash_size, ram=ram_size, name=board['name']))
|
||||
click.echo(
|
||||
BOARDLIST_TPL.format(
|
||||
type=click.style(
|
||||
board['id'], fg="cyan"),
|
||||
mcu=board['mcu'],
|
||||
frequency="%dMhz" % (board['fcpu'] / 1000000),
|
||||
flash=flash_size,
|
||||
ram=ram_size,
|
||||
name=board['name']))
|
||||
|
||||
|
||||
def _get_boards(installed=False):
|
||||
|
||||
+31
-17
@@ -55,19 +55,37 @@ def validate_path(ctx, param, value): # pylint: disable=W0613
|
||||
@click.argument("src", nargs=-1, callback=validate_path)
|
||||
@click.option("-l", "--lib", multiple=True, callback=validate_path)
|
||||
@click.option("--exclude", multiple=True)
|
||||
@click.option("-b", "--board", multiple=True, metavar="ID",
|
||||
callback=validate_boards)
|
||||
@click.option("--build-dir", default=mkdtemp,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option(
|
||||
"-b", "--board", multiple=True, metavar="ID", callback=validate_boards)
|
||||
@click.option(
|
||||
"--build-dir",
|
||||
default=mkdtemp,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option("--keep-build-dir", is_flag=True)
|
||||
@click.option("--project-conf",
|
||||
type=click.Path(exists=True, file_okay=True, dir_okay=False,
|
||||
readable=True, resolve_path=True))
|
||||
@click.option(
|
||||
"--project-conf",
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=True,
|
||||
dir_okay=False,
|
||||
readable=True,
|
||||
resolve_path=True))
|
||||
@click.option("-v", "--verbose", is_flag=True)
|
||||
@click.pass_context
|
||||
def cli(ctx, src, lib, exclude, board, # pylint: disable=R0913
|
||||
build_dir, keep_build_dir, project_conf, verbose):
|
||||
def cli(ctx, # pylint: disable=R0913
|
||||
src,
|
||||
lib,
|
||||
exclude,
|
||||
board,
|
||||
build_dir,
|
||||
keep_build_dir,
|
||||
project_conf,
|
||||
verbose):
|
||||
|
||||
if not src:
|
||||
src = getenv("PLATFORMIO_CI_SRC", "").split(":")
|
||||
@@ -102,9 +120,8 @@ def cli(ctx, src, lib, exclude, board, # pylint: disable=R0913
|
||||
finally:
|
||||
if not keep_build_dir:
|
||||
rmtree(
|
||||
build_dir, onerror=lambda action, name, exc:
|
||||
(chmod(name, stat.S_IWRITE), remove(name))
|
||||
)
|
||||
build_dir,
|
||||
onerror=lambda action, name, exc: (chmod(name, stat.S_IWRITE), remove(name)))
|
||||
|
||||
|
||||
def _clean_dir(dirpath):
|
||||
@@ -113,10 +130,7 @@ def _clean_dir(dirpath):
|
||||
|
||||
|
||||
def _copy_contents(dst_dir, contents):
|
||||
items = {
|
||||
"dirs": set(),
|
||||
"files": set()
|
||||
}
|
||||
items = {"dirs": set(), "files": set()}
|
||||
|
||||
for path in contents:
|
||||
if isdir(path):
|
||||
|
||||
+46
-36
@@ -37,24 +37,35 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613
|
||||
assert not unknown_boards
|
||||
return value
|
||||
except AssertionError:
|
||||
raise click.BadParameter(
|
||||
"%s. Please search for the board ID using "
|
||||
"`platformio boards` command" % ", ".join(unknown_boards))
|
||||
raise click.BadParameter("%s. Please search for the board ID using "
|
||||
"`platformio boards` command" %
|
||||
", ".join(unknown_boards))
|
||||
|
||||
|
||||
@click.command("init", short_help="Initialize new PlatformIO based project")
|
||||
@click.option("--project-dir", "-d", default=getcwd,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option("-b", "--board", multiple=True, metavar="ID",
|
||||
callback=validate_boards)
|
||||
@click.option("--ide",
|
||||
type=click.Choice(ProjectGenerator.get_supported_ides()))
|
||||
@click.option(
|
||||
"--project-dir",
|
||||
"-d",
|
||||
default=getcwd,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option(
|
||||
"-b", "--board", multiple=True, metavar="ID", callback=validate_boards)
|
||||
@click.option(
|
||||
"--ide", type=click.Choice(ProjectGenerator.get_supported_ides()))
|
||||
@click.option("--enable-auto-uploading", is_flag=True)
|
||||
@click.option("--env-prefix", default="")
|
||||
@click.pass_context
|
||||
def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
enable_auto_uploading, env_prefix):
|
||||
def cli(ctx, # pylint: disable=R0913
|
||||
project_dir,
|
||||
board,
|
||||
ide,
|
||||
enable_auto_uploading,
|
||||
env_prefix):
|
||||
|
||||
if project_dir == getcwd():
|
||||
click.secho("\nThe current working directory", fg="yellow", nl=False)
|
||||
@@ -63,18 +74,20 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
"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"
|
||||
)
|
||||
fg="yellow")
|
||||
click.echo("")
|
||||
|
||||
click.echo("The next files/directories will be created in %s" %
|
||||
click.style(project_dir, fg="cyan"))
|
||||
click.style(
|
||||
project_dir, fg="cyan"))
|
||||
click.echo("%s - Project Configuration File. |-> PLEASE EDIT ME <-|" %
|
||||
click.style("platformio.ini", fg="cyan"))
|
||||
click.echo("%s - Put your source files here" %
|
||||
click.style("src", fg="cyan"))
|
||||
click.style(
|
||||
"platformio.ini", fg="cyan"))
|
||||
click.echo("%s - Put your source files here" % click.style(
|
||||
"src", fg="cyan"))
|
||||
click.echo("%s - Put here project specific (private) libraries" %
|
||||
click.style("lib", fg="cyan"))
|
||||
click.style(
|
||||
"lib", fg="cyan"))
|
||||
|
||||
if (app.get_setting("enable_prompts") and
|
||||
not click.confirm("Do you want to continue?")):
|
||||
@@ -83,10 +96,8 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
init_base_project(project_dir)
|
||||
|
||||
if board:
|
||||
fill_project_envs(
|
||||
ctx, project_dir, board,
|
||||
enable_auto_uploading, env_prefix, ide is not None
|
||||
)
|
||||
fill_project_envs(ctx, project_dir, board, enable_auto_uploading,
|
||||
env_prefix, ide is not None)
|
||||
|
||||
if ide:
|
||||
if not board:
|
||||
@@ -102,8 +113,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
"However, the IDE features (code autocompletion, syntax "
|
||||
"linter) have been configured for the first board '%s' from "
|
||||
"your list '%s'." % (board[0], ", ".join(board)),
|
||||
fg="yellow"
|
||||
)
|
||||
fg="yellow")
|
||||
pg = ProjectGenerator(project_dir, ide, board[0])
|
||||
pg.generate()
|
||||
|
||||
@@ -116,8 +126,7 @@ def cli(ctx, project_dir, board, ide, # pylint: disable=R0913
|
||||
"`platformio run --target clean` - clean project (remove compiled "
|
||||
"files)\n"
|
||||
"`platformio run --help` - additional information",
|
||||
fg="green"
|
||||
)
|
||||
fg="green")
|
||||
|
||||
|
||||
def get_first_board(project_dir):
|
||||
@@ -132,8 +141,9 @@ def get_first_board(project_dir):
|
||||
|
||||
def init_base_project(project_dir):
|
||||
if not util.is_platformio_project(project_dir):
|
||||
copyfile(join(util.get_source_dir(), "projectconftpl.ini"),
|
||||
join(project_dir, "platformio.ini"))
|
||||
copyfile(
|
||||
join(util.get_source_dir(), "projectconftpl.ini"),
|
||||
join(project_dir, "platformio.ini"))
|
||||
|
||||
lib_dir = join(project_dir, "lib")
|
||||
src_dir = join(project_dir, "src")
|
||||
@@ -275,8 +285,8 @@ def init_cvs_ignore(project_dir):
|
||||
|
||||
|
||||
def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
|
||||
ctx, project_dir, board_ids, enable_auto_uploading,
|
||||
env_prefix, force_download):
|
||||
ctx, project_dir, board_ids, enable_auto_uploading, env_prefix,
|
||||
force_download):
|
||||
installed_boards = PlatformManager().get_installed_boards()
|
||||
content = []
|
||||
used_boards = []
|
||||
@@ -291,8 +301,8 @@ def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
|
||||
|
||||
for id_ in board_ids:
|
||||
manifest = None
|
||||
for boards in (
|
||||
installed_boards, PlatformManager.get_registered_boards()):
|
||||
for boards in (installed_boards,
|
||||
PlatformManager.get_registered_boards()):
|
||||
for b in boards:
|
||||
if b['id'] == id_:
|
||||
manifest = b
|
||||
@@ -329,10 +339,10 @@ def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals
|
||||
|
||||
def _install_dependent_platforms(ctx, platforms):
|
||||
installed_platforms = [
|
||||
p['name'] for p in PlatformManager().get_installed()]
|
||||
p['name'] for p in PlatformManager().get_installed()
|
||||
]
|
||||
if set(platforms) <= set(installed_platforms):
|
||||
return
|
||||
ctx.invoke(
|
||||
cli_platform_install,
|
||||
platforms=list(set(platforms) - set(installed_platforms))
|
||||
)
|
||||
platforms=list(set(platforms) - set(installed_platforms)))
|
||||
+46
-34
@@ -33,14 +33,26 @@ from platformio.managers.platform import PlatformFactory
|
||||
@click.option("-e", "--environment", multiple=True)
|
||||
@click.option("-t", "--target", multiple=True)
|
||||
@click.option("--upload-port")
|
||||
@click.option("-d", "--project-dir", default=getcwd,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option(
|
||||
"-d",
|
||||
"--project-dir",
|
||||
default=getcwd,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option("-v", "--verbose", is_flag=True)
|
||||
@click.option("--disable-auto-clean", is_flag=True)
|
||||
@click.pass_context
|
||||
def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
project_dir, verbose, disable_auto_clean):
|
||||
def cli(ctx, # pylint: disable=R0913,R0914
|
||||
environment,
|
||||
target,
|
||||
upload_port,
|
||||
project_dir,
|
||||
verbose,
|
||||
disable_auto_clean):
|
||||
assert check_project_envs(project_dir, environment)
|
||||
with util.cd(project_dir):
|
||||
# clean obsolete .pioenvs dir
|
||||
@@ -59,7 +71,8 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
if config.has_option("platformio", "env_default"):
|
||||
env_default = [
|
||||
e.strip()
|
||||
for e in config.get("platformio", "env_default").split(",")]
|
||||
for e in config.get("platformio", "env_default").split(",")
|
||||
]
|
||||
|
||||
results = []
|
||||
for section in config.sections():
|
||||
@@ -71,9 +84,10 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
raise exception.InvalidEnvName(section)
|
||||
|
||||
envname = section[4:]
|
||||
if ((environment and envname not in environment) or
|
||||
(not environment and env_default and
|
||||
envname not in env_default)):
|
||||
skipenv = any([environment and envname not in environment,
|
||||
not environment and env_default and
|
||||
envname not in env_default])
|
||||
if skipenv:
|
||||
# echo("Skipped %s environment" % style(envname, fg="yellow"))
|
||||
continue
|
||||
|
||||
@@ -86,8 +100,8 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
if "piotest" not in options and "piotest" in ctx.meta:
|
||||
options['piotest'] = ctx.meta['piotest']
|
||||
|
||||
ep = EnvironmentProcessor(
|
||||
ctx, envname, options, target, upload_port, verbose)
|
||||
ep = EnvironmentProcessor(ctx, envname, options, target,
|
||||
upload_port, verbose)
|
||||
results.append(ep.process())
|
||||
|
||||
if not all(results):
|
||||
@@ -96,10 +110,7 @@ def cli(ctx, environment, target, upload_port, # pylint: disable=R0913,R0914
|
||||
|
||||
class EnvironmentProcessor(object):
|
||||
|
||||
REMAPED_OPTIONS = {
|
||||
"FRAMEWORK": "PIOFRAMEWORK",
|
||||
"PLATFORM": "PIOPLATFORM"
|
||||
}
|
||||
REMAPED_OPTIONS = {"FRAMEWORK": "PIOFRAMEWORK", "PLATFORM": "PIOPLATFORM"}
|
||||
|
||||
RENAMED_OPTIONS = {
|
||||
"INSTALL_LIBS": "LIB_INSTALL",
|
||||
@@ -107,8 +118,13 @@ class EnvironmentProcessor(object):
|
||||
"LIB_USE": "LIB_FORCE"
|
||||
}
|
||||
|
||||
def __init__(self, cmd_ctx, name, options, # pylint: disable=R0913
|
||||
targets, upload_port, verbose):
|
||||
def __init__(self, # pylint: disable=R0913
|
||||
cmd_ctx,
|
||||
name,
|
||||
options,
|
||||
targets,
|
||||
upload_port,
|
||||
verbose):
|
||||
self.cmd_ctx = cmd_ctx
|
||||
self.name = name
|
||||
self.options = self._validate_options(options)
|
||||
@@ -121,21 +137,21 @@ class EnvironmentProcessor(object):
|
||||
start_time = time()
|
||||
|
||||
click.echo("[%s] Processing %s (%s)" % (
|
||||
datetime.now().strftime("%c"),
|
||||
click.style(self.name, fg="cyan", bold=True),
|
||||
", ".join(["%s: %s" % (k, v) for k, v in self.options.iteritems()])
|
||||
))
|
||||
datetime.now().strftime("%c"), click.style(
|
||||
self.name, fg="cyan", bold=True), ", ".join(
|
||||
["%s: %s" % (k, v) for k, v in self.options.iteritems()])))
|
||||
click.secho("-" * terminal_width, bold=True)
|
||||
|
||||
result = self._run()
|
||||
|
||||
is_error = result['returncode'] != 0
|
||||
if is_error or "piotest_processor" not in self.cmd_ctx.meta:
|
||||
print_header("[%s] Took %.2f seconds" % (
|
||||
(click.style("ERROR", fg="red", bold=True) if is_error
|
||||
else click.style("SUCCESS", fg="green", bold=True)),
|
||||
time() - start_time
|
||||
), is_error=is_error)
|
||||
print_header(
|
||||
"[%s] Took %.2f seconds" % ((click.style(
|
||||
"ERROR", fg="red", bold=True) if is_error else click.style(
|
||||
"SUCCESS", fg="green", bold=True)),
|
||||
time() - start_time),
|
||||
is_error=is_error)
|
||||
|
||||
return not is_error
|
||||
|
||||
@@ -148,10 +164,8 @@ class EnvironmentProcessor(object):
|
||||
click.secho(
|
||||
"Warning! `%s` option is deprecated and will be "
|
||||
"removed in the next release! Please use "
|
||||
"`%s` instead." % (
|
||||
k, self.RENAMED_OPTIONS[_k].lower()),
|
||||
fg="yellow"
|
||||
)
|
||||
"`%s` instead." % (k, self.RENAMED_OPTIONS[_k].lower()),
|
||||
fg="yellow")
|
||||
k = self.RENAMED_OPTIONS[_k].lower()
|
||||
result[k] = v
|
||||
return result
|
||||
@@ -249,12 +263,10 @@ def check_project_envs(project_dir, environments):
|
||||
if not config.sections():
|
||||
raise exception.ProjectEnvsNotAvailable()
|
||||
|
||||
known = set([s[4:] for s in config.sections()
|
||||
if s.startswith("env:")])
|
||||
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))
|
||||
raise exception.UnknownEnvNames(", ".join(unknown), ", ".join(known))
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -46,41 +46,72 @@ def serialports_list(json_output):
|
||||
|
||||
|
||||
if int(PYSERIAL_VERSION[0]) == 3:
|
||||
|
||||
@cli.command("monitor", short_help="Monitor Serial port")
|
||||
@click.option("--port", "-p", help="Port, a number or a device name")
|
||||
@click.option("--baud", "-b", type=int, default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option("--parity", default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option("--rtscts", is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option("--xonxoff", is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option("--rts", default=None, type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state")
|
||||
@click.option("--dtr", default=None, type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state")
|
||||
@click.option("--echo", is_flag=True,
|
||||
help="Enable local echo, default=Off")
|
||||
@click.option("--encoding", default="UTF-8",
|
||||
help="Set the encoding for the serial port (e.g. hexlify, "
|
||||
"Latin1, UTF-8), default: UTF-8")
|
||||
@click.option("--filter", "-f", multiple=True,
|
||||
help="Add text transformation")
|
||||
@click.option("--eol", default="CRLF",
|
||||
type=click.Choice(["CR", "LF", "CRLF"]),
|
||||
help="End of line mode, default=CRLF")
|
||||
@click.option("--raw", is_flag=True,
|
||||
help="Do not apply any encodings/transformations")
|
||||
@click.option("--exit-char", type=int, default=29,
|
||||
help="ASCII code of special character that is used to exit "
|
||||
"the application, default=29 (DEC)")
|
||||
@click.option("--menu-char", type=int, default=20,
|
||||
help="ASCII code of special character that is used to "
|
||||
"control miniterm (menu), default=20 (DEC)")
|
||||
@click.option("--quiet", is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
@click.option(
|
||||
"--baud",
|
||||
"-b",
|
||||
type=int,
|
||||
default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option(
|
||||
"--parity",
|
||||
default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option(
|
||||
"--rtscts",
|
||||
is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option(
|
||||
"--xonxoff",
|
||||
is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option(
|
||||
"--rts",
|
||||
default=None,
|
||||
type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state")
|
||||
@click.option(
|
||||
"--dtr",
|
||||
default=None,
|
||||
type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state")
|
||||
@click.option(
|
||||
"--echo", is_flag=True, help="Enable local echo, default=Off")
|
||||
@click.option(
|
||||
"--encoding",
|
||||
default="UTF-8",
|
||||
help="Set the encoding for the serial port (e.g. hexlify, "
|
||||
"Latin1, UTF-8), default: UTF-8")
|
||||
@click.option(
|
||||
"--filter", "-f", multiple=True, help="Add text transformation")
|
||||
@click.option(
|
||||
"--eol",
|
||||
default="CRLF",
|
||||
type=click.Choice(["CR", "LF", "CRLF"]),
|
||||
help="End of line mode, default=CRLF")
|
||||
@click.option(
|
||||
"--raw",
|
||||
is_flag=True,
|
||||
help="Do not apply any encodings/transformations")
|
||||
@click.option(
|
||||
"--exit-char",
|
||||
type=int,
|
||||
default=29,
|
||||
help="ASCII code of special character that is used to exit "
|
||||
"the application, default=29 (DEC)")
|
||||
@click.option(
|
||||
"--menu-char",
|
||||
type=int,
|
||||
default=20,
|
||||
help="ASCII code of special character that is used to "
|
||||
"control miniterm (menu), default=20 (DEC)")
|
||||
@click.option(
|
||||
"--quiet",
|
||||
is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
def serialports_monitor(**kwargs):
|
||||
if not kwargs['port']:
|
||||
for item in get_serialports():
|
||||
@@ -107,47 +138,78 @@ if int(PYSERIAL_VERSION[0]) == 3:
|
||||
default_port=kwargs['port'],
|
||||
default_baudrate=kwargs['baud'],
|
||||
default_rts=kwargs['rts'],
|
||||
default_dtr=kwargs['dtr']
|
||||
)
|
||||
default_dtr=kwargs['dtr'])
|
||||
except Exception as e: # pylint: disable=W0702
|
||||
raise MinitermException(e)
|
||||
else:
|
||||
|
||||
@cli.command("monitor", short_help="Monitor Serial port")
|
||||
@click.option("--port", "-p", help="Port, a number or a device name")
|
||||
@click.option("--baud", "-b", type=int, default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option("--parity", default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option("--rtscts", is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option("--xonxoff", is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option("--rts", default=None, type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state, default=0")
|
||||
@click.option("--dtr", default=None, type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state, default=0")
|
||||
@click.option("--echo", is_flag=True,
|
||||
help="Enable local echo, default=Off")
|
||||
@click.option("--cr", is_flag=True,
|
||||
help="Do not send CR+LF, send CR only, default=Off")
|
||||
@click.option("--lf", is_flag=True,
|
||||
help="Do not send CR+LF, send LF only, default=Off")
|
||||
@click.option("--debug", "-d", count=True,
|
||||
help="""Debug received data (escape non-printable chars)
|
||||
@click.option(
|
||||
"--baud",
|
||||
"-b",
|
||||
type=int,
|
||||
default=9600,
|
||||
help="Set baud rate, default=9600")
|
||||
@click.option(
|
||||
"--parity",
|
||||
default="N",
|
||||
type=click.Choice(["N", "E", "O", "S", "M"]),
|
||||
help="Set parity, default=N")
|
||||
@click.option(
|
||||
"--rtscts",
|
||||
is_flag=True,
|
||||
help="Enable RTS/CTS flow control, default=Off")
|
||||
@click.option(
|
||||
"--xonxoff",
|
||||
is_flag=True,
|
||||
help="Enable software flow control, default=Off")
|
||||
@click.option(
|
||||
"--rts",
|
||||
default=None,
|
||||
type=click.Choice(["0", "1"]),
|
||||
help="Set initial RTS line state, default=0")
|
||||
@click.option(
|
||||
"--dtr",
|
||||
default=None,
|
||||
type=click.Choice(["0", "1"]),
|
||||
help="Set initial DTR line state, default=0")
|
||||
@click.option(
|
||||
"--echo", is_flag=True, help="Enable local echo, default=Off")
|
||||
@click.option(
|
||||
"--cr",
|
||||
is_flag=True,
|
||||
help="Do not send CR+LF, send CR only, default=Off")
|
||||
@click.option(
|
||||
"--lf",
|
||||
is_flag=True,
|
||||
help="Do not send CR+LF, send LF only, default=Off")
|
||||
@click.option(
|
||||
"--debug",
|
||||
"-d",
|
||||
count=True,
|
||||
help="""Debug received data (escape non-printable chars)
|
||||
# --debug can be given multiple times:
|
||||
# 0: just print what is received
|
||||
# 1: escape non-printable characters, do newlines as unusual
|
||||
# 2: escape non-printable characters, newlines too
|
||||
# 3: hex dump everything""")
|
||||
@click.option("--exit-char", type=int, default=29,
|
||||
help="ASCII code of special character that is used to exit "
|
||||
"the application, default=29 (DEC)")
|
||||
@click.option("--menu-char", type=int, default=20,
|
||||
help="ASCII code of special character that is used to "
|
||||
"control miniterm (menu), default=20 (DEC)")
|
||||
@click.option("--quiet", is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
@click.option(
|
||||
"--exit-char",
|
||||
type=int,
|
||||
default=29,
|
||||
help="ASCII code of special character that is used to exit "
|
||||
"the application, default=29 (DEC)")
|
||||
@click.option(
|
||||
"--menu-char",
|
||||
type=int,
|
||||
default=20,
|
||||
help="ASCII code of special character that is used to "
|
||||
"control miniterm (menu), default=20 (DEC)")
|
||||
@click.option(
|
||||
"--quiet",
|
||||
is_flag=True,
|
||||
help="Diagnostics: suppress non-error messages, default=Off")
|
||||
def serialports_monitor(**kwargs):
|
||||
sys.argv = app.get_session_var("command_ctx").args[1:]
|
||||
|
||||
|
||||
@@ -29,12 +29,14 @@ def settings_get(name):
|
||||
list_tpl = "{name:<40} {value:<35} {description}"
|
||||
terminal_width, _ = click.get_terminal_size()
|
||||
|
||||
click.echo(list_tpl.format(
|
||||
name=click.style("Name", fg="cyan"),
|
||||
value=(click.style("Value", fg="green") +
|
||||
click.style(" [Default]", fg="yellow")),
|
||||
description="Description"
|
||||
))
|
||||
click.echo(
|
||||
list_tpl.format(
|
||||
name=click.style(
|
||||
"Name", fg="cyan"),
|
||||
value=(click.style(
|
||||
"Value", fg="green") + click.style(
|
||||
" [Default]", fg="yellow")),
|
||||
description="Description"))
|
||||
click.echo("-" * terminal_width)
|
||||
|
||||
for _name, _data in sorted(app.DEFAULT_SETTINGS.items()):
|
||||
@@ -55,11 +57,12 @@ def settings_get(name):
|
||||
else:
|
||||
_value_str += click.style(" ", fg="yellow")
|
||||
|
||||
click.echo(list_tpl.format(
|
||||
name=click.style(_name, fg="cyan"),
|
||||
value=_value_str,
|
||||
description=_data['description']
|
||||
))
|
||||
click.echo(
|
||||
list_tpl.format(
|
||||
name=click.style(
|
||||
_name, fg="cyan"),
|
||||
value=_value_str,
|
||||
description=_data['description']))
|
||||
|
||||
|
||||
@cli.command("set", short_help="Set new value for the setting")
|
||||
|
||||
+34
-25
@@ -32,9 +32,16 @@ from platformio.managers.platform import PlatformFactory
|
||||
@click.option("--environment", "-e", multiple=True, metavar="<environment>")
|
||||
@click.option("--skip", multiple=True, metavar="<pattern>")
|
||||
@click.option("--upload-port", metavar="<upload port>")
|
||||
@click.option("-d", "--project-dir", default=getcwd,
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True,
|
||||
writable=True, resolve_path=True))
|
||||
@click.option(
|
||||
"-d",
|
||||
"--project-dir",
|
||||
default=getcwd,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
file_okay=False,
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option("--verbose", "-v", is_flag=True)
|
||||
@click.pass_context
|
||||
def cli(ctx, environment, skip, upload_port, project_dir, verbose):
|
||||
@@ -85,16 +92,17 @@ def cli(ctx, environment, skip, upload_port, project_dir, verbose):
|
||||
elif status is None:
|
||||
status_str = click.style("IGNORED", fg="yellow")
|
||||
|
||||
click.echo("test:%s/env:%s\t%s" % (
|
||||
click.style(testname, fg="yellow"),
|
||||
click.style(envname, fg="cyan"),
|
||||
status_str), err=status is False)
|
||||
click.echo(
|
||||
"test:%s/env:%s\t%s" % (click.style(
|
||||
testname, fg="yellow"), click.style(
|
||||
envname, fg="cyan"), status_str),
|
||||
err=status is False)
|
||||
|
||||
print_header("[%s] Took %.2f seconds" % (
|
||||
(click.style("PASSED", fg="green", bold=True) if passed
|
||||
else click.style("FAILED", fg="red", bold=True)),
|
||||
time() - start_time
|
||||
), is_error=not passed)
|
||||
print_header(
|
||||
"[%s] Took %.2f seconds" % ((click.style(
|
||||
"PASSED", fg="green", bold=True) if passed else click.style(
|
||||
"FAILED", fg="red", bold=True)), time() - start_time),
|
||||
is_error=not passed)
|
||||
|
||||
if not passed:
|
||||
raise exception.ReturnErrorCode()
|
||||
@@ -122,41 +130,42 @@ class TestProcessor(object):
|
||||
return self._run_hardware_test()
|
||||
|
||||
def _progress(self, text, is_error=False):
|
||||
print_header("[test::%s] %s" % (
|
||||
click.style(self.test_name, fg="yellow", bold=True),
|
||||
text
|
||||
), is_error=is_error)
|
||||
print_header(
|
||||
"[test::%s] %s" % (click.style(
|
||||
self.test_name, fg="yellow", bold=True), text),
|
||||
is_error=is_error)
|
||||
click.echo()
|
||||
|
||||
def _build_or_upload(self, target):
|
||||
if self.test_name != "*":
|
||||
self.cmd_ctx.meta['piotest'] = self.test_name
|
||||
return self.cmd_ctx.invoke(
|
||||
cmd_run, project_dir=self.options['project_dir'],
|
||||
cmd_run,
|
||||
project_dir=self.options['project_dir'],
|
||||
upload_port=self.options['upload_port'],
|
||||
verbose=self.options['verbose'],
|
||||
environment=[self.env_name],
|
||||
target=target
|
||||
)
|
||||
target=target)
|
||||
|
||||
def _run_hardware_test(self):
|
||||
click.echo("If you don't see any output for the first 10 secs, "
|
||||
"please reset board (press reset button)")
|
||||
click.echo()
|
||||
ser = serial.Serial(self.get_serial_port(), self.SERIAL_BAUDRATE,
|
||||
timeout=self.SERIAL_TIMEOUT)
|
||||
ser = serial.Serial(
|
||||
self.get_serial_port(),
|
||||
self.SERIAL_BAUDRATE,
|
||||
timeout=self.SERIAL_TIMEOUT)
|
||||
passed = True
|
||||
while True:
|
||||
line = ser.readline().strip()
|
||||
if not line:
|
||||
continue
|
||||
if line.endswith(":PASS"):
|
||||
click.echo("%s\t%s" % (
|
||||
line[:-5], click.style("PASSED", fg="green")))
|
||||
click.echo("%s\t%s" % (line[:-5], click.style(
|
||||
"PASSED", fg="green")))
|
||||
elif ":FAIL:" in line:
|
||||
passed = False
|
||||
click.echo("%s\t%s" % (
|
||||
line, click.style("FAILED", fg="red")))
|
||||
click.echo("%s\t%s" % (line, click.style("FAILED", fg="red")))
|
||||
else:
|
||||
click.echo(line)
|
||||
if all([l in line for l in ("Tests", "Failures", "Ignored")]):
|
||||
|
||||
@@ -19,8 +19,8 @@ from platformio.commands.platform import platform_update as cmd_platform_update
|
||||
from platformio.managers.lib import LibraryManager
|
||||
|
||||
|
||||
@click.command("update",
|
||||
short_help="Update installed Platforms, Packages and Libraries")
|
||||
@click.command(
|
||||
"update", short_help="Update installed Platforms, Packages and Libraries")
|
||||
@click.option(
|
||||
"-c",
|
||||
"--only-check",
|
||||
|
||||
@@ -22,26 +22,22 @@ import requests
|
||||
from platformio import VERSION, __version__, exception, util
|
||||
|
||||
|
||||
@click.command("upgrade",
|
||||
short_help="Upgrade PlatformIO to the latest version")
|
||||
@click.command(
|
||||
"upgrade", short_help="Upgrade PlatformIO to the latest version")
|
||||
def cli():
|
||||
latest = get_latest_version()
|
||||
if __version__ == latest:
|
||||
return click.secho(
|
||||
"You're up-to-date!\nPlatformIO %s is currently the "
|
||||
"newest version available." % __version__, fg="green"
|
||||
)
|
||||
"newest version available." % __version__,
|
||||
fg="green")
|
||||
else:
|
||||
click.secho("Please wait while upgrading PlatformIO ...",
|
||||
fg="yellow")
|
||||
click.secho("Please wait while upgrading PlatformIO ...", fg="yellow")
|
||||
|
||||
to_develop = not all([c.isdigit() for c in latest if c != "."])
|
||||
cmds = (
|
||||
["pip", "install", "--upgrade",
|
||||
"https://github.com/platformio/platformio/archive/develop.zip"
|
||||
if to_develop else "platformio"],
|
||||
["platformio", "--version"]
|
||||
)
|
||||
cmds = (["pip", "install", "--upgrade",
|
||||
"https://github.com/platformio/platformio/archive/develop.zip"
|
||||
if to_develop else "platformio"], ["platformio", "--version"])
|
||||
|
||||
cmd = None
|
||||
r = None
|
||||
@@ -63,21 +59,19 @@ def cli():
|
||||
actual_version = r['out'].strip().split("version", 1)[1].strip()
|
||||
click.secho(
|
||||
"PlatformIO has been successfully upgraded to %s" %
|
||||
actual_version, fg="green")
|
||||
actual_version,
|
||||
fg="green")
|
||||
click.echo("Release notes: ", nl=False)
|
||||
click.secho("http://docs.platformio.org/en/stable/history.html",
|
||||
fg="cyan")
|
||||
click.secho(
|
||||
"http://docs.platformio.org/en/stable/history.html", fg="cyan")
|
||||
except Exception as e: # pylint: disable=W0703
|
||||
if not r:
|
||||
raise exception.UpgradeError(
|
||||
"\n".join([str(cmd), str(e)]))
|
||||
permission_errors = (
|
||||
"permission denied",
|
||||
"not permitted"
|
||||
)
|
||||
raise exception.UpgradeError("\n".join([str(cmd), str(e)]))
|
||||
permission_errors = ("permission denied", "not permitted")
|
||||
if (any([m in r['err'].lower() for m in permission_errors]) and
|
||||
"windows" not in util.get_systype()):
|
||||
click.secho("""
|
||||
click.secho(
|
||||
"""
|
||||
-----------------
|
||||
Permission denied
|
||||
-----------------
|
||||
@@ -86,11 +80,13 @@ You need the `sudo` permission to install Python packages. Try
|
||||
> sudo pip install -U platformio
|
||||
|
||||
WARNING! Don't use `sudo` for the rest PlatformIO commands.
|
||||
""", fg="yellow", err=True)
|
||||
""",
|
||||
fg="yellow",
|
||||
err=True)
|
||||
raise exception.ReturnErrorCode()
|
||||
else:
|
||||
raise exception.UpgradeError(
|
||||
"\n".join([str(cmd), r['out'], r['err']]))
|
||||
raise exception.UpgradeError("\n".join([str(cmd), r['out'], r[
|
||||
'err']]))
|
||||
|
||||
|
||||
def get_latest_version():
|
||||
@@ -107,11 +103,9 @@ def get_latest_version():
|
||||
|
||||
def get_develop_latest_version():
|
||||
version = None
|
||||
r = requests.get(
|
||||
"https://raw.githubusercontent.com/platformio/platformio"
|
||||
"/develop/platformio/__init__.py",
|
||||
headers=util.get_request_defheaders()
|
||||
)
|
||||
r = requests.get("https://raw.githubusercontent.com/platformio/platformio"
|
||||
"/develop/platformio/__init__.py",
|
||||
headers=util.get_request_defheaders())
|
||||
r.raise_for_status()
|
||||
for line in r.text.split("\n"):
|
||||
line = line.strip()
|
||||
@@ -129,9 +123,7 @@ def get_develop_latest_version():
|
||||
|
||||
|
||||
def get_pypi_latest_version():
|
||||
r = requests.get(
|
||||
"https://pypi.python.org/pypi/platformio/json",
|
||||
headers=util.get_request_defheaders()
|
||||
)
|
||||
r = requests.get("https://pypi.python.org/pypi/platformio/json",
|
||||
headers=util.get_request_defheaders())
|
||||
r.raise_for_status()
|
||||
return r.json()['info']['version']
|
||||
Reference in new issue
Block a user