Skip to content

Commit

Permalink
adding color support for the terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed May 1, 2017
1 parent da5ab41 commit 260ad55
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test:
./uranium/scripts/uranium_standalone --uranium-dir=. test ${ARGS} -v
./uranium/scripts/uranium_standalone --uranium-dir=. test ${ARGS} -v -sx

build:
./uranium/scripts/uranium_standalone --uranium-dir=.
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
base = os.path.dirname(os.path.abspath(__file__))

install_requires = [
"coloredlogs==6.1",
"deepmerge==0.0.3",
"docopt==0.6.2",
"pip==9.0.1",
Expand Down
18 changes: 18 additions & 0 deletions tests/test_logging_full.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
URANIUM_PY = """
def main(build):
raise Exception("foo")
""".strip()

from uranium.scripts import execute_script
from .conftest import URANIUM_SOURCE_ROOT


def test_error(tmpdir):
# we need to create a virtualenv
tmpdir.join("ubuild.py").write(URANIUM_PY)
code, out, err = execute_script(
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath
)
assert "URANIUM FAILED" in str(out)
assert code == 1
11 changes: 9 additions & 2 deletions uranium/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
)
from .lib.sandbox.venv.activate_this import write_activate_this
from .lib.sandbox import Sandbox
from .lib.log_templates import STARTING_URANIUM, ENDING_URANIUM
from .lib.log_templates import (
STARTING_URANIUM, ENDING_URANIUM, ERRORED_URANIUM
)
from .lib.utils import log_multiline
from .remote import get_remote_script
from .app_globals import _build_proxy
Expand Down Expand Up @@ -158,7 +160,12 @@ def _run(self, options):
LOGGER.debug("", exc_info=True)
log_multiline(LOGGER, logging.ERROR, str(e))
code = 1
log_multiline(LOGGER, logging.INFO, ENDING_URANIUM)
if code:
log_multiline(LOGGER, logging.ERROR,
"task returned error code {0}".format(code))
log_multiline(LOGGER, logging.ERROR, ERRORED_URANIUM)
else:
log_multiline(LOGGER, logging.INFO, ENDING_URANIUM)
finally:
self._options = None
return code
Expand Down
4 changes: 4 additions & 0 deletions uranium/lib/log_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
ENDING_URANIUM = """
=== URANIUM FINISHED ===
""".strip()

ERRORED_URANIUM = """
=== URANIUM FAILED ===
""".strip()
14 changes: 6 additions & 8 deletions uranium/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
which are available in the build object as the build.options.task
and build.options.args, respectively.
"""
import coloredlogs
import docopt
import logging
import os
Expand Down Expand Up @@ -60,7 +61,7 @@ def main(argv=sys.argv[1:]):
try:
return build.run(build_options)
except UraniumException as e:
LOGGER.info("An error occurred: " + str(e))
LOGGER.error("An error occurred: " + str(e))
return 1


Expand All @@ -69,15 +70,12 @@ def _create_stdout_logger(level):
create a logger to stdout. This creates logger for a series
of module we would like to log information on.
"""
out_hdlr = logging.StreamHandler(sys.stdout)
out_hdlr.setFormatter(logging.Formatter(
'[%(asctime)s] %(message)s', "%H:%M:%S"
))
out_hdlr.setLevel(level)
for name in LOGGING_NAMES:
log = logging.getLogger(name)
log.addHandler(out_hdlr)
log.setLevel(level)
coloredlogs.install(level=level, logger=log,
fmt="[%(asctime)s] %(message)s",
datefmt="%H:%M:%S",
stream=sys.stdout)


def _print_tasks(build, script):
Expand Down

0 comments on commit 260ad55

Please sign in to comment.