Commit 074d28a8 authored by Tristan Gingold's avatar Tristan Gingold

action.py: move set_logging_level to __main__

parent 1047c915
...@@ -27,6 +27,8 @@ from __future__ import absolute_import ...@@ -27,6 +27,8 @@ from __future__ import absolute_import
import argparse import argparse
import sys import sys
import logging import logging
from hdlmake.util import shell
from hdlmake.util.termcolor import colored
from .manifest_parser import ManifestParser from .manifest_parser import ManifestParser
from .action.core import ActionCore from .action.core import ActionCore
...@@ -41,17 +43,13 @@ def hdlmake(args): ...@@ -41,17 +43,13 @@ def hdlmake(args):
-- prepare the global module containing the heavy common stuff -- prepare the global module containing the heavy common stuff
""" """
# # Options
# SET & GET PARSER
#
parser = _get_parser() parser = _get_parser()
#
# PARSE & GET OPTIONS
#
options = _get_options(args, parser) options = _get_options(args, parser)
try: try:
set_logging_level(options)
# Create a ModulePool object, this will become our workspace # Create a ModulePool object, this will become our workspace
action = ActionCore(options) action = ActionCore(options)
action.load_top_module() action.load_top_module()
...@@ -207,6 +205,29 @@ def _get_parser(): ...@@ -207,6 +205,29 @@ def _get_parser():
help="display full error log with traceback") help="display full error log with traceback")
return parser return parser
def set_logging_level(options):
"""Set the log level and config (A.K.A. log verbosity)"""
numeric_level = getattr(logging, options.log.upper(), None)
if not isinstance(numeric_level, int):
raise Exception('Invalid log level: %s' % options.log)
if not shell.check_windows() and options.logfile == None:
logging.basicConfig(
format=colored(
"%(levelname)s",
"yellow") + colored(
"\t%(filename)s:%(lineno)d: %(funcName)s()\t",
"blue") + "%(message)s",
level=numeric_level)
else:
logging.basicConfig(
format="%(levelname)s" +
"\t%(filename)s:%(lineno)d: %(funcName)s()\t" +
"%(message)s",
level=numeric_level,
filename=options.logfile)
logging.debug(str(options))
def _get_options(args, parser): def _get_options(args, parser):
"""Function that decodes and set the provided command user options""" """Function that decodes and set the provided command user options"""
...@@ -224,6 +245,3 @@ def _get_options(args, parser): ...@@ -224,6 +245,3 @@ def _get_options(args, parser):
def main(): def main():
"""Entry point used by the executable""" """Entry point used by the executable"""
hdlmake(sys.argv[1:]) hdlmake(sys.argv[1:])
if __name__ == "__main__":
main()
...@@ -30,34 +30,9 @@ import sys ...@@ -30,34 +30,9 @@ import sys
from hdlmake.tools.makefile_writer import load_syn_tool, load_sim_tool from hdlmake.tools.makefile_writer import load_syn_tool, load_sim_tool
from hdlmake.util import shell from hdlmake.util import shell
from hdlmake.util.termcolor import colored
from hdlmake import new_dep_solver as dep_solver from hdlmake import new_dep_solver as dep_solver
from hdlmake.srcfile import SourceFileSet, VHDLFile, VerilogFile, SVFile from hdlmake.srcfile import SourceFileSet, VHDLFile, VerilogFile, SVFile
def set_logging_level(options):
"""Set the log level and config (A.K.A. log verbosity)"""
numeric_level = getattr(logging, options.log.upper(), None)
if not isinstance(numeric_level, int):
raise Exception('Invalid log level: %s' % options.log)
if not shell.check_windows() and options.logfile == None:
logging.basicConfig(
format=colored(
"%(levelname)s",
"yellow") + colored(
"\t%(filename)s:%(lineno)d: %(funcName)s()\t",
"blue") + "%(message)s",
level=numeric_level)
else:
logging.basicConfig(
format="%(levelname)s" +
"\t%(filename)s:%(lineno)d: %(funcName)s()\t" +
"%(message)s",
level=numeric_level,
filename=options.logfile)
logging.debug(str(options))
class Action(list): class Action(list):
"""This is the base class providing the common Action methods""" """This is the base class providing the common Action methods"""
...@@ -69,7 +44,6 @@ class Action(list): ...@@ -69,7 +44,6 @@ class Action(list):
self.privative_fileset = SourceFileSet() self.privative_fileset = SourceFileSet()
self._deps_solved = False self._deps_solved = False
self.options = options self.options = options
set_logging_level(options)
def load_top_module(self): def load_top_module(self):
# Top level module. # Top level module.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment