From 5681a153eb83b436da0efede5aae19f947d7c68f Mon Sep 17 00:00:00 2001 From: Tom Marks Date: Tue, 26 Jun 2018 22:20:50 -0400 Subject: [PATCH] Adds logger and activate level=DEBUG on cli flag --- thanks/cli.py | 7 ++++++- thanks/thanks.py | 11 ++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/thanks/cli.py b/thanks/cli.py index 71171fe..8fa2477 100644 --- a/thanks/cli.py +++ b/thanks/cli.py @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- """Console script for thanks.""" +import logging import click from thanks.thanks import Thanks +logging.basicConfig(level=logging.CRITICAL) +logger = logging.getLogger("thanks") + @click.command() @click.argument("package_name", @@ -27,9 +31,10 @@ def main(package_name, requirements, # pipfile, setuppy, debug, outfile): + if debug: + logger.level = logging.DEBUG thanks = Thanks(debug=debug) for p in package_name: - print(p) thanks.package(p) for r in requirements: requirements_list = r.read().splitlines() diff --git a/thanks/thanks.py b/thanks/thanks.py index fb7a774..e67ae6f 100644 --- a/thanks/thanks.py +++ b/thanks/thanks.py @@ -4,6 +4,7 @@ from collections import namedtuple from humanfriendly.tables import format_pretty_table import json +import logging import os import requirements import requests @@ -13,6 +14,8 @@ from . import package_tools +logger = logging.getLogger("thanks") + JSON_FILE = ("{}/thanks.json".format(os.path.dirname(os.path.realpath(__file__)))) ProjectData = namedtuple('ProjectData', ['name', 'funding_link', 'authors']) @@ -24,8 +27,7 @@ def __init__(self, debug=False): self.give_thanks_to = {} def package(self, package_name): - if self.debug: - print('Checking ', package_name) + logger.debug("Checking {}".format(package_name)) package_data = (self._get_local_data(package_name) or self._get_remote_data(package_name)) if package_data: @@ -43,10 +45,6 @@ def requirements_list(self, requirements_list): # def pipfile(self, pipfile): # pass - def _display_thanks(self): - if self.give_thanks_to: - print(self._generate_output()) - def _get_local_data(self, project_name): try: metadata = package_tools.get_local_metadata(project_name) @@ -82,7 +80,6 @@ def _get_remote_data(self, project_name): data = None return data - def _generate_output(self, colored_output=True): def _uncolored(text, *args, **kwargs): return text