Skip to content

Commit

Permalink
Fix flake8 warnings
Browse files Browse the repository at this point in the history
I've also simplified the return statement in DetectCdr()

SQUASH: Fixed bug in previous commit

The DetectCdr() return statement simplification introduced an error (it reversed the logic).

Thanks to 'JTL' (who reported this bug on IRC).

Restore old task name
  • Loading branch information
JoeLametta committed Dec 13, 2018
1 parent ce5a8e7 commit be1e275
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
4 changes: 2 additions & 2 deletions whipper/common/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def getFastToc(self, runner, device):
'pre-gap length bug. '
'See http://sourceforge.net/tracker/?func=detail&aid=604751&group_id=2171&atid=102171') # noqa: E501

t = cdrdao.ReadTOC_Task(device)
t = cdrdao.ReadTOCTask(device)
runner.run(t)
toc = t.toc.table

Expand All @@ -114,7 +114,7 @@ def getTable(self, runner, cddbdiscid, mbdiscid, device, offset,
itable = None
tdict = {}

t = cdrdao.ReadTOC_Task(device)
t = cdrdao.ReadTOCTask(device)
t.description = "Reading table"
t.toc_path = toc_path
runner.run(t)
Expand Down
64 changes: 27 additions & 37 deletions whipper/program/cdrdao.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import sys
import os
import re
import shutil
import tempfile
import subprocess
import time
from subprocess import Popen, PIPE

from whipper.common.common import truncate_filename
Expand Down Expand Up @@ -47,24 +45,26 @@ def parse(self, line):

track_s = _TRACK_RE.search(line)
if track_s:
logger.debug("RE: Began reading track: %d"
% int(track_s.group('track')))
logger.debug("RE: Began reading track: %d" %
int(track_s.group('track')))
self.currentTrack = int(track_s.group('track'))

crc_s = _CRC_RE.search(line)
if crc_s:
sys.stdout.write("Track %d finished, found %d Q sub-channels with CRC errors\n" % (self.currentTrack, int(crc_s.group('channels'))) )
print("Track %d finished, found %d Q sub-channels "
"with CRC errors" % (self.currentTrack,
int(crc_s.group('channels'))))

self.oldline = line


class ReadTOC_Task(task.Task):

class ReadTOCTask(task.Task):
"""
Task that reads the TOC of the disc using cdrdao
"""
description = "Reading TOC"
toc = None

def __init__(self, device, fast_toc=False, toc_path=None):
"""
Read the TOC for 'device'.
Expand All @@ -74,32 +74,33 @@ def __init__(self, device, fast_toc=False, toc_path=None):
@type fast_toc: bool
@param toc_path: Where to save TOC if wanted.
@type toc_path: str
"""

self.device = device
self.fast_toc = fast_toc
self.toc_path = toc_path
self._buffer = "" # accumulate characters
self._parser = ProgressParser()

self.fd, self.tocfile = tempfile.mkstemp(suffix=u'.cdrdao.read-toc.whipper.task')

self.fd, self.tocfile = tempfile.mkstemp(
suffix=u'.cdrdao.read-toc.whipper.task')

def start(self, runner):
task.Task.start(self, runner)
os.close(self.fd)
os.unlink(self.tocfile)

cmd = [CDRDAO, 'read-toc'] + (['--fast-toc'] if self.fast_toc else []) + [
'--device', self.device, self.tocfile]
cmd = ([CDRDAO, 'read-toc'] + (['--fast-toc'] if self.fast_toc
else []) + ['--device', self.device, self.tocfile])

self._popen = asyncsub.Popen(cmd,
bufsize=1024,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True)

self.schedule(0.01, self._read, runner)

def _read(self, runner):
Expand All @@ -123,8 +124,10 @@ def _read(self, runner):
self._buffer = ""
for line in lines:
self._parser.parse(line)
if (self._parser.currentTrack is not 0 and self._parser.tracks is not 0):
progress = float('%d' % self._parser.currentTrack) / float(self._parser.tracks)
if (self._parser.currentTrack is not 0 and
self._parser.tracks is not 0):
progress = (float('%d' % self._parser.currentTrack) /
float(self._parser.tracks))
if progress < 1.0:
self.setProgress(progress)

Expand All @@ -139,9 +142,7 @@ def _poll(self, runner):

self._done()


def _done(self):
end_time = time.time()
self.setProgress(1.0)
self.toc = TocFile(self.tocfile)
self.toc.parse()
Expand All @@ -151,23 +152,23 @@ def _done(self):
# If the output path doesn't exist, make it recursively
if not os.path.isdir(t_dirn):
os.makedirs(t_dirn)
t_dst = truncate_filename(os.path.join(t_dirn, t_comp[-1] + '.toc'))
t_dst = truncate_filename(
os.path.join(t_dirn, t_comp[-1] + '.toc'))
shutil.copy(self.tocfile, os.path.join(t_dirn, t_dst))
os.unlink(self.tocfile)
self.stop()
return


def DetectCdr(device):
"""
Return whether cdrdao detects a CD-R for 'device'.
"""
cmd = [CDRDAO, 'disk-info', '-v1', '--device', device]
logger.debug("executing %r", cmd)
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
if 'CD-R medium : n/a' in p.stdout.read():
return False
else:
return True
return 'CD-R medium : n/a' not in p.stdout.read()


def version():
"""
Expand All @@ -187,20 +188,9 @@ def version():
return None
return m.group('version')


def getCDRDAOVersion():
"""
stopgap morituri-insanity compatibility layer
"""
return version()

def DetectCdr(device):
"""
Return whether cdrdao detects a CD-R for 'device'.
"""
cmd = [CDRDAO, 'disk-info', '-v1', '--device', device]
logger.debug("executing %r", cmd)
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
if 'CD-R medium : n/a' in p.stdout.read():
return False
else:
return True

0 comments on commit be1e275

Please sign in to comment.