Skip to content

Commit

Permalink
add command line option for log level
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Sep 18, 2021
1 parent 8ab94e8 commit 64cb7f6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions type2nc/type2nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,19 +698,29 @@ def btn_generate_nc_command(self):


if __name__ == "__main__":
logging.basicConfig(level=logging.WARNING)
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('main')
logger.debug("startup")
logger.info("startup")
log_level_map = {'critical': logging.CRITICAL, 'error': logging.ERROR,
'warn': logging.WARNING, 'warning': logging.WARNING,
'info': logging.INFO, 'debug': logging.DEBUG}

cmdl_parser = argparse.ArgumentParser(description="Create Klartext NC code from font files. If no options are given, start gui")
cmdl_parser.add_argument("-i", "--input", metavar="font input file", nargs='+', type=pathlib.Path, help="path of one or more font files")
cmdl_parser.add_argument("-o", "--output", metavar="output folder", type=pathlib.Path, help="path to the output folder where klartext files are generated")
cmdl_parser.add_argument("-s", "--step_size", metavar="step size", type=float, default=0.05, required=False, help="step size for converting curves to line segmenst: between 0.001 (very fine) and 0.2 (very coarse)")
cmdl_parser.add_argument("-d", "--create_demos", action="store_true", default=False, required=False, help="if set, demo output will use cycle 225 for definition of parameters")
cmdl_parser.add_argument("-e", "--create_empty_label", action="store_true", default=False, required=False, help="if set, create label for each selected character, even if it is not defined in the font. Stops errors because of missing label definition")

cmdl_parser.add_argument("-l", "--log", metavar="logging level", default="warning", help="set logging level to critical, error, warn/warning, info or debug. Default is info")

arguments = cmdl_parser.parse_args()

selected_level = log_level_map.get(arguments.log.lower())

if selected_level is None:
raise Exception("the given log level {:s} cant be mapped to an existing log level. It must be one of critical, error, warn/warning, info or debug")
logging.basicConfig(level=selected_level)

if arguments.input is not None:
if not arguments.output.is_dir():
logger.error("the output path '%s' is not a folder", arguments.output)
Expand Down

0 comments on commit 64cb7f6

Please sign in to comment.