diff --git a/larigira/audiogen.py b/larigira/audiogen.py index 95d5894..fb7a21e 100644 --- a/larigira/audiogen.py +++ b/larigira/audiogen.py @@ -1,21 +1,15 @@ from __future__ import print_function import sys import argparse -from pkg_resources import iter_entry_points +from entrypoints_utils import get_one_entrypoint import json -import logging +from logging import getLogger +log = getLogger('audiogen') def get_audiogenerator(kind): '''Messes with entrypoints to return an audiogenerator function''' - points = tuple(iter_entry_points(group='larigira.audiogenerators', - name=kind)) - if not points: - raise ValueError('cant find a generator for ', kind) - if len(points) > 1: - logging.warning("Found more than one audiogenerator for '%s'" % kind) - gen = points[0] - return gen.load() + return get_one_entrypoint('larigira.audiogenerators', kind) def get_parser(): @@ -49,7 +43,7 @@ def main(): spec = read_spec(args.audiospec[0]) errors = tuple(check_spec(spec)) if errors: - logging.error("Errors in audiospec") + log.error("Errors in audiospec") for err in errors: print(err) # TODO: to stderr sys.exit(1) diff --git a/larigira/entrypoints_utils.py b/larigira/entrypoints_utils.py new file mode 100644 index 0000000..1f556cf --- /dev/null +++ b/larigira/entrypoints_utils.py @@ -0,0 +1,13 @@ +from logging import getLogger +log = getLogger('entrypoints_utils') +from pkg_resources import iter_entry_points + + +def get_one_entrypoint(group, kind): + '''Messes with entrypoints to return an entrypoint of a given group/kind''' + points = tuple(iter_entry_points(group=group, name=kind)) + if not points: + raise ValueError('cant find an entrypoint %s:%s' % (group, kind)) + if len(points) > 1: + log.warning("Found more than one timeform for %s:%s" % (group, kind)) + return points[0].load() diff --git a/larigira/timegen.py b/larigira/timegen.py index 8c500f1..2846ddd 100644 --- a/larigira/timegen.py +++ b/larigira/timegen.py @@ -4,22 +4,16 @@ main module to read and get informations about alarms from __future__ import print_function import sys import argparse -from pkg_resources import iter_entry_points +from entrypoints_utils import get_one_entrypoint import json -import logging +from logging import getLogger +log = getLogger('timegen') from datetime import datetime def get_timegenerator(kind): '''Messes with entrypoints to return an timegenerator function''' - points = tuple(iter_entry_points(group='larigira.timegenerators', - name=kind)) - if not points: - raise ValueError('cant find a generator for ', kind) - if len(points) > 1: - logging.warning("Found more than one timegenerator for '%s'" % kind) - gen = points[0] - return gen.load() + return get_one_entrypoint('larigira.timegenerators', kind) def get_parser(): @@ -65,7 +59,7 @@ def main(): spec = read_spec(args.timespec[0]) errors = tuple(check_spec(spec)) if errors: - logging.error("Errors in timespec") + log.error("Errors in timespec") for err in errors: print(err) # TODO: to stderr sys.exit(1)