This commit is contained in:
Ivan Kravets
2018-09-20 14:55:55 +03:00
parent 24f97ef768
commit e6fa8654ad
11 changed files with 49 additions and 52 deletions

View File

@ -107,8 +107,8 @@ def configure():
try: try:
click_echo_origin[origin](*args, **kwargs) click_echo_origin[origin](*args, **kwargs)
except IOError: except IOError:
(sys.stderr.write if kwargs.get("err") else (sys.stderr.write if kwargs.get("err") else sys.stdout.write)(
sys.stdout.write)("%s\n" % (args[0] if args else "")) "%s\n" % (args[0] if args else ""))
click.echo = lambda *args, **kwargs: _safe_echo(0, *args, **kwargs) click.echo = lambda *args, **kwargs: _safe_echo(0, *args, **kwargs)
click.secho = lambda *args, **kwargs: _safe_echo(1, *args, **kwargs) click.secho = lambda *args, **kwargs: _safe_echo(1, *args, **kwargs)

View File

@ -352,8 +352,8 @@ def get_cid():
pass pass
cid = str( cid = str(
uuid.UUID( uuid.UUID(
bytes=hashlib.md5(str(_uid if _uid else uuid.getnode())) bytes=hashlib.md5(str(_uid if _uid else uuid.getnode())).
.digest())) digest()))
if "windows" in util.get_systype() or os.getuid() > 0: if "windows" in util.get_systype() or os.getuid() > 0:
set_state_item("cid", cid) set_state_item("cid", cid)
return cid return cid

View File

@ -97,8 +97,8 @@ def _dump_defines(env):
board_mcu = env.BoardConfig().get("build.mcu") board_mcu = env.BoardConfig().get("build.mcu")
if board_mcu: if board_mcu:
defines.append( defines.append(
str("__AVR_%s__" % board_mcu.upper() str("__AVR_%s__" % board_mcu.upper().replace(
.replace("ATMEGA", "ATmega").replace("ATTINY", "ATtiny"))) "ATMEGA", "ATmega").replace("ATTINY", "ATtiny")))
# built-in GCC marcos # built-in GCC marcos
# if env.GetCompilerType() == "gcc": # if env.GetCompilerType() == "gcc":

View File

@ -307,13 +307,12 @@ def lib_builtin(storage, json_output):
def lib_show(library, json_output): def lib_show(library, json_output):
lm = LibraryManager() lm = LibraryManager()
name, requirements, _ = lm.parse_pkg_uri(library) name, requirements, _ = lm.parse_pkg_uri(library)
lib_id = lm.search_lib_id( lib_id = lm.search_lib_id({
{ "name": name,
"name": name, "requirements": requirements
"requirements": requirements },
}, silent=json_output,
silent=json_output, interactive=not json_output)
interactive=not json_output)
lib = get_api_result("/lib/info/%d" % lib_id, cache_valid="1d") lib = get_api_result("/lib/info/%d" % lib_id, cache_valid="1d")
if json_output: if json_output:
return click.echo(json.dumps(lib)) return click.echo(json.dumps(lib))
@ -423,16 +422,16 @@ def lib_stats(json_output):
click.echo("-" * terminal_width) click.echo("-" * terminal_width)
def _print_lib_item(item): def _print_lib_item(item):
click.echo((printitemdate_tpl date = str(
if "date" in item else printitem_tpl).format( time.strftime("%c", util.parse_date(item['date'])) if "date" in
name=click.style(item['name'], fg="cyan"), item else "")
date=str( url = click.style(
time.strftime("%c", util.parse_date(item['date'])) "https://platformio.org/lib/show/%s/%s" % (item['id'],
if "date" in item else ""), quote(item['name'])),
url=click.style( fg="blue")
"https://platformio.org/lib/show/%s/%s" % click.echo(
(item['id'], quote(item['name'])), (printitemdate_tpl if "date" in item else printitem_tpl).format(
fg="blue"))) name=click.style(item['name'], fg="cyan"), date=date, url=url))
def _print_tag_item(name): def _print_tag_item(name):
click.echo( click.echo(

View File

@ -273,8 +273,8 @@ def platform_show(platform, json_output): # pylint: disable=too-many-branches
if item['type']: if item['type']:
click.echo("Type: %s" % item['type']) click.echo("Type: %s" % item['type'])
click.echo("Requirements: %s" % item['requirements']) click.echo("Requirements: %s" % item['requirements'])
click.echo("Installed: %s" % ("Yes" if item.get("version") else click.echo("Installed: %s" %
"No (optional)")) ("Yes" if item.get("version") else "No (optional)"))
if "version" in item: if "version" in item:
click.echo("Version: %s" % item['version']) click.echo("Version: %s" % item['version'])
if "originalVersion" in item: if "originalVersion" in item:
@ -365,8 +365,8 @@ def platform_update(platforms, only_packages, only_check, json_output):
if not pkg_dir: if not pkg_dir:
continue continue
latest = pm.outdated(pkg_dir, requirements) latest = pm.outdated(pkg_dir, requirements)
if (not latest and not PlatformFactory.newPlatform(pkg_dir) if (not latest and not PlatformFactory.newPlatform(pkg_dir).
.are_outdated_packages()): are_outdated_packages()):
continue continue
data = _get_installed_platform_data( data = _get_installed_platform_data(
pkg_dir, with_boards=False, expose_packages=False) pkg_dir, with_boards=False, expose_packages=False)

View File

@ -210,10 +210,10 @@ class EnvironmentProcessor(object):
if is_error or "piotest_processor" not in self.cmd_ctx.meta: if is_error or "piotest_processor" not in self.cmd_ctx.meta:
print_header( print_header(
"[%s] Took %.2f seconds" % "[%s] Took %.2f seconds" % (
((click.style("ERROR", fg="red", bold=True) (click.style("ERROR", fg="red", bold=True) if is_error else
if is_error else click.style( click.style("SUCCESS", fg="green", bold=True)),
"SUCCESS", fg="green", bold=True)), time() - start_time), time() - start_time),
is_error=is_error) is_error=is_error)
return not is_error return not is_error
@ -384,9 +384,8 @@ def print_summary(results, start_time):
print_header( print_header(
"[%s] Took %.2f seconds" % ( "[%s] Took %.2f seconds" % (
(click.style("SUCCESS", fg="green", bold=True) (click.style("SUCCESS", fg="green", bold=True) if successed else
if successed else click.style("ERROR", fg="red", bold=True)), click.style("ERROR", fg="red", bold=True)), time() - start_time),
time() - start_time),
is_error=not successed) is_error=not successed)

View File

@ -102,8 +102,9 @@ def get_pip_package(to_develop):
pkg_name = os.path.join(cache_dir, "piocoredevelop.zip") pkg_name = os.path.join(cache_dir, "piocoredevelop.zip")
try: try:
with open(pkg_name, "w") as fp: with open(pkg_name, "w") as fp:
r = util.exec_command( r = util.exec_command(["curl", "-fsSL", dl_url],
["curl", "-fsSL", dl_url], stdout=fp, universal_newlines=True) stdout=fp,
universal_newlines=True)
assert r['returncode'] == 0 assert r['returncode'] == 0
# check ZIP structure # check ZIP structure
with ZipFile(pkg_name) as zp: with ZipFile(pkg_name) as zp:

View File

@ -319,8 +319,8 @@ def check_internal_updates(ctx, what):
if not app.get_setting("auto_update_" + what): if not app.get_setting("auto_update_" + what):
click.secho("Please update them via ", fg="yellow", nl=False) click.secho("Please update them via ", fg="yellow", nl=False)
click.secho( click.secho(
"`platformio %s update`" % ("lib --global" if what == "libraries" "`platformio %s update`" %
else "platform"), ("lib --global" if what == "libraries" else "platform"),
fg="cyan", fg="cyan",
nl=False) nl=False)
click.secho(" command.\n", fg="yellow") click.secho(" command.\n", fg="yellow")

View File

@ -237,9 +237,8 @@ class LibraryManager(BasePkgManager):
if not isinstance(values, list): if not isinstance(values, list):
values = [v.strip() for v in values.split(",") if v] values = [v.strip() for v in values.split(",") if v]
for value in values: for value in values:
query.append( query.append('%s:"%s"' %
'%s:"%s"' % (key[:-1] (key[:-1] if key.endswith("s") else key, value))
if key.endswith("s") else key, value))
lib_info = None lib_info = None
result = util.get_api_result( result = util.get_api_result(
@ -337,13 +336,12 @@ class LibraryManager(BasePkgManager):
force=False): force=False):
_name, _requirements, _url = self.parse_pkg_uri(name, requirements) _name, _requirements, _url = self.parse_pkg_uri(name, requirements)
if not _url: if not _url:
name = "id=%d" % self.search_lib_id( name = "id=%d" % self.search_lib_id({
{ "name": _name,
"name": _name, "requirements": _requirements
"requirements": _requirements },
}, silent=silent,
silent=silent, interactive=interactive)
interactive=interactive)
requirements = _requirements requirements = _requirements
pkg_dir = BasePkgManager.install( pkg_dir = BasePkgManager.install(
self, self,

View File

@ -235,8 +235,8 @@ class PlatformFactory(object):
name = pm.load_manifest(platform_dir)['name'] name = pm.load_manifest(platform_dir)['name']
if not platform_dir: if not platform_dir:
raise exception.UnknownPlatform(name if not requirements else raise exception.UnknownPlatform(
"%s@%s" % (name, requirements)) name if not requirements else "%s@%s" % (name, requirements))
platform_cls = None platform_cls = None
if isfile(join(platform_dir, "platform.py")): if isfile(join(platform_dir, "platform.py")):

View File

@ -112,8 +112,8 @@ class MeasurementProtocol(TelemetryBase):
self['cd2'] = "Python/%s %s" % (platform.python_version(), self['cd2'] = "Python/%s %s" % (platform.python_version(),
platform.platform()) platform.platform())
# self['cd3'] = " ".join(_filter_args(sys.argv[1:])) # self['cd3'] = " ".join(_filter_args(sys.argv[1:]))
self['cd4'] = 1 if (not util.is_ci() self['cd4'] = 1 if (not util.is_ci() and
and (caller_id or not util.is_container())) else 0 (caller_id or not util.is_container())) else 0
if caller_id: if caller_id:
self['cd5'] = caller_id.lower() self['cd5'] = caller_id.lower()