pep8 fixes

This commit is contained in:
Thomas Vander Stichele
2012-11-11 23:00:37 +00:00
parent 6adf75a832
commit 0fab4515c6
24 changed files with 82 additions and 24 deletions

View File

@@ -21,7 +21,7 @@ coverage: _trial_temp/coverage
python misc/show-coverage.py `ls _trial_temp/coverage/morituri* | grep -v morituri.test | grep -v morituri.extern`
pep8:
python misc/pep8.py $(SOURCES)
for file in $(SOURCES); do python misc/pep8.py --repeat $$file; done
clean-local:
@rm -rf _trial_temp

View File

@@ -27,6 +27,7 @@ Logging
from morituri.extern.log import log as externlog
from morituri.extern.log.log import *
def init():
externlog.init('RIP_DEBUG')
externlog.setPackageScrubList('morituri')

View File

@@ -37,6 +37,7 @@ class MusicBrainzException(Exception):
class TrackMetadata(object):
artist = None
title = None
duration = None # in ms
@@ -131,6 +132,8 @@ def _getMetadata(release):
# see http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/ripper.py
def musicbrainz(discid):
"""
Based on a MusicBrainz disc id, get a list of DiscMetadata objects

View File

@@ -32,6 +32,7 @@ from morituri.result import result
from morituri.program import cdrdao, cdparanoia
from morituri.image import image
def filterForPath(text):
return "-".join(text.split("/"))

View File

@@ -29,6 +29,7 @@ Rename files on file system and inside metafiles in a resumable way.
class Operator(object):
def __init__(self, statePath, key):
self._todo = []
self._done = []
@@ -70,7 +71,6 @@ class Operator(object):
# last task done is i; check if the next one might have gotten done.
self._resuming = True
def save(self):
"""
Saves the state to the given state path using the given key.
@@ -112,6 +112,7 @@ class Operator(object):
class FileRenamer(Operator):
def addRename(self, source, destination):
"""
Add a rename operation.
@@ -124,6 +125,7 @@ class FileRenamer(Operator):
class Operation(object):
def verify(self):
"""
Check if the operation will succeed in the current conditions.
@@ -164,6 +166,7 @@ class Operation(object):
class RenameFile(Operation):
def __init__(self, source, destination):
self._source = source
self._destination = destination
@@ -189,6 +192,7 @@ class RenameFile(Operation):
class RenameInFile(Operation):
def __init__(self, path, source, destination):
self._path = path
self._source = source

View File

@@ -5,8 +5,11 @@ from morituri.extern.log import log
from morituri.extern.task import task, gstreamer
# log.Loggable first to get logging
class SyncRunner(log.Loggable, task.SyncRunner):
pass
class GstPipelineTask(log.Loggable, gstreamer.GstPipelineTask):
pass

View File

@@ -1,6 +1,7 @@
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
def get():
return {
'isinstalled': True,

View File

@@ -1,6 +1,7 @@
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
def get():
return {
'isinstalled': False,

View File

@@ -19,7 +19,9 @@ else:
import select
import fcntl
class Popen(subprocess.Popen):
def recv(self, maxsize=None):
return self._recv('stdout', maxsize)
@@ -41,6 +43,7 @@ class Popen(subprocess.Popen):
setattr(self, which, None)
if subprocess.mswindows:
def send(self, input):
if not self.stdin:
return None
@@ -81,6 +84,7 @@ class Popen(subprocess.Popen):
return read
else:
def send(self, input):
if not self.stdin:
return None
@@ -123,6 +127,7 @@ class Popen(subprocess.Popen):
message = "Other end disconnected!"
def recv_some(p, t=.1, e=1, tr=5, stderr=0):
if tr < 1:
tr = 1
@@ -145,6 +150,7 @@ def recv_some(p, t=.1, e=1, tr=5, stderr=0):
time.sleep(max((x-time.time())/tr, 0))
return ''.join(y)
def send_all(p, data):
while len(data):
sent = p.send(data)

View File

@@ -218,6 +218,7 @@ class File:
"""
I represent a FILE line in a cue file.
"""
def __init__(self, path, format):
"""
@type path: unicode

View File

@@ -31,6 +31,7 @@ from morituri.image import cue, table
from morituri.extern.task import task, gstreamer
class Image(object, log.Loggable):
"""
@ivar table: The Table of Contents for this image.
@@ -90,7 +91,8 @@ class Image(object, log.Loggable):
tracks.append(t)
# FIXME: this probably only works for non-compliant .CUE files
# where pregap is put at end of previous file
t.index(1, absolute=offset, path=self.cue.table.tracks[i].getIndex(1).path,
t.index(1, absolute=offset,
path=self.cue.table.tracks[i].getIndex(1).path,
relative=0)
offset += length
@@ -135,6 +137,7 @@ class AccurateRipChecksumTask(log.Loggable, task.MultiSeparateTask):
self.checksums = [t.checksum for t in self.tasks]
task.MultiSeparateTask.stop(self)
class AudioLengthTask(log.Loggable, gstreamer.GstPipelineTask):
"""
I calculate the length of a track in audio frames.
@@ -147,7 +150,6 @@ class AudioLengthTask(log.Loggable, gstreamer.GstPipelineTask):
playing = False
def __init__(self, path):
"""
@type path: unicode
@@ -186,6 +188,7 @@ class AudioLengthTask(log.Loggable, gstreamer.GstPipelineTask):
self.pipeline.set_state(self.gst.STATE_NULL)
self.stop()
class ImageVerifyTask(log.Loggable, task.MultiSeparateTask):
"""
I verify a disk image and get the necessary track lengths.
@@ -235,6 +238,7 @@ class ImageVerifyTask(log.Loggable, task.MultiSeparateTask):
task.MultiSeparateTask.stop(self)
class ImageEncodeTask(log.Loggable, task.MultiSeparateTask):
"""
I encode a disk image to a different format.

View File

@@ -117,6 +117,7 @@ class Track:
return self.indexes[1].absolute - self.indexes[0].absolute
class Index:
"""
@ivar counter: counter for the index source; distinguishes between
@@ -142,9 +143,10 @@ class Index:
self.counter = counter
def __repr__(self):
return '<Index %02d, absolute %r, path %r, relative %r, counter %r>' % (
return '<Index %02d absolute %r path %r relative %r counter %r>' % (
self.number, self.absolute, self.path, self.relative, self.counter)
class Table(object, log.Loggable):
"""
I represent a table of indexes on a CD.
@@ -232,7 +234,6 @@ class Table(object, log.Loggable):
"""
return len([t for t in self.tracks if not t.audio]) > 0
def _cddbSum(self, i):
ret = 0
while i > 0:
@@ -287,8 +288,6 @@ class Table(object, log.Loggable):
self.debug('CDDB values: %r', result)
return result
def getCDDBValues(self):
"""
Get all CDDB values needed to calculate disc id and lookup URL.
@@ -353,7 +352,6 @@ class Table(object, log.Loggable):
return result
def getCDDBDiscId(self):
"""
Calculate the CDDB disc ID.
@@ -364,7 +362,6 @@ class Table(object, log.Loggable):
values = self.getCDDBValues()
return "%08x" % values[0]
def getMusicBrainzDiscId(self):
"""
Calculate the MusicBrainz disc ID.
@@ -507,7 +504,6 @@ class Table(object, log.Loggable):
self.debug('Musicbrainz values: %r', result)
return result
def getAccurateRipIds(self):
"""
Calculate the two AccurateRip ID's.
@@ -622,6 +618,7 @@ class Table(object, log.Loggable):
return "\n".join(lines)
### methods that modify the table
def clearFiles(self):
"""
Clear all file backings.
@@ -645,7 +642,6 @@ class Table(object, log.Loggable):
except IndexError:
break
def setFile(self, track, index, path, length, counter=None):
"""
Sets the given file as the source from the given index on.
@@ -763,6 +759,7 @@ class Table(object, log.Loggable):
return gap
### lookups
def getNextTrackIndex(self, track, index):
"""
Return the next track and index.
@@ -790,8 +787,8 @@ class Table(object, log.Loggable):
return track, indexes[0]
# various tests for types of Table
def hasTOC(self):
"""
Check if the Table has a complete TOC.

View File

@@ -86,7 +86,9 @@ _INDEX_RE = re.compile(r"""
\s(?P<offset>.+)$ # start offset
""", re.VERBOSE)
class TocFile(object, log.Loggable):
def __init__(self, path):
"""
@type path: unicode
@@ -355,10 +357,12 @@ class TocFile(object, log.Loggable):
raise KeyError("Cannot find file for %r" % path)
class File:
"""
I represent a FILE line in a .toc file.
"""
def __init__(self, path, start, length):
"""
@type path: unicode

View File

@@ -33,6 +33,7 @@ from morituri.common import log, common
from morituri.extern import asyncsub
from morituri.extern.task import task
class FileSizeError(Exception):
message = None
@@ -40,15 +41,18 @@ class FileSizeError(Exception):
"""
The given path does not have the expected size.
"""
def __init__(self, path, message):
self.args = (path, message)
self.path = path
self.message = message
class ReturnCodeError(Exception):
"""
The program had a non-zero return code.
"""
def __init__(self, returncode):
self.args = (returncode, )
self.returncode = returncode
@@ -69,6 +73,7 @@ _ERROR_RE = re.compile("^scsi_read error:")
# from reading cdparanoia source code, it looks like offset is reported in
# number of single-channel samples, ie. 2 bytes per unit, and absolute
class ProgressParser(object):
read = 0 # last [read] frame
wrote = 0 # last [wrote] frame
@@ -92,7 +97,6 @@ class ProgressParser(object):
self._reads = {} # read count for each sector
def parse(self, line):
"""
Parse a line.
@@ -188,6 +192,8 @@ class ProgressParser(object):
# FIXME: handle errors
class ReadTrackTask(log.Loggable, task.Task):
"""
I am a task that reads a track using cdparanoia.
@@ -366,6 +372,7 @@ class ReadTrackTask(log.Loggable, task.Task):
self.stop()
return
class ReadVerifyTrackTask(log.Loggable, task.MultiSeparateTask):
"""
I am a task that reads and verifies a track using cdparanoia.
@@ -460,7 +467,8 @@ class ReadVerifyTrackTask(log.Loggable, task.MultiSeparateTask):
# we chain up should be handled by a parent class function ?
try:
if not self.exception:
self.quality = max(self.tasks[0].quality, self.tasks[2].quality)
self.quality = max(self.tasks[0].quality,
self.tasks[2].quality)
self.peak = self.tasks[4].peak
self.debug('peak: %r', self.peak)

View File

@@ -38,6 +38,7 @@ class ProgramError(Exception):
"""
The program had a fatal error.
"""
def __init__(self, errorMessage):
self.args = (errorMessage, )
self.errorMessage = errorMessage
@@ -80,6 +81,7 @@ class LineParser(object, log.Loggable):
Parse incoming bytes into lines
Calls 'parse' on owner for each parsed line.
"""
def __init__(self, owner):
self._buffer = "" # accumulate characters
self._lines = [] # accumulate lines
@@ -132,7 +134,8 @@ class OutputParser(object, log.Loggable):
# find counter in LEADOUT state; only when we read full toc
self.log('state: %s, buffer bytes: %d', self._state, len(self._buffer))
if self._buffer and self._state == 'LEADOUT':
# split on lines that end in \r, which reset cursor to counter start
# split on lines that end in \r, which reset cursor to counter
# start
# this misses the first one, but that's ok:
# length 03:40:71...\n00:01:00
times = self._buffer.split('\r')
@@ -183,7 +186,6 @@ class OutputParser(object, log.Loggable):
self._parse(lines)
self._lines.extend(lines)
def _parse(self, lines):
for line in lines:
#print 'parsing', len(line), line
@@ -207,7 +209,6 @@ class OutputParser(object, log.Loggable):
error = m.group('error')
self._task.errors.append(error)
def _parse_TRACK(self, line):
if line.startswith('---'):
return
@@ -382,7 +383,6 @@ class DiscInfoTask(CDRDAOTask):
def readbyteserr(self, bytes):
self.parser.read(bytes)
def parse(self, line):
# called by parser
if line.startswith('Sessions'):
@@ -572,12 +572,14 @@ class ReadTOCTask(ReadAllSessionsTask):
class DeviceOpenException(Exception):
def __init__(self, msg):
self.msg = msg
self.args = (msg, )
class ProgramFailedException(Exception):
def __init__(self, code):
self.code = code
self.args = (code, )

View File

@@ -25,13 +25,13 @@ import time
from morituri.common import common
from morituri.configure import configure
class MorituriLogger(object):
def log(self, ripResult, epoch=time.time()):
lines = self.logRip(ripResult, epoch=epoch)
return '\n'.join(lines)
def logRip(self, ripResult, epoch):
lines = []

View File

@@ -24,6 +24,7 @@ import time
from morituri.result import logger
class TrackResult:
"""
@type filename: unicode
@@ -70,6 +71,7 @@ class TrackResult:
classVersion = 2
class RipResult:
"""
I hold information about the result for rips.
@@ -104,6 +106,7 @@ class RipResult:
return None
class Logger(object):
"""
I log the result of a rip.
@@ -120,5 +123,6 @@ class Logger(object):
"""
raise NotImplementedError
def getLogger():
return logger.MorituriLogger()

View File

@@ -22,7 +22,9 @@
from morituri.common import logcommand, accurip
class Show(logcommand.LogCommand):
summary = "show accuraterip data"
def do(self, args):

View File

@@ -201,6 +201,7 @@ See http://sourceforge.net/tracker/?func=detail&aid=604751&group_id=2171&atid=1
prog.result.model = 'Unknown'
# FIXME: turn this into a method
def ripIfNotRipped(number):
# we can have a previous result
trackResult = prog.result.getTrackResult(number)
@@ -364,6 +365,7 @@ See http://sourceforge.net/tracker/?func=detail&aid=604751&group_id=2171&atid=1
class CD(logcommand.LogCommand):
summary = "handle CD's"
subCommandClasses = [Rip, ]

View File

@@ -24,6 +24,7 @@ from morituri.common import logcommand
from morituri.common import task
class Checksum(logcommand.LogCommand):
summary = "run a checksum task"
@@ -46,7 +47,6 @@ class Checksum(logcommand.LogCommand):
self.stdout.write('Checksum: %08x\n' % checksumtask.checksum)
class Encode(logcommand.LogCommand):
summary = "run an encode task"
@@ -85,11 +85,11 @@ class Encode(logcommand.LogCommand):
runner.run(encodetask)
class MusicBrainzNGS(logcommand.LogCommand):
summary = "examine MusicBrainz NGS info"
def do(self, args):
try:
discId = unicode(args[0])
@@ -112,7 +112,9 @@ class MusicBrainzNGS(logcommand.LogCommand):
j + 1, track.artist.encode('utf-8'),
track.title.encode('utf-8')))
class Debug(logcommand.LogCommand):
summary = "debug internals"
subCommandClasses = [Checksum, Encode, MusicBrainzNGS]

View File

@@ -22,7 +22,9 @@
from morituri.common import logcommand, drive
class List(logcommand.LogCommand):
summary = "list drives"
def do(self, args):
@@ -52,6 +54,7 @@ class List(logcommand.LogCommand):
class Drive(logcommand.LogCommand):
summary = "handle drives"
subCommandClasses = [List, ]

View File

@@ -30,6 +30,7 @@ from morituri.extern.task import task
class Encode(logcommand.LogCommand):
summary = "encode image"
def addOptions(self):
@@ -49,7 +50,6 @@ class Encode(logcommand.LogCommand):
default, "', '".join(encode.ALL_PROFILES.keys())),
default=default)
def do(self, args):
prog = program.Program()
prog.outdir = (self.options.output_directory or os.getcwd())
@@ -98,7 +98,9 @@ class Encode(logcommand.LogCommand):
outm3u.write('%s' % root)
outm3u.close()
class Retag(logcommand.LogCommand):
summary = "retag image files"
def do(self, args):
@@ -135,7 +137,9 @@ class Retag(logcommand.LogCommand):
print '%s already tagged correctly' % path
print
class Verify(logcommand.LogCommand):
summary = "verify image"
def do(self, args):
@@ -163,7 +167,9 @@ class Verify(logcommand.LogCommand):
print "\n".join(prog.getAccurateRipResults()) + "\n"
class Image(logcommand.LogCommand):
summary = "handle images"
description = """

View File

@@ -10,6 +10,7 @@ from morituri.rip import cd, offset, drive, image, accurip, debug
from morituri.extern.command import command
from morituri.extern.task import task
def main(argv):
c = Rip()
try:
@@ -53,6 +54,7 @@ cdrdao says:
return ret
class Rip(logcommand.LogCommand):
usage = "%prog %command"
description = """Rip rips CD's.

View File

@@ -45,6 +45,7 @@ OFFSETS = "+6, +48, +102, +667, +12, +30, +618, +594, +738, -472, " + \
"-495, -494, +975, +935, +87, +668, +1776, +1364, +1336, " + \
"+1127"
class Find(logcommand.LogCommand):
summary = "find drive read offset"
description = """Find drive's read offset by ripping tracks from a
@@ -85,7 +86,6 @@ CD in the AccurateRip database."""
# this can be a symlink to another device
def do(self, args):
prog = program.Program()
runner = task.SyncRunner()
@@ -214,6 +214,7 @@ CD in the AccurateRip database."""
os.unlink(path)
return "%08x" % t.checksum
class Offset(logcommand.LogCommand):
summary = "handle drive offsets"