Convert docstrings to reStructuredText
This commit also includes: - whitespace / code formatting fixes - slight syntax related changes: except <exception_name>, e -> except <exception_name> as e - 3 pointless instructions instances have been rewritten [sorted] (spotted by semi-automatic check) The unrelated changes shouldn't have any real impact on whipper's behaviour.
This commit is contained in:
@@ -37,13 +37,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FileSizeError(Exception):
|
||||
"""The given path does not have the expected size."""
|
||||
|
||||
message = None
|
||||
|
||||
"""
|
||||
The given path does not have the expected size.
|
||||
"""
|
||||
|
||||
def __init__(self, path, message):
|
||||
self.args = (path, message)
|
||||
self.path = path
|
||||
@@ -51,9 +48,7 @@ class FileSizeError(Exception):
|
||||
|
||||
|
||||
class ReturnCodeError(Exception):
|
||||
"""
|
||||
The program had a non-zero return code.
|
||||
"""
|
||||
"""The program had a non-zero return code."""
|
||||
|
||||
def __init__(self, returncode):
|
||||
self.args = (returncode, )
|
||||
@@ -79,6 +74,22 @@ _ERROR_RE = re.compile("^scsi_read error:")
|
||||
|
||||
|
||||
class ProgressParser:
|
||||
"""Parse cdparanoia's output information.
|
||||
|
||||
:cvar read:
|
||||
:vartype read:
|
||||
:cvar wrote:
|
||||
:vartype wrote:
|
||||
:cvar errors:
|
||||
:vartype errors:
|
||||
:ivar reads:
|
||||
:vartype reads:
|
||||
:ivar start: first frame to rip.
|
||||
:vartype start: int
|
||||
:ivar stop: last frame to rip (inclusive).
|
||||
:vartype stop: int
|
||||
"""
|
||||
|
||||
read = 0 # last [read] frame
|
||||
wrote = 0 # last [wrote] frame
|
||||
errors = 0 # count of number of scsi errors
|
||||
@@ -87,12 +98,6 @@ class ProgressParser:
|
||||
reads = 0 # total number of reads
|
||||
|
||||
def __init__(self, start, stop):
|
||||
"""
|
||||
@param start: first frame to rip
|
||||
@type start: int
|
||||
@param stop: last frame to rip (inclusive)
|
||||
@type stop: int
|
||||
"""
|
||||
self.start = start
|
||||
self.stop = stop
|
||||
|
||||
@@ -102,8 +107,10 @@ class ProgressParser:
|
||||
self._reads = {} # read count for each sector
|
||||
|
||||
def parse(self, line):
|
||||
"""
|
||||
Parse a line.
|
||||
"""Parse a line.
|
||||
|
||||
:param line:
|
||||
:type line:
|
||||
"""
|
||||
m = _PROGRESS_RE.search(line)
|
||||
if m:
|
||||
@@ -184,9 +191,12 @@ class ProgressParser:
|
||||
self.wrote = frameOffset
|
||||
|
||||
def getTrackQuality(self):
|
||||
"""
|
||||
Each frame gets read twice.
|
||||
"""Each frame gets read twice.
|
||||
|
||||
More than two reads for a frame reduce track quality.
|
||||
|
||||
:returns:
|
||||
:rtype: float or int
|
||||
"""
|
||||
frames = self.stop - self.start + 1 # + 1 since stop is inclusive
|
||||
reads = self.reads
|
||||
@@ -203,10 +213,35 @@ class ProgressParser:
|
||||
# FIXME: handle errors
|
||||
|
||||
class ReadTrackTask(task.Task):
|
||||
"""
|
||||
I am a task that reads a track using cdparanoia.
|
||||
"""I am a task that reads a track using cdparanoia.
|
||||
|
||||
@ivar reads: how many reads were done to rip the track
|
||||
:cvar description:
|
||||
:vartype description:
|
||||
:cvar quality:
|
||||
:cvar speed:
|
||||
:cvar duration:
|
||||
:ivar path: where to store the ripped track.
|
||||
:vartype path: unicode
|
||||
:ivar table: table of contents of CD.
|
||||
:vartype table: L{table.Table}
|
||||
:ivar start: first frame to rip.
|
||||
:vartype start: int
|
||||
:ivar stop: last frame to rip (inclusive); >= start.
|
||||
:vartype stop: int
|
||||
:ivar offset: read offset, in samples.
|
||||
:vartype offset: int
|
||||
:ivar parser:
|
||||
:vartype parser:
|
||||
:ivar device: the device to rip from.
|
||||
:vartype device: str
|
||||
:ivar start_time:
|
||||
:vartype start_time:
|
||||
:ivar overread:
|
||||
:vartype overread:
|
||||
:ivar buffer:
|
||||
:vartype buffer:
|
||||
:ivar errors:
|
||||
:vartype errors:
|
||||
"""
|
||||
|
||||
description = "Reading track"
|
||||
@@ -218,26 +253,6 @@ class ReadTrackTask(task.Task):
|
||||
|
||||
def __init__(self, path, table, start, stop, overread, offset=0,
|
||||
device=None, action="Reading", what="track"):
|
||||
"""
|
||||
Read the given track.
|
||||
|
||||
@param path: where to store the ripped track
|
||||
@type path: unicode
|
||||
@param table: table of contents of CD
|
||||
@type table: L{table.Table}
|
||||
@param start: first frame to rip
|
||||
@type start: int
|
||||
@param stop: last frame to rip (inclusive); >= start
|
||||
@type stop: int
|
||||
@param offset: read offset, in samples
|
||||
@type offset: int
|
||||
@param device: the device to rip from
|
||||
@type device: str
|
||||
@param action: a string representing the action; e.g. Read/Verify
|
||||
@type action: str
|
||||
@param what: a string representing what's being read; e.g. Track
|
||||
@type what: str
|
||||
"""
|
||||
assert type(path) is unicode, "%r is not unicode" % path
|
||||
|
||||
self.path = path
|
||||
@@ -299,7 +314,7 @@ class ReadTrackTask(task.Task):
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
close_fds=True)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
import errno
|
||||
if e.errno == errno.ENOENT:
|
||||
raise common.MissingDependencyException('cdparanoia')
|
||||
@@ -398,24 +413,45 @@ class ReadTrackTask(task.Task):
|
||||
|
||||
|
||||
class ReadVerifyTrackTask(task.MultiSeparateTask):
|
||||
"""
|
||||
I am a task that reads and verifies a track using cdparanoia.
|
||||
"""I am a task that reads and verifies a track using cdparanoia.
|
||||
|
||||
I also encode the track.
|
||||
|
||||
The path where the file is stored can be changed if necessary, for
|
||||
example if the file name is too long.
|
||||
|
||||
@ivar path: the path where the file is to be stored.
|
||||
@ivar checksum: the checksum of the track; set if they match.
|
||||
@ivar testchecksum: the test checksum of the track.
|
||||
@ivar copychecksum: the copy checksum of the track.
|
||||
@ivar testspeed: the test speed of the track, as a multiple of
|
||||
track duration.
|
||||
@ivar copyspeed: the copy speed of the track, as a multiple of
|
||||
track duration.
|
||||
@ivar testduration: the test duration of the track, in seconds.
|
||||
@ivar copyduration: the copy duration of the track, in seconds.
|
||||
@ivar peak: the peak level of the track
|
||||
:cvar checksum: the checksum of the track; set if they match.
|
||||
:vartype checksum:
|
||||
:cvar testchecksum: the test checksum of the track.
|
||||
:vartype testchecksum:
|
||||
:cvar copychecksum: the copy checksum of the track.
|
||||
:vartype copychecksum:
|
||||
:cvar peak: the peak level of the track
|
||||
:vartype peak:
|
||||
:cvar quality:
|
||||
:vartype quality:
|
||||
:cvar testspeed: the test speed of the track, as a multiple of
|
||||
track duration.
|
||||
:vartype testspeed:
|
||||
:cvar copyspeed: the copy speed of the track, as a multiple of
|
||||
track duration.
|
||||
:vartype copyspeed:
|
||||
:cvar testduration: the test duration of the track, in seconds.
|
||||
:vartype testduration:
|
||||
:cvar copyduration: the copy duration of the track, in seconds.
|
||||
:vartype copyduration:
|
||||
:ivar path: the path where the file is to be stored.
|
||||
:vartype path: str
|
||||
:ivar table: table of contents of CD.
|
||||
:vartype table: L{table.Table}
|
||||
:ivar stop: last frame to rip (inclusive).
|
||||
:vartype stop: int
|
||||
:ivar offset: read offset, in samples.
|
||||
:vartype offset: int
|
||||
:ivar device: the device to rip from.
|
||||
:vartype device: str
|
||||
:ivar taglist: a dict of tags.
|
||||
:vartype taglist: dict
|
||||
"""
|
||||
|
||||
checksum = None
|
||||
@@ -433,22 +469,6 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
|
||||
|
||||
def __init__(self, path, table, start, stop, overread, offset=0,
|
||||
device=None, taglist=None, what="track"):
|
||||
"""
|
||||
@param path: where to store the ripped track
|
||||
@type path: str
|
||||
@param table: table of contents of CD
|
||||
@type table: L{table.Table}
|
||||
@param start: first frame to rip
|
||||
@type start: int
|
||||
@param stop: last frame to rip (inclusive)
|
||||
@type stop: int
|
||||
@param offset: read offset, in samples
|
||||
@type offset: int
|
||||
@param device: the device to rip from
|
||||
@type device: str
|
||||
@param taglist: a dict of tags
|
||||
@type taglist: dict
|
||||
"""
|
||||
task.MultiSeparateTask.__init__(self)
|
||||
|
||||
logger.debug('Creating read and verify task on %r', path)
|
||||
@@ -478,7 +498,7 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
|
||||
try:
|
||||
tmpoutpath = path + u'.part'
|
||||
open(tmpoutpath, 'wb').close()
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
if errno.ENAMETOOLONG != e.errno:
|
||||
raise
|
||||
path = common.shrinkPath(path)
|
||||
@@ -540,7 +560,7 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
|
||||
try:
|
||||
logger.debug('Moving to final path %r', self.path)
|
||||
os.rename(self._tmppath, self.path)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.debug('Exception while moving to final '
|
||||
'path %r: %r', self.path, str(e))
|
||||
self.exception = e
|
||||
@@ -548,7 +568,7 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
|
||||
os.unlink(self._tmppath)
|
||||
else:
|
||||
logger.debug('stop: exception %r', self.exception)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
print 'WARNING: unhandled exception %r' % (e, )
|
||||
|
||||
task.MultiSeparateTask.stop(self)
|
||||
|
||||
Reference in New Issue
Block a user