Fix script load module issue (#21763)

* Fix script load depedency

* Revert #21754
This commit is contained in:
Jason Hu 2019-03-07 16:48:14 -08:00 committed by Paulus Schoutsen
parent 2fb978393b
commit 78a806bc5c
2 changed files with 10 additions and 20 deletions

View File

@ -52,15 +52,10 @@ def run(args: List) -> int:
hass = HomeAssistant(loop) hass = HomeAssistant(loop)
pkgload = PackageLoadable(hass) pkgload = PackageLoadable(hass)
for req in getattr(script, 'REQUIREMENTS', []): for req in getattr(script, 'REQUIREMENTS', []):
try: if loop.run_until_complete(pkgload.loadable(req)):
loop.run_until_complete(pkgload.loadable(req))
continue continue
except ImportError:
pass
returncode = install_package(req, **_pip_kwargs) if not install_package(req, **_pip_kwargs):
if not returncode:
print('Aborting script, could not install dependency', req) print('Aborting script, could not install dependency', req)
return 1 return 1

View File

@ -41,20 +41,15 @@ ERROR_STR = 'General Errors'
def color(the_color, *args, reset=None): def color(the_color, *args, reset=None):
"""Color helper.""" """Color helper."""
try:
from colorlog.escape_codes import escape_codes, parse_colors from colorlog.escape_codes import escape_codes, parse_colors
try: try:
if not args: if not args:
assert reset is None, "Cannot reset if nothing being printed" assert reset is None, "You cannot reset if nothing being printed"
return parse_colors(the_color) return parse_colors(the_color)
return parse_colors(the_color) + ' '.join(args) + \ return parse_colors(the_color) + ' '.join(args) + \
escape_codes[reset or 'reset'] escape_codes[reset or 'reset']
except KeyError as k: except KeyError as k:
raise ValueError( raise ValueError("Invalid color {} in {}".format(str(k), the_color))
"Invalid color {} in {}".format(str(k), the_color))
except ImportError:
# We should fallback to black-and-white if colorlog is not installed
return ' '.join(args)
def run(script_args: List) -> int: def run(script_args: List) -> int: