Replace sys.std{out,err} statements with logger/print calls (#331)
* Change global default log level to 'INFO'
We're going to increase our usage of logger statements instead of print instructions (where deemed opportune).
* Replace sys.std{out,err} statements with logger/print calls
Fixes #303.
This commit is contained in:
@@ -22,7 +22,6 @@ import argparse
|
||||
import cdio
|
||||
import os
|
||||
import glob
|
||||
import sys
|
||||
import logging
|
||||
from whipper.command.basecommand import BaseCommand
|
||||
from whipper.common import (
|
||||
@@ -84,29 +83,28 @@ class _CD(BaseCommand):
|
||||
def do(self):
|
||||
self.config = config.Config()
|
||||
self.program = program.Program(self.config,
|
||||
record=self.options.record,
|
||||
stdout=sys.stdout)
|
||||
record=self.options.record)
|
||||
self.runner = task.SyncRunner()
|
||||
|
||||
# if the device is mounted (data session), unmount it
|
||||
self.device = self.options.device
|
||||
sys.stdout.write('Checking device %s\n' % self.device)
|
||||
logger.info('checking device %s', self.device)
|
||||
|
||||
utils.load_device(self.device)
|
||||
utils.unmount_device(self.device)
|
||||
|
||||
# first, read the normal TOC, which is fast
|
||||
print("Reading TOC...")
|
||||
logger.info("reading TOC...")
|
||||
self.ittoc = self.program.getFastToc(self.runner, self.device)
|
||||
|
||||
# already show us some info based on this
|
||||
self.program.getRipResult(self.ittoc.getCDDBDiscId())
|
||||
sys.stdout.write("CDDB disc id: %s\n" % self.ittoc.getCDDBDiscId())
|
||||
print("CDDB disc id: %s" % self.ittoc.getCDDBDiscId())
|
||||
self.mbdiscid = self.ittoc.getMusicBrainzDiscId()
|
||||
sys.stdout.write("MusicBrainz disc id %s\n" % self.mbdiscid)
|
||||
print("MusicBrainz disc id %s" % self.mbdiscid)
|
||||
|
||||
sys.stdout.write("MusicBrainz lookup URL %s\n" %
|
||||
self.ittoc.getMusicBrainzSubmitURL())
|
||||
print("MusicBrainz lookup URL %s" %
|
||||
self.ittoc.getMusicBrainzSubmitURL())
|
||||
|
||||
self.program.metadata = (
|
||||
self.program.getMusicBrainz(self.ittoc, self.mbdiscid,
|
||||
@@ -120,12 +118,12 @@ class _CD(BaseCommand):
|
||||
cddbid = self.ittoc.getCDDBValues()
|
||||
cddbmd = self.program.getCDDB(cddbid)
|
||||
if cddbmd:
|
||||
sys.stdout.write('FreeDB identifies disc as %s\n' % cddbmd)
|
||||
logger.info('FreeDB identifies disc as %s', cddbmd)
|
||||
|
||||
# also used by rip cd info
|
||||
if not getattr(self.options, 'unknown', False):
|
||||
logger.critical("unable to retrieve disc metadata, "
|
||||
"--unknown not passed")
|
||||
"--unknown argument not passed")
|
||||
return -1
|
||||
|
||||
self.program.result.isCdr = cdrdao.DetectCdr(self.device)
|
||||
@@ -236,8 +234,7 @@ Log files will log the path to tracks relative to this directory.
|
||||
if info:
|
||||
try:
|
||||
default_offset = config.Config().getReadOffset(*info)
|
||||
sys.stdout.write("Using configured read offset %d\n" %
|
||||
default_offset)
|
||||
logger.info("using configured read offset %d", default_offset)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@@ -340,7 +337,8 @@ Log files will log the path to tracks relative to this directory.
|
||||
logger.critical(msg)
|
||||
raise RuntimeError(msg)
|
||||
else:
|
||||
print("creating output directory %s" % dirname.encode('utf-8'))
|
||||
logger.info("creating output directory %s",
|
||||
dirname.encode('utf-8'))
|
||||
os.makedirs(dirname)
|
||||
|
||||
# FIXME: turn this into a method
|
||||
@@ -381,11 +379,11 @@ Log files will log the path to tracks relative to this directory.
|
||||
logger.debug('previous result %r, expected %r' % (
|
||||
trackResult.filename, path))
|
||||
|
||||
sys.stdout.write('Verifying track %d of %d: %s\n' % (
|
||||
number, len(self.itable.tracks),
|
||||
os.path.basename(path).encode('utf-8')))
|
||||
logger.info('verifying track %d of %d: %s', (
|
||||
number, len(self.itable.tracks),
|
||||
os.path.basename(path).encode('utf-8')))
|
||||
if not self.program.verifyTrack(self.runner, trackResult):
|
||||
sys.stdout.write('Verification failed, reripping...\n')
|
||||
logger.warning('verification failed, reripping...')
|
||||
os.unlink(path)
|
||||
|
||||
if not os.path.exists(path):
|
||||
@@ -399,9 +397,9 @@ Log files will log the path to tracks relative to this directory.
|
||||
tries += 1
|
||||
if tries > 1:
|
||||
extra = " (try %d)" % tries
|
||||
sys.stdout.write('Ripping track %d of %d%s: %s\n' % (
|
||||
number, len(self.itable.tracks), extra,
|
||||
os.path.basename(path).encode('utf-8')))
|
||||
logger.info('ripping track %d of %d%s: %s', (
|
||||
number, len(self.itable.tracks), extra,
|
||||
os.path.basename(path).encode('utf-8')))
|
||||
try:
|
||||
logger.debug('ripIfNotRipped: track %d, try %d',
|
||||
number, tries)
|
||||
@@ -427,17 +425,14 @@ Log files will log the path to tracks relative to this directory.
|
||||
"track can't be ripped. "
|
||||
"Rip attempts number is equal to 'MAX_TRIES'")
|
||||
if trackResult.testcrc == trackResult.copycrc:
|
||||
sys.stdout.write('CRCs match for track %d\n' % number)
|
||||
logger.info('CRCs match for track %d', number)
|
||||
else:
|
||||
raise RuntimeError(
|
||||
"CRCs did not match for track %d\n" % number
|
||||
"CRCs did not match for track %d" % number
|
||||
)
|
||||
|
||||
sys.stdout.write(
|
||||
'Peak level: {}\n'.format(trackResult.peak))
|
||||
|
||||
sys.stdout.write(
|
||||
'Rip quality: {:.2%}\n'.format(trackResult.quality))
|
||||
print('Peak level: %.6f' % (trackResult.peak / 32768.0))
|
||||
print('Rip quality: {:.2%}'.format(trackResult.quality))
|
||||
|
||||
# overlay this rip onto the Table
|
||||
if number == 0:
|
||||
@@ -452,8 +447,7 @@ Log files will log the path to tracks relative to this directory.
|
||||
logger.debug('Unlinking %r', trackResult.filename)
|
||||
os.unlink(trackResult.filename)
|
||||
trackResult.filename = None
|
||||
sys.stdout.write(
|
||||
'HTOA discarded, contains digital silence\n')
|
||||
logger.info('HTOA discarded, contains digital silence')
|
||||
else:
|
||||
self.itable.setFile(1, 0, trackResult.filename,
|
||||
self.ittoc.getTrackStart(1), number)
|
||||
@@ -467,14 +461,15 @@ Log files will log the path to tracks relative to this directory.
|
||||
htoa = self.program.getHTOA()
|
||||
if htoa:
|
||||
start, stop = htoa
|
||||
print('found Hidden Track One Audio from frame %d to %d' % (
|
||||
start, stop))
|
||||
logger.info('found Hidden Track One Audio from frame %d to %d', (
|
||||
start, stop))
|
||||
_ripIfNotRipped(0)
|
||||
|
||||
for i, track in enumerate(self.itable.tracks):
|
||||
# FIXME: rip data tracks differently
|
||||
if not track.audio:
|
||||
print('skipping data track %d, not implemented' % (i + 1))
|
||||
logger.warning('skipping data track %d, not implemented',
|
||||
(i + 1))
|
||||
# FIXME: make it work for now
|
||||
track.indexes[1].relative = 0
|
||||
continue
|
||||
@@ -489,7 +484,7 @@ Log files will log the path to tracks relative to this directory.
|
||||
try:
|
||||
self.program.verifyImage(self.runner, self.ittoc)
|
||||
except accurip.EntryNotFound:
|
||||
print('AccurateRip entry not found')
|
||||
logger.warning('AccurateRip entry not found')
|
||||
|
||||
accurip.print_report(self.program.result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user