diff --git a/whipper/__init__.py b/whipper/__init__.py
index d795e3f9..550c41f6 100644
--- a/whipper/__init__.py
+++ b/whipper/__init__.py
@@ -4,7 +4,7 @@
__version__ = '0.7.2'
-level = logging.WARNING
+level = logging.INFO
if 'WHIPPER_DEBUG' in os.environ:
level = os.environ['WHIPPER_DEBUG'].upper()
if 'WHIPPER_LOGFILE' in os.environ:
diff --git a/whipper/command/accurip.py b/whipper/command/accurip.py
index 1859fdb2..d1f551b6 100644
--- a/whipper/command/accurip.py
+++ b/whipper/command/accurip.py
@@ -18,8 +18,6 @@
# You should have received a copy of the GNU General Public License
# along with whipper. If not, see .
-import sys
-
from whipper.command.basecommand import BaseCommand
from whipper.common.accurip import get_db_entry, ACCURATERIP_URL
@@ -42,18 +40,17 @@ def do(self):
count = responses[0].num_tracks
- sys.stdout.write("Found %d responses for %d tracks\n\n" % (
- len(responses), count))
+ logger.info("Found %d responses for %d tracks",
+ (len(responses), count))
for (i, r) in enumerate(responses):
if r.num_tracks != count:
- sys.stdout.write(
- "Warning: response %d has %d tracks instead of %d\n" % (
- i, r.num_tracks, count))
+ logger.warning("response %d has %d tracks instead of %d", (
+ i, r.num_tracks, count))
# checksum and confidence by track
for track in range(count):
- sys.stdout.write("Track %d:\n" % (track + 1))
+ print("Track %d:" % (track + 1))
checksums = {}
for (i, r) in enumerate(responses):
@@ -82,9 +79,9 @@ def do(self):
sortedChecksums.reverse()
for highest, checksum in sortedChecksums:
- sys.stdout.write(" %d result(s) for checksum %s: %s\n" % (
- len(checksums[checksum]), checksum,
- str(checksums[checksum])))
+ print(" %d result(s) for checksum %s: %s" % (
+ len(checksums[checksum]),
+ checksum, str(checksums[checksum])))
class AccuRip(BaseCommand):
diff --git a/whipper/command/cd.py b/whipper/command/cd.py
index 8fa6e631..2f284b5f 100644
--- a/whipper/command/cd.py
+++ b/whipper/command/cd.py
@@ -22,7 +22,6 @@
import cdio
import os
import glob
-import sys
import logging
from whipper.command.basecommand import BaseCommand
from whipper.common import (
@@ -84,29 +83,28 @@ def add_arguments(parser):
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 @@ def do(self):
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 @@ def add_arguments(self):
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 @@ def doCommand(self):
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 @@ def _ripIfNotRipped(number):
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 @@ def _ripIfNotRipped(number):
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 @@ def _ripIfNotRipped(number):
"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 @@ def _ripIfNotRipped(number):
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 @@ def _ripIfNotRipped(number):
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 @@ def _ripIfNotRipped(number):
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)
diff --git a/whipper/command/drive.py b/whipper/command/drive.py
index 0046034f..0932375f 100644
--- a/whipper/command/drive.py
+++ b/whipper/command/drive.py
@@ -18,8 +18,6 @@
# You should have received a copy of the GNU General Public License
# along with whipper. If not, see .
-import sys
-
from whipper.command.basecommand import BaseCommand
from whipper.common import config, drive
from whipper.extern.task import task
@@ -40,24 +38,21 @@ def do(self):
runner.run(t)
if t.defeatsCache is None:
- sys.stdout.write(
- 'Cannot analyze the drive. Is there a CD in it?\n')
+ logger.critical('cannot analyze the drive: is there a CD in it?')
return
if not t.defeatsCache:
- sys.stdout.write(
- 'cdparanoia cannot defeat the audio cache on this drive.\n')
+ logger.info('cdparanoia cannot defeat the audio cache '
+ 'on this drive')
else:
- sys.stdout.write(
- 'cdparanoia can defeat the audio cache on this drive.\n')
+ logger.info('cdparanoia can defeat the audio cache on this drive')
info = drive.getDeviceInfo(self.options.device)
if not info:
- sys.stdout.write('Drive caching behaviour not saved:'
- 'could not get device info (requires pycdio).\n')
+ logger.error('Drive caching behaviour not saved: '
+ 'could not get device info')
return
- sys.stdout.write(
- 'Adding drive cache behaviour to configuration file.\n')
+ logger.info('adding drive cache behaviour to configuration file')
config.Config().setDefeatsCache(
info[0], info[1], info[2], t.defeatsCache)
@@ -72,48 +67,38 @@ def do(self):
self.config = config.Config()
if not paths:
- sys.stdout.write('No drives found.\n')
- sys.stdout.write('Create /dev/cdrom if you have a CD drive, \n')
- sys.stdout.write('or install pycdio for better detection.\n')
-
+ logger.critical('No drives found. Create /dev/cdrom '
+ 'if you have a CD drive, or install '
+ 'pycdio for better detection')
return
try:
import cdio as _ # noqa: F401 (TODO: fix it in a separate PR?)
except ImportError:
- sys.stdout.write(
- 'Install pycdio for vendor/model/release detection.\n')
+ logger.error('install pycdio for vendor/model/release detection')
return
for path in paths:
vendor, model, release = drive.getDeviceInfo(path)
- sys.stdout.write(
- "drive: %s, vendor: %s, model: %s, release: %s\n" % (
- path, vendor, model, release))
+ print("drive: %s, vendor: %s, model: %s, release: %s" % (
+ path, vendor, model, release))
try:
offset = self.config.getReadOffset(
vendor, model, release)
- sys.stdout.write(
- " Configured read offset: %d\n" % offset)
+ print(" Configured read offset: %d" % offset)
except KeyError:
# Note spaces at the beginning for pretty terminal output
- sys.stdout.write(" "
- "No read offset found. "
- "Run 'whipper offset find'\n")
+ logger.warning("no read offset found. "
+ "Run 'whipper offset find'")
try:
defeats = self.config.getDefeatsCache(
vendor, model, release)
- sys.stdout.write(
- " Can defeat audio cache: %s\n" % defeats)
+ print(" Can defeat audio cache: %s" % defeats)
except KeyError:
- sys.stdout.write(
- " Unknown whether audio cache can be defeated. "
- "Run 'whipper drive analyze'\n")
-
- if not paths:
- sys.stdout.write('No drives found.\n')
+ logger.warning("unknown whether audio cache can be "
+ "defeated. Run 'whipper drive analyze'")
class Drive(BaseCommand):
diff --git a/whipper/command/main.py b/whipper/command/main.py
index 50b3f602..e9c41d4c 100644
--- a/whipper/command/main.py
+++ b/whipper/command/main.py
@@ -19,12 +19,7 @@
def main():
- try:
- server = config.Config().get_musicbrainz_server()
- except KeyError as e:
- sys.stderr.write('whipper: %s\n' % str(e))
- sys.exit()
-
+ server = config.Config().get_musicbrainz_server()
musicbrainzngs.set_hostname(server)
# register plugins with pkg_resources
distributions, _ = pkg_resources.working_set.find_plugins(
@@ -35,7 +30,7 @@ def main():
cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None)
ret = cmd.do()
except SystemError as e:
- sys.stderr.write('whipper: error: %s\n' % e)
+ logger.critical("SystemError: %s", e)
if (isinstance(e, common.EjectError) and
cmd.options.eject in ('failure', 'always')):
eject_device(e.device)
@@ -51,18 +46,17 @@ def main():
if isinstance(e.exception, ImportError):
raise ImportError(e.exception)
elif isinstance(e.exception, common.MissingDependencyException):
- sys.stderr.write('whipper: error: missing dependency "%s"\n' %
- e.exception.dependency)
+ logger.critical('missing dependency "%s"', e.exception.dependency)
return 255
if isinstance(e.exception, common.EmptyError):
logger.debug("EmptyError: %r", str(e.exception))
- sys.stderr.write('whipper: error: Could not create encoded file.\n') # noqa: E501
+ logger.critical('could not create encoded file')
return 255
# in python3 we can instead do `raise e.exception` as that would show
# the exception's original context
- sys.stderr.write(e.exceptionMessage)
+ logger.critical(e.exceptionMessage)
return 255
return ret if ret else 0
diff --git a/whipper/command/offset.py b/whipper/command/offset.py
index 201cd1ac..e0b94a85 100644
--- a/whipper/command/offset.py
+++ b/whipper/command/offset.py
@@ -20,7 +20,6 @@
import argparse
import os
-import sys
import tempfile
import logging
from whipper.command.basecommand import BaseCommand
@@ -79,7 +78,7 @@ def do(self):
device = self.options.device
# if necessary, load and unmount
- sys.stdout.write('Checking device %s\n' % device)
+ logger.info('checking device %s', device)
utils.load_device(device)
utils.unmount_device(device)
@@ -116,25 +115,22 @@ def match(archecksums, track, responses):
return None, None
for offset in self._offsets:
- sys.stdout.write('Trying read offset %d ...\n' % offset)
+ logger.info('trying read offset %d...', offset)
try:
archecksums = self._arcs(runner, table, 1, offset)
except task.TaskException as e:
# let MissingDependency fall through
- if isinstance(e.exception,
- common.MissingDependencyException):
+ if isinstance(e.exception, common.MissingDependencyException):
raise e
if isinstance(e.exception, cdparanoia.FileSizeError):
- sys.stdout.write(
- 'WARNING: cannot rip with offset %d...\n' % offset)
+ logger.warning('cannot rip with offset %d...' % offset)
continue
- logger.warning("Unknown task exception for offset %d: %r" % (
+ logger.warning("unknown task exception for offset %d: %r" % (
offset, e))
- sys.stdout.write(
- 'WARNING: cannot rip with offset %d...\n' % offset)
+ logger.warning('cannot rip with offset %d...' % offset)
continue
logger.debug('AR checksums calculated: %s %s' % archecksums)
@@ -142,10 +138,9 @@ def match(archecksums, track, responses):
c, i = match(archecksums, 1, responses)
if c:
count = 1
- logger.debug('MATCHED against response %d' % i)
- sys.stdout.write(
- 'Offset of device is likely %d, confirming ...\n' %
- offset)
+ logger.debug('matched against response %d' % i)
+ logger.info('offset of device is likely %d, confirming...',
+ offset)
# now try and rip all other tracks as well, except for the
# last one (to avoid readers that can't do overread
@@ -154,9 +149,8 @@ def match(archecksums, track, responses):
archecksums = self._arcs(runner, table, track, offset)
except task.TaskException as e:
if isinstance(e.exception, cdparanoia.FileSizeError):
- sys.stdout.write(
- 'WARNING: cannot rip with offset %d...\n' %
- offset)
+ logger.warning('cannot rip with offset %d...' %
+ offset)
continue
c, i = match(archecksums, track, responses)
@@ -169,16 +163,16 @@ def match(archecksums, track, responses):
self._foundOffset(device, offset)
return 0
else:
- sys.stdout.write(
- 'Only %d of %d tracks matched, continuing ...\n' % (
- count, len(table.tracks)))
+ logger.warning('only %d of %d tracks matched, '
+ 'continuing...',
+ (count, len(table.tracks)))
- sys.stdout.write('No matching offset found.\n')
- sys.stdout.write('Consider trying again with a different disc.\n')
+ logger.error('no matching offset found. '
+ 'Consider trying again with a different disc')
def _arcs(self, runner, table, track, offset):
# rips the track with the given offset, return the arcs checksums
- logger.debug('Ripping track %r with offset %d ...', track, offset)
+ logger.debug('ripping track %r with offset %d...', track, offset)
fd, path = tempfile.mkstemp(
suffix=u'.track%02d.offset%d.whipper.wav' % (
@@ -205,17 +199,15 @@ def _arcs(self, runner, table, track, offset):
return ("%08x" % v1, "%08x" % v2)
def _foundOffset(self, device, offset):
- sys.stdout.write('\nRead offset of device is: %d.\n' %
- offset)
+ print('\nRead offset of device is: %d.' % offset)
info = drive.getDeviceInfo(device)
if not info:
- sys.stdout.write(
- 'Offset not saved: could not get '
- 'device info (requires pycdio).\n')
+ logger.error('offset not saved: '
+ 'could not get device info (requires pycdio)')
return
- sys.stdout.write('Adding read offset to configuration file.\n')
+ logger.info('adding read offset to configuration file')
config.Config().setReadOffset(info[0], info[1], info[2],
offset)
diff --git a/whipper/common/accurip.py b/whipper/common/accurip.py
index 3b64c85a..1fc6d35d 100644
--- a/whipper/common/accurip.py
+++ b/whipper/common/accurip.py
@@ -240,7 +240,7 @@ def verify_result(result, responses, checksums):
def print_report(result):
"""
- Print AccurateRip verification results to stdout.
+ Print AccurateRip verification results.
"""
for i, track in enumerate(result.tracks):
status = 'rip NOT accurate'
diff --git a/whipper/common/program.py b/whipper/common/program.py
index 477b2536..9287f93f 100644
--- a/whipper/common/program.py
+++ b/whipper/common/program.py
@@ -25,7 +25,6 @@
import musicbrainzngs
import re
import os
-import sys
import time
from whipper.common import accurip, cache, checksum, common, mbngs, path
@@ -59,15 +58,12 @@ class Program:
outdir = None
result = None
- _stdout = None
-
- def __init__(self, config, record=False, stdout=sys.stdout):
+ def __init__(self, config, record=False):
"""
@param record: whether to record results of API calls for playback.
"""
self._record = record
self._cache = cache.ResultCache()
- self._stdout = stdout
self._config = config
d = {}
@@ -87,7 +83,7 @@ def __init__(self, config, record=False, stdout=sys.stdout):
def setWorkingDirectory(self, workingDirectory):
if workingDirectory:
- logger.info('Changing to working directory %s' % workingDirectory)
+ logger.info('changing to working directory %s', workingDirectory)
os.chdir(workingDirectory)
def getFastToc(self, runner, device):
@@ -97,9 +93,9 @@ def getFastToc(self, runner, device):
from pkg_resources import parse_version as V
version = cdrdao.getCDRDAOVersion()
if V(version) < V('1.2.3rc2'):
- sys.stdout.write('Warning: cdrdao older than 1.2.3 has a '
- 'pre-gap length bug.\n'
- 'See http://sourceforge.net/tracker/?func=detail&aid=604751&group_id=2171&atid=102171\n') # noqa: E501
+ logger.warning('cdrdao older than 1.2.3 has a '
+ 'pre-gap length bug. '
+ 'See http://sourceforge.net/tracker/?func=detail&aid=604751&group_id=2171&atid=102171') # noqa: E501
toc = cdrdao.ReadTOCTask(device).table
assert toc.hasTOC()
return toc
@@ -125,23 +121,23 @@ def getTable(self, runner, cddbdiscid, mbdiscid, device, offset,
if not itable:
logger.debug('getTable: cddbdiscid %s, mbdiscid %s not '
- 'in cache for offset %s, reading table' % (
+ 'in cache for offset %s, reading table', (
cddbdiscid, mbdiscid, offset))
t = cdrdao.ReadTableTask(device, out_path)
itable = t.table
tdict[offset] = itable
ptable.persist(tdict)
- logger.debug('getTable: read table %r' % itable)
+ logger.debug('getTable: read table %r', itable)
else:
logger.debug('getTable: cddbdiscid %s, mbdiscid %s in cache '
- 'for offset %s' % (cddbdiscid, mbdiscid, offset))
- logger.debug('getTable: loaded table %r' % itable)
+ 'for offset %s', (cddbdiscid, mbdiscid, offset))
+ logger.debug('getTable: loaded table %r', itable)
assert itable.hasTOC()
self.result.table = itable
- logger.debug('getTable: returning table with mb id %s' %
+ logger.debug('getTable: returning table with mb id %s',
itable.getMusicBrainzDiscId())
return itable
@@ -253,12 +249,12 @@ def getCDDB(self, cddbdiscid):
return [item['DTITLE'] for item in md if 'DTITLE' in item] or None
except ValueError as e:
- self._stdout.write("WARNING: CDDB protocol error: %s\n" % e)
+ logger.warning("CDDB protocol error: %s", e)
except IOError as e:
# FIXME: for some reason errno is a str ?
if e.errno == 'socket error':
- self._stdout.write("WARNING: CDDB network error: %r\n" % (e, ))
+ logger.warning("CDDB network error: %r", (e, ))
else:
raise
@@ -270,7 +266,7 @@ def getMusicBrainz(self, ittoc, mbdiscid, release=None, country=None,
@type ittoc: L{whipper.image.table.Table}
"""
# look up disc on MusicBrainz
- self._stdout.write('Disc duration: %s, %d audio tracks\n' % (
+ print('Disc duration: %s, %d audio tracks' % (
common.formatTime(ittoc.duration() / 1000.0),
ittoc.getAudioTracks()))
logger.debug('MusicBrainz submit url: %r',
@@ -287,41 +283,37 @@ def getMusicBrainz(self, ittoc, mbdiscid, release=None, country=None,
record=self._record)
break
except mbngs.NotFoundException as e:
- logger.warning("release not found: %r" % (e, ))
+ logger.warning("release not found: %r", (e, ))
break
except musicbrainzngs.NetworkError as e:
- logger.warning("network error: %r" % (e, ))
+ logger.warning("network error: %r", (e, ))
break
except mbngs.MusicBrainzException as e:
- logger.warning("musicbrainz exception: %r" % (e, ))
+ logger.warning("musicbrainz exception: %r", (e, ))
time.sleep(5)
continue
if not metadatas:
- self._stdout.write('Continuing without metadata\n')
+ logger.warning('continuing without metadata')
if metadatas:
deltas = {}
- self._stdout.write('\nMatching releases:\n')
+ print('\nMatching releases:')
for metadata in metadatas:
- self._stdout.write('\n')
- self._stdout.write('Artist : %s\n' %
- metadata.artist.encode('utf-8'))
- self._stdout.write('Title : %s\n' %
- metadata.title.encode('utf-8'))
- self._stdout.write('Duration: %s\n' %
- common.formatTime(metadata.duration /
- 1000.0))
- self._stdout.write('URL : %s\n' % metadata.url)
- self._stdout.write('Release : %s\n' % metadata.mbid)
- self._stdout.write('Type : %s\n' % metadata.releaseType)
+ print('\nArtist : %s' % metadata.artist.encode('utf-8'))
+ print('Title : %s' % metadata.title.encode('utf-8'))
+ print('Duration: %s' % common.formatTime(
+ metadata.duration / 1000.0))
+ print('URL : %s' % metadata.url)
+ print('Release : %s' % metadata.mbid)
+ print('Type : %s' % metadata.releaseType)
if metadata.barcode:
- self._stdout.write("Barcode : %s\n" % metadata.barcode)
+ print("Barcode : %s" % metadata.barcode)
if metadata.catalogNumber:
- self._stdout.write("Cat no : %s\n" %
- metadata.catalogNumber.encode('utf-8'))
+ print("Cat no : %s" %
+ metadata.catalogNumber.encode('utf-8'))
delta = abs(metadata.duration - ittoc.duration())
if delta not in deltas:
@@ -344,20 +336,15 @@ def getMusicBrainz(self, ittoc, mbdiscid, release=None, country=None,
if release:
metadatas = [m for m in metadatas if m.url.endswith(release)]
- logger.debug('Asked for release %r, only kept %r',
+ logger.debug('asked for release %r, only kept %r',
release, metadatas)
if len(metadatas) == 1:
- self._stdout.write('\n')
- self._stdout.write('Picked requested release id %s\n' %
- release)
- self._stdout.write('Artist : %s\n' %
- metadatas[0].artist.encode('utf-8'))
- self._stdout.write('Title : %s\n' %
- metadatas[0].title.encode('utf-8'))
+ logger.info('picked requested release id %s', release)
+ print('Artist: %s' % metadatas[0].artist.encode('utf-8'))
+ print('Title : %s' % metadatas[0].title.encode('utf-8'))
elif not metadatas:
- self._stdout.write(
- "Requested release id '%s', "
- "but none of the found releases match\n" % release)
+ logger.warning("requested release id '%s', but none of "
+ "the found releases match", release)
return
else:
if lowest:
@@ -370,32 +357,28 @@ def getMusicBrainz(self, ittoc, mbdiscid, release=None, country=None,
for i, metadata in enumerate(metadatas):
if not artist == metadata.artist:
logger.warning("artist 0: %r and artist %d: %r "
- "are not the same" % (
+ "are not the same", (
artist, i, metadata.artist))
if not releaseTitle == metadata.releaseTitle:
logger.warning("title 0: %r and title %d: %r "
- "are not the same" % (
+ "are not the same", (
releaseTitle, i,
metadata.releaseTitle))
if (not release and len(list(deltas)) > 1):
- self._stdout.write('\n')
- self._stdout.write('Picked closest match in duration.\n')
- self._stdout.write('Others may be wrong in MusicBrainz, '
- 'please correct.\n')
- self._stdout.write('Artist : %s\n' %
- artist.encode('utf-8'))
- self._stdout.write('Title : %s\n' %
- metadatas[0].title.encode('utf-8'))
+ logger.warning('picked closest match in duration. '
+ 'Others may be wrong in MusicBrainz, '
+ 'please correct')
+ print('Artist : %s' % artist.encode('utf-8'))
+ print('Title : %s' % metadatas[0].title.encode('utf-8'))
# Select one of the returned releases. We just pick the first one.
ret = metadatas[0]
else:
- self._stdout.write(
- 'Submit this disc to MusicBrainz at the above URL.\n')
+ print('Submit this disc to MusicBrainz at the above URL.')
ret = None
- self._stdout.write('\n')
+ print()
return ret
def getTagList(self, number, mbdiscid):
@@ -427,7 +410,7 @@ def getTagList(self, number, mbdiscid):
mbidTrack = track.mbid
mbidTrackArtist = track.mbidArtist
except IndexError as e:
- print('ERROR: no track %d found, %r' % (number, e))
+ logger.error('no track %d found, %r', (number, e))
raise
else:
# htoa defaults to disc's artist
@@ -484,7 +467,7 @@ def verifyTrack(self, runner, trackResult):
runner.run(t)
except task.TaskException as e:
if isinstance(e.exception, common.MissingFrames):
- logger.warning('missing frames for %r' % trackResult.filename)
+ logger.warning('missing frames for %r', trackResult.filename)
return False
else:
raise
@@ -528,9 +511,9 @@ def ripTrack(self, runner, trackResult, offset, device, taglist,
runner.run(t)
logger.debug('ripped track')
- logger.debug('test speed %.3f/%.3f seconds' % (
+ logger.debug('test speed %.3f/%.3f seconds', (
t.testspeed, t.testduration))
- logger.debug('copy speed %.3f/%.3f seconds' % (
+ logger.debug('copy speed %.3f/%.3f seconds', (
t.copyspeed, t.copyduration))
trackResult.testcrc = t.testchecksum
trackResult.copycrc = t.copychecksum
@@ -544,7 +527,7 @@ def ripTrack(self, runner, trackResult, offset, device, taglist,
if trackResult.filename != t.path:
trackResult.filename = t.path
- logger.info('Filename changed to %r', trackResult.filename)
+ logger.info('filename changed to %r', trackResult.filename)
def verifyImage(self, runner, table):
"""
@@ -565,7 +548,7 @@ def verifyImage(self, runner, table):
return False
responses = accurip.get_db_entry(table.accuraterip_path())
- logger.info('%d AccurateRip response(s) found' % len(responses))
+ logger.info('%d AccurateRip response(s) found', len(responses))
checksums = accurip.calculate_checksums([
os.path.join(os.path.dirname(self.cuePath), t.indexes[1].path)
diff --git a/whipper/extern/task/task.py b/whipper/extern/task/task.py
index 3c2b4a6a..6c396af0 100644
--- a/whipper/extern/task/task.py
+++ b/whipper/extern/task/task.py
@@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with whipper. If not, see .
+from __future__ import print_function
import logging
import sys
@@ -539,16 +540,15 @@ def progressed(self, task, value):
self._task.description, 100.0))
else:
# clear with whitespace
- sys.stdout.write("%s\r" % (' ' * self._longest, ))
+ print(("%s\r" % (' ' * self._longest, )), end='')
def _output(self, what, newline=False, ret=True):
- sys.stdout.write(what)
- sys.stdout.write(' ' * (self._longest - len(what)))
+ print(what, end='')
+ print((' ' * (self._longest - len(what))), end='')
if ret:
- sys.stdout.write('\r')
+ print('\r', end='')
if newline:
- sys.stdout.write('\n')
- sys.stdout.flush()
+ print()
if len(what) > self._longest:
self._longest = len(what)