Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve all flake8 warnings #163

Merged
merged 3 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion misc/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

soup = BeautifulSoup.BeautifulSoup(doc)

offsets = {} # offset -> total count
offsets = {} # offset -> total count

rows = soup.findAll('tr')
for row in rows:
Expand Down
2 changes: 1 addition & 1 deletion whipper/command/accurip.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import logging
logger = logging.getLogger(__name__)


class Show(BaseCommand):
summary = "show accuraterip data"
description = """
Expand All @@ -52,7 +53,6 @@ def do(self):
"Warning: response %d has %d tracks instead of %d\n" % (
i, r.trackCount, count))


# checksum and confidence by track
for track in range(count):
sys.stdout.write("Track %d:\n" % (track + 1))
Expand Down
1 change: 1 addition & 0 deletions whipper/command/basecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# A: The prefix matching prevents passing '-h' (and possibly other
# options) to the child command.


class BaseCommand():
"""
A base command class for whipper commands.
Expand Down
216 changes: 121 additions & 95 deletions whipper/command/cd.py

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions whipper/command/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import logging
logger = logging.getLogger(__name__)


class RCCue(BaseCommand):
summary = "write a cue file for the cached result"
description = summary
Expand Down Expand Up @@ -148,9 +149,6 @@ class Encode(BaseCommand):
description = summary

def add_arguments(self):
# here to avoid import gst eating our options
from whipper.common import encode

self.parser.add_argument('input', action='store',
help="audio file to encode")
self.parser.add_argument('output', nargs='?', action='store',
Expand All @@ -174,8 +172,8 @@ def do(self):
runner = task.SyncRunner()

logger.debug('Encoding %s to %s',
fromPath.encode('utf-8'),
toPath.encode('utf-8'))
fromPath.encode('utf-8'),
toPath.encode('utf-8'))
encodetask = encode.FlacEncodeTask(fromPath, toPath)

runner.run(encodetask)
Expand Down Expand Up @@ -244,7 +242,7 @@ def do(self):
sys.stdout.write('- Release %d:\n' % (i + 1, ))
sys.stdout.write(' Artist: %s\n' % md.artist.encode('utf-8'))
sys.stdout.write(' Title: %s\n' % md.title.encode('utf-8'))
sys.stdout.write(' Type: %s\n' % md.releaseType.encode('utf-8'))
sys.stdout.write(' Type: %s\n' % md.releaseType.encode('utf-8')) # noqa: E501
sys.stdout.write(' URL: %s\n' % md.url)
sys.stdout.write(' Tracks: %d\n' % len(md.tracks))
if md.catalogNumber:
Expand Down
21 changes: 12 additions & 9 deletions whipper/command/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import logging
logger = logging.getLogger(__name__)


class Analyze(BaseCommand):
summary = "analyze caching behaviour of drive"
description = """Determine whether cdparanoia can defeat the audio cache of the drive."""
description = """Determine whether cdparanoia can defeat the audio cache of the drive.""" # noqa: E501
device_option = True

def do(self):
Expand All @@ -51,14 +52,15 @@ def do(self):

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')
sys.stdout.write('Drive caching behaviour not saved:'
'could not get device info (requires pycdio).\n')
return

sys.stdout.write(
'Adding drive cache behaviour to configuration file.\n')

config.Config().setDefeatsCache(info[0], info[1], info[2],
t.defeatsCache)
config.Config().setDefeatsCache(
info[0], info[1], info[2], t.defeatsCache)


class List(BaseCommand):
Expand All @@ -77,7 +79,7 @@ def do(self):
return

try:
import cdio as _
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')
Expand All @@ -87,16 +89,18 @@ def do(self):
vendor, model, release = drive.getDeviceInfo(path)
sys.stdout.write(
"drive: %s, vendor: %s, model: %s, release: %s\n" % (
path, vendor, model, release))
path, vendor, model, release))

try:
offset = self.config.getReadOffset(
vendor, model, release)
sys.stdout.write(
" Configured read offset: %d\n" % offset)
except KeyError:
sys.stdout.write(
" No read offset found. Run 'whipper offset find'\n")
# Note spaces at the beginning for pretty terminal output
sys.stdout.write(" "
"No read offset found. "
"Run 'whipper offset find'\n")

try:
defeats = self.config.getDefeatsCache(
Expand All @@ -108,7 +112,6 @@ def do(self):
" Unknown whether audio cache can be defeated. "
"Run 'whipper drive analyze'\n")


if not paths:
sys.stdout.write('No drives found.\n')

Expand Down
8 changes: 4 additions & 4 deletions whipper/command/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def do(self):
sys.stdout.write('MusicBrainz disc id is %s\n' % mbdiscid)

sys.stdout.write("MusicBrainz lookup URL %s\n" %
cueImage.table.getMusicBrainzSubmitURL())
cueImage.table.getMusicBrainzSubmitURL())
prog.metadata = prog.getMusicBrainz(cueImage.table, mbdiscid,
release=self.options.release_id,
country=self.options.country,
prompt=self.options.prompt)
release=self.options.release_id, # noqa: E501
country=self.options.country,
prompt=self.options.prompt)

if not prog.metadata:
print 'Not in MusicBrainz database, skipping'
Expand Down
24 changes: 14 additions & 10 deletions whipper/command/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging
logger = logging.getLogger(__name__)


def main():
# set user agent
musicbrainzngs.set_useragent("whipper", whipper.__version__,
Expand Down Expand Up @@ -47,7 +48,7 @@ def main():

if isinstance(e.exception, common.EmptyError):
logger.debug("EmptyError: %r", str(e.exception))
sys.stderr.write('whipper: error: Could not create encoded file.\n')
sys.stderr.write('whipper: error: Could not create encoded file.\n') # noqa: E501
return 255

# in python3 we can instead do `raise e.exception` as that would show
Expand All @@ -56,6 +57,7 @@ def main():
return 255
return ret if ret else 0


class Whipper(BaseCommand):
description = """whipper is a CD ripping utility focusing on accuracy over speed.

Expand All @@ -74,18 +76,20 @@ class Whipper(BaseCommand):

def add_arguments(self):
self.parser.add_argument('-R', '--record',
action='store_true', dest='record',
help="record API requests for playback")
action='store_true', dest='record',
help="record API requests for playback")
self.parser.add_argument('-v', '--version',
action="store_true", dest="version",
help="show version information")
action="store_true", dest="version",
help="show version information")
self.parser.add_argument('-h', '--help',
action="store_true", dest="help",
help="show this help message and exit")
action="store_true", dest="help",
help="show this help message and exit")
self.parser.add_argument('-e', '--eject',
action="store", dest="eject", default="always",
choices=('never', 'failure', 'success', 'always'),
help="when to eject disc (default: always)")
action="store", dest="eject",
default="always",
choices=('never', 'failure',
'success', 'always'),
help="when to eject disc (default: always)")

def handle_arguments(self):
if self.options.help:
Expand Down
39 changes: 21 additions & 18 deletions whipper/command/offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@
import os
import sys
import tempfile

import logging
import gobject
gobject.threads_init()

from whipper.command.basecommand import BaseCommand
from whipper.common import accurip, common, config, drive, program
from whipper.common import accurip, common, config, drive
from whipper.common import task as ctask
from whipper.program import cdrdao, cdparanoia, utils
from whipper.common import checksum

from whipper.extern.task import task

import logging
gobject.threads_init()

logger = logging.getLogger(__name__)

# see http://www.accuraterip.com/driveoffsets.htm
Expand Down Expand Up @@ -117,7 +115,7 @@ def do(self):

if responses[0].cddbDiscId != table.getCDDBDiscId():
logger.warning("AccurateRip response discid different: %s",
responses[0].cddbDiscId)
responses[0].cddbDiscId)

# now rip the first track at various offsets, calculating AccurateRip
# CRC, and matching it against the retrieved ones
Expand All @@ -137,7 +135,7 @@ def match(archecksum, track, responses):

# let MissingDependency fall through
if isinstance(e.exception,
common.MissingDependencyException):
common.MissingDependencyException):
raise e

if isinstance(e.exception, cdparanoia.FileSizeError):
Expand All @@ -159,7 +157,7 @@ def match(archecksum, track, responses):
logger.debug('MATCHED against response %d' % i)
sys.stdout.write(
'Offset of device is likely %d, confirming ...\n' %
offset)
offset)

# now try and rip all other tracks as well, except for the
# last one (to avoid readers that can't do overread
Expand All @@ -185,7 +183,7 @@ def match(archecksum, track, responses):
else:
sys.stdout.write(
'Only %d of %d tracks matched, continuing ...\n' % (
count, len(table.tracks)))
count, len(table.tracks)))

sys.stdout.write('No matching offset found.\n')
sys.stdout.write('Consider trying again with a different disc.\n')
Expand All @@ -201,34 +199,39 @@ def _arcs(self, runner, table, track, offset):
os.close(fd)

t = cdparanoia.ReadTrackTask(path, table,
table.getTrackStart(track), table.getTrackEnd(track),
overread=False, offset=offset, device=self.options.device)
table.getTrackStart(
track), table.getTrackEnd(track),
overread=False, offset=offset,
device=self.options.device)
t.description = 'Ripping track %d with read offset %d' % (
track, offset)
runner.run(t)


# TODO MW: Update this to also use the v2 checksum(s)
t = checksum.FastAccurateRipChecksumTask(path, trackNumber=track,
trackCount=len(table.tracks), wave=True, v2=False)
t = checksum.FastAccurateRipChecksumTask(path,
trackNumber=track,
trackCount=len(table.tracks),
wave=True, v2=False)
runner.run(t)

os.unlink(path)
return "%08x" % t.checksum

def _foundOffset(self, device, offset):
sys.stdout.write('\nRead offset of device is: %d.\n' %
offset)
offset)

info = drive.getDeviceInfo(device)
if not info:
sys.stdout.write('Offset not saved: could not get device info (requires pycdio).\n')
sys.stdout.write(
'Offset not saved: could not get '
'device info (requires pycdio).\n')
return

sys.stdout.write('Adding read offset to configuration file.\n')

config.Config().setReadOffset(info[0], info[1], info[2],
offset)
offset)


class Offset(BaseCommand):
Expand Down
7 changes: 4 additions & 3 deletions whipper/common/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import logging
logger = logging.getLogger(__name__)


class Persister:
"""
I wrap an optional pickle to persist an object to disk.
Expand Down Expand Up @@ -125,7 +126,7 @@ def __init__(self, path):
try:
os.makedirs(self.path)
except OSError, e:
if e.errno != 17: # FIXME
if e.errno != 17: # FIXME
raise

def _getPath(self, key):
Expand Down Expand Up @@ -176,7 +177,7 @@ def getRipResult(self, cddbdiscid, create=True):
presult.persist(presult.object)
else:
logger.debug('result for cddbdiscid %r found in cache, reusing',
cddbdiscid)
cddbdiscid)

return presult

Expand Down Expand Up @@ -218,7 +219,7 @@ def get(self, cddbdiscid, mbdiscid):
ptable.object = None
else:
logger.debug('no valid cached table found for %r' %
cddbdiscid)
cddbdiscid)

if not ptable.object:
# get an empty persistable from the writable location
Expand Down
5 changes: 3 additions & 2 deletions whipper/common/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def start(self, runner):
self.schedule(0.0, self._arc)

def _arc(self):
arc = accuraterip_checksum(self.path, self.trackNumber, self.trackCount,
self._wave, self._v2)
arc = accuraterip_checksum(self.path, self.trackNumber,
self.trackCount,
self._wave, self._v2)
self.checksum = arc

self.stop()
Loading