diff --git a/releasenotes/notes/add-verbose-flag-88d72cb01812c616.yaml b/releasenotes/notes/add-verbose-flag-88d72cb01812c616.yaml new file mode 100644 index 0000000..25eed1e --- /dev/null +++ b/releasenotes/notes/add-verbose-flag-88d72cb01812c616.yaml @@ -0,0 +1,3 @@ +--- +features: + - Add the ``--verbose``, ``-v``, and ``-q`` options to the command line tool for producing different levels of debug output. diff --git a/reno/lister.py b/reno/lister.py index d03ffb5..b60267a 100644 --- a/reno/lister.py +++ b/reno/lister.py @@ -12,12 +12,17 @@ from __future__ import print_function +import logging + from reno import scanner from reno import utils +LOG = logging.getLogger(__name__) + def list_cmd(args): "List notes files based on query arguments" + LOG.debug('starting list') reporoot = args.reporoot.rstrip('/') + '/' notesdir = utils.get_notes_dir(args) notes = scanner.get_notes_by_version(reporoot, notesdir, args.branch) diff --git a/reno/main.py b/reno/main.py index 9611b8e..7f4cfb5 100644 --- a/reno/main.py +++ b/reno/main.py @@ -11,6 +11,7 @@ # under the License. import argparse +import logging import sys from reno import create @@ -21,6 +22,21 @@ from reno import report def main(argv=sys.argv[1:]): parser = argparse.ArgumentParser() + parser.add_argument( + '-v', '--verbose', + dest='verbosity', + default=logging.INFO, + help='produce more output', + action='store_const', + const=logging.DEBUG, + ) + parser.add_argument( + '-q', '--quiet', + dest='verbosity', + action='store_const', + const=logging.WARN, + help='produce less output', + ) parser.add_argument( '--rel-notes-dir', '-d', dest='relnotesdir', @@ -89,4 +105,10 @@ def main(argv=sys.argv[1:]): do_report.set_defaults(func=report.report_cmd) args = parser.parse_args() + + logging.basicConfig( + level=args.verbosity, + format='%(message)s', + ) + return args.func(args) diff --git a/reno/scanner.py b/reno/scanner.py index 4bcbb38..d27f461 100644 --- a/reno/scanner.py +++ b/reno/scanner.py @@ -13,6 +13,7 @@ from __future__ import print_function import collections +import logging import os.path import re import subprocess @@ -21,6 +22,7 @@ import sys from reno import utils _TAG_PAT = re.compile('tag: ([\d\.]+)') +LOG = logging.getLogger(__name__) def _get_current_version(reporoot, branch=None): @@ -87,13 +89,15 @@ def get_notes_by_version(reporoot, notesdir, branch=None): they were available, regardless of whether they changed later. """ + LOG.debug('scanning %s/%s (branch=%s)' % (reporoot, notesdir, branch)) + versions = [] earliest_seen = collections.OrderedDict() # Determine the current version, which might be an unreleased or dev # version. current_version = _get_current_version(reporoot, branch) - # print('current_version = %s' % current_version) + LOG.debug('current repository version: %s' % current_version) # Remember the most current filename for each id, to allow for # renames. @@ -105,6 +109,7 @@ def get_notes_by_version(reporoot, notesdir, branch=None): if branch is not None: log_cmd.append(branch) log_cmd.extend(['--', notesdir + '/*.yaml']) + LOG.debug('running %s' % ' '.join(log_cmd)) history_results = utils.check_output(log_cmd, cwd=reporoot) history = history_results.split('\x00') current_version = current_version @@ -121,34 +126,43 @@ def get_notes_by_version(reporoot, notesdir, branch=None): sha = hlines[0].split(' ')[0] tags = _TAG_PAT.findall(hlines[0]) filenames = hlines[2:] + LOG.debug('%s contains files %s' % (sha, filenames)) # If there are no tags in this block, assume the most recently # seen version. if not tags: + LOG.debug('%s is untagged, using %s' % (sha, current_version)) tags = [current_version] else: current_version = tags[0] + LOG.debug('%s has tags, updating current version to %s' % + (sha, current_version)) # Remember each version we have seen. if current_version not in versions: + LOG.debug('%s is a new version' % current_version) versions.append(current_version) # Remember the files seen, using their UUID suffix as a unique id. for f in filenames: # Updated as older tags are found, handling edits to release # notes. + LOG.debug('setting earliest reference to %s to %s' % + (f, tags[0])) uniqueid = _get_unique_id(f) earliest_seen[uniqueid] = tags[0] if uniqueid in last_name_by_id: # We already have a filename for this id from a # new commit, so use that one in case the name has # changed. + LOG.debug('%s was seen before' % f) continue if _file_exists_at_commit(reporoot, f, sha): # Remember this filename as the most recent version of # the unique id we have seen, in case the name # changed from an older commit. last_name_by_id[uniqueid] = (f, sha) + LOG.debug('remembering %s as filename for %s' % (f, uniqueid)) # Invert earliest_seen to make a list of notes files for each # version. diff --git a/reno/tests/test_scanner.py b/reno/tests/test_scanner.py index ab89c16..bc200ec 100644 --- a/reno/tests/test_scanner.py +++ b/reno/tests/test_scanner.py @@ -13,6 +13,7 @@ # under the License. import itertools +import logging import os.path import re import subprocess @@ -156,6 +157,13 @@ class Base(base.TestCase): def setUp(self): super(Base, self).setUp() + self.logger = self.useFixture( + fixtures.FakeLogger( + format='%(levelname)8s %(name)s %(message)s', + level=logging.DEBUG, + nuke_handlers=True, + ) + ) # Older git does not have config --local, so create a temporary home # directory to permit using git config --global without stepping on # developer configuration.