Initial pass on python 3 port

Given the imminent end-of-life for Python 2, I didn't bother making the
codebase compatible with both.

Signed-off-by: Drew DeVault <sir@cmpwn.com>
This commit is contained in:
Drew DeVault
2019-08-10 11:45:17 +09:00
committed by JoeLametta
parent f740a0ef0d
commit 64dd9d843a
33 changed files with 274 additions and 317 deletions

View File

@@ -2,4 +2,4 @@ import accuraterip
def accuraterip_checksum(f, track_number, total_tracks):
return accuraterip.compute(f.encode('utf-8'), track_number, total_tracks)
return accuraterip.compute(f, track_number, total_tracks)

View File

@@ -220,7 +220,7 @@ class ReadTrackTask(task.Task):
Read the given track.
:param path: where to store the ripped track
:type path: unicode
:type path: str
:param table: table of contents of CD
:type table: table.Table
:param start: first frame to rip
@@ -236,7 +236,7 @@ class ReadTrackTask(task.Task):
:param what: a string representing what's being read; e.g. Track
:type what: str
"""
assert isinstance(path, unicode), "%r is not unicode" % path
assert isinstance(path, str), "%r is not str" % path
self.path = path
self._table = table
@@ -314,7 +314,7 @@ class ReadTrackTask(task.Task):
self.schedule(0.01, self._read, runner)
return
self._buffer += ret
self._buffer += ret.decode()
# parse buffer into lines if possible, and parse them
if "\n" in self._buffer:
@@ -452,7 +452,6 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
logger.debug('read and verify with taglist %r', taglist)
# FIXME: choose a dir on the same disk/dir as the final path
fd, tmppath = tempfile.mkstemp(suffix='.whipper.wav')
tmppath = unicode(tmppath)
os.fchmod(fd, 0644)
os.close(fd)
self._tmpwavpath = tmppath
@@ -472,13 +471,13 @@ class ReadVerifyTrackTask(task.MultiSeparateTask):
# encode to the final path + '.part'
try:
tmpoutpath = path + u'.part'
tmpoutpath = path + '.part'
open(tmpoutpath, 'wb').close()
except IOError as e:
if errno.ENAMETOOLONG != e.errno:
raise
path = common.truncate_filename(common.shrinkPath(path))
tmpoutpath = common.truncate_filename(path + u'.part')
tmpoutpath = common.truncate_filename(path + '.part')
open(tmpoutpath, 'wb').close()
self._tmppath = tmpoutpath
self.path = path
@@ -597,7 +596,7 @@ class AnalyzeTask(ctask.PopenTask):
def done(self):
if self.cwd:
shutil.rmtree(self.cwd)
output = "".join(self._output)
output = "".join(o.decode() for o in self._output)
m = _OK_RE.search(output)
self.defeatsCache = bool(m)

View File

@@ -84,7 +84,7 @@ class ReadTOCTask(task.Task):
self._parser = ProgressParser()
self.fd, self.tocfile = tempfile.mkstemp(
suffix=u'.cdrdao.read-toc.whipper.task')
suffix='.cdrdao.read-toc.whipper.task')
def start(self, runner):
task.Task.start(self, runner)
@@ -112,7 +112,7 @@ class ReadTOCTask(task.Task):
return
self.schedule(0.01, self._read, runner)
return
self._buffer += ret
self._buffer += ret.decode()
# parse buffer into lines if possible, and parse them
if "\n" in self._buffer:
@@ -168,7 +168,7 @@ def DetectCdr(device):
cmd = [CDRDAO, 'disk-info', '-v1', '--device', device]
logger.debug("executing %r", cmd)
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
return 'CD-R medium : n/a' not in p.stdout.read()
return 'CD-R medium : n/a' not in p.stdout.read().decode()
def version():

View File

@@ -21,11 +21,11 @@ class AudioLengthTask(ctask.PopenTask):
def __init__(self, path):
"""
:type path: unicode
:type path: str
"""
assert isinstance(path, unicode), "%r is not unicode" % path
assert isinstance(path, str), "%r is not str" % path
self.logName = os.path.basename(path).encode('utf-8')
self.logName = os.path.basename(path)
self.command = [SOXI, '-s', path]
@@ -47,4 +47,4 @@ class AudioLengthTask(ctask.PopenTask):
def done(self):
if self._error:
logger.warning("soxi reported on stderr: %s", "".join(self._error))
self.length = int("".join(self._output))
self.length = int("".join(o.decode() for o in self._output))