Address errors, improvements, formatting
- Removed unused code not portable due to buffer() use - raw_input() does not exist in Python 3 - Fixed octal constant syntax for Python 3 - Fixed TypeError - Replace if not exists: makedirs(path) with single call: using makedirs(path, exist_ok=True) - Class inherits from object, can be safely removed from bases in python3: pylint's useless-object-inheritance (W0235) check Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
|
||||
import requests
|
||||
import struct
|
||||
from errno import EEXIST
|
||||
from os import makedirs
|
||||
from os.path import dirname, exists, join
|
||||
|
||||
@@ -40,7 +39,7 @@ class EntryNotFound(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class _AccurateRipResponse(object):
|
||||
class _AccurateRipResponse:
|
||||
"""
|
||||
An AccurateRip response contains a collection of metadata identifying a
|
||||
particular digital audio compact disc.
|
||||
@@ -143,13 +142,11 @@ def _download_entry(path):
|
||||
|
||||
def _save_entry(raw_entry, path):
|
||||
logger.debug('saving AccurateRip entry to %s', path)
|
||||
# XXX: os.makedirs(exist_ok=True) in py3
|
||||
try:
|
||||
makedirs(dirname(path))
|
||||
makedirs(dirname(path), exist_ok=True)
|
||||
except OSError as e:
|
||||
if e.errno != EEXIST:
|
||||
logger.error('could not save entry to %s: %s', path, e)
|
||||
return
|
||||
logger.error('could not save entry to %s: %s', path, e)
|
||||
return
|
||||
open(path, 'wb').write(raw_entry)
|
||||
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ def validate_template(template, kind):
|
||||
'variable(s): {}'.format(', '.join(matches)))
|
||||
|
||||
|
||||
class VersionGetter(object):
|
||||
class VersionGetter:
|
||||
"""
|
||||
I get the version of a program by looking for it in command output
|
||||
according to a regexp.
|
||||
|
||||
@@ -19,14 +19,13 @@
|
||||
# along with whipper. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from os import getenv, makedirs
|
||||
from os.path import join, expanduser, exists
|
||||
from os.path import join, expanduser
|
||||
|
||||
|
||||
def config_path():
|
||||
path = join(getenv('XDG_CONFIG_HOME') or join(expanduser('~'), '.config'),
|
||||
'whipper')
|
||||
if not exists(path):
|
||||
makedirs(path)
|
||||
makedirs(path, exist_ok=True)
|
||||
return join(path, 'whipper.conf')
|
||||
|
||||
|
||||
@@ -35,8 +34,7 @@ def cache_path(name=None):
|
||||
'whipper')
|
||||
if name:
|
||||
path = join(path, name)
|
||||
if not exists(path):
|
||||
makedirs(path)
|
||||
makedirs(path, exist_ok=True)
|
||||
return path
|
||||
|
||||
|
||||
@@ -46,6 +44,5 @@ def data_path(name=None):
|
||||
'whipper')
|
||||
if name:
|
||||
path = join(path, name)
|
||||
if not exists(path):
|
||||
makedirs(path)
|
||||
makedirs(path, exist_ok=True)
|
||||
return path
|
||||
|
||||
@@ -45,7 +45,7 @@ class NotFoundException(MusicBrainzException):
|
||||
return "Disc not found in MusicBrainz"
|
||||
|
||||
|
||||
class TrackMetadata(object):
|
||||
class TrackMetadata:
|
||||
artist = None
|
||||
title = None
|
||||
duration = None # in ms
|
||||
@@ -56,7 +56,7 @@ class TrackMetadata(object):
|
||||
mbidWorks = []
|
||||
|
||||
|
||||
class DiscMetadata(object):
|
||||
class DiscMetadata:
|
||||
"""
|
||||
:param artist: artist(s) name
|
||||
:param sortName: release artist sort name
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
import re
|
||||
|
||||
|
||||
class PathFilter(object):
|
||||
class PathFilter:
|
||||
"""
|
||||
I filter path components for safe storage on file systems.
|
||||
"""
|
||||
|
||||
@@ -333,7 +333,7 @@ class Program:
|
||||
|
||||
if prompt:
|
||||
guess = (deltas[lowest])[0].mbid
|
||||
release = raw_input(
|
||||
release = input(
|
||||
"\nPlease select a release [%s]: " % guess)
|
||||
|
||||
if not release:
|
||||
@@ -505,8 +505,7 @@ class Program:
|
||||
stop = self.result.table.getTrackEnd(trackResult.number)
|
||||
|
||||
dirname = os.path.dirname(trackResult.filename)
|
||||
if not os.path.exists(dirname):
|
||||
os.makedirs(dirname)
|
||||
os.makedirs(dirname, exist_ok=True)
|
||||
|
||||
if not what:
|
||||
what = 'track %d' % (trackResult.number, )
|
||||
|
||||
@@ -24,7 +24,7 @@ import tempfile
|
||||
"""Rename files on file system and inside metafiles in a resumable way."""
|
||||
|
||||
|
||||
class Operator(object):
|
||||
class Operator:
|
||||
|
||||
def __init__(self, statePath, key):
|
||||
self._todo = []
|
||||
@@ -116,7 +116,7 @@ class FileRenamer(Operator):
|
||||
"""
|
||||
|
||||
|
||||
class Operation(object):
|
||||
class Operation:
|
||||
|
||||
def verify(self):
|
||||
"""
|
||||
|
||||
24
whipper/extern/asyncsub.py
vendored
24
whipper/extern/asyncsub.py
vendored
@@ -150,27 +150,3 @@ def recv_some(p, t=.1, e=1, tr=5, stderr=0):
|
||||
else:
|
||||
time.sleep(max((x - time.time()) / tr, 0))
|
||||
return ''.join(x.decode() for x in y).encode()
|
||||
|
||||
|
||||
def send_all(p, data):
|
||||
while data:
|
||||
sent = p.send(data)
|
||||
if sent is None:
|
||||
raise Exception(message)
|
||||
data = buffer(data, sent)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.platform == 'win32':
|
||||
shell, commands, tail = ('cmd', ('dir /w', 'echo HELLO WORLD'), '\r\n')
|
||||
else:
|
||||
shell, commands, tail = ('sh', ('ls', 'echo HELLO WORLD'), '\n')
|
||||
|
||||
a = Popen(shell, stdin=PIPE, stdout=PIPE)
|
||||
print(recv_some(a))
|
||||
for cmd in commands:
|
||||
send_all(a, cmd + tail)
|
||||
print(recv_some(a))
|
||||
send_all(a, 'exit' + tail)
|
||||
print(recv_some(a, e=0))
|
||||
a.wait()
|
||||
|
||||
5
whipper/extern/freedb.py
vendored
5
whipper/extern/freedb.py
vendored
@@ -17,16 +17,13 @@
|
||||
# USA
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def digit_sum(i):
|
||||
"""returns the sum of all digits for the given integer"""
|
||||
|
||||
return sum(map(int, str(i)))
|
||||
|
||||
|
||||
class DiscID(object):
|
||||
class DiscID:
|
||||
def __init__(self, offsets, total_length, track_count, playable_length):
|
||||
"""offsets is a list of track offsets, in CD frames
|
||||
total_length is the total length of the disc, in seconds
|
||||
|
||||
4
whipper/extern/task/task.py
vendored
4
whipper/extern/task/task.py
vendored
@@ -68,7 +68,7 @@ def _getExceptionMessage(exception, frame=-1, filename=None):
|
||||
% locals()
|
||||
|
||||
|
||||
class LogStub(object):
|
||||
class LogStub:
|
||||
"""
|
||||
I am a stub for a log interface.
|
||||
"""
|
||||
@@ -243,7 +243,7 @@ class Task(LogStub):
|
||||
|
||||
|
||||
# FIXME: should this become a real interface, like in zope ?
|
||||
class ITaskListener(object):
|
||||
class ITaskListener:
|
||||
"""
|
||||
I am an interface for objects listening to tasks.
|
||||
"""
|
||||
|
||||
@@ -58,7 +58,7 @@ _INDEX_RE = re.compile(r"""
|
||||
""", re.VERBOSE)
|
||||
|
||||
|
||||
class CueFile(object):
|
||||
class CueFile:
|
||||
"""
|
||||
I represent a .cue file as an object.
|
||||
|
||||
@@ -138,8 +138,8 @@ class CueFile(object):
|
||||
seconds = int(m.expand('\\3'))
|
||||
frames = int(m.expand('\\4'))
|
||||
frameOffset = int(frames
|
||||
+ seconds * common.FRAMES_PER_SECOND
|
||||
+ minutes * common.FRAMES_PER_SECOND * 60)
|
||||
+ seconds * common.FRAMES_PER_SECOND
|
||||
+ minutes * common.FRAMES_PER_SECOND * 60)
|
||||
|
||||
logger.debug('found index %d of track %r in %r:%d',
|
||||
indexNumber, currentTrack, currentFile.path,
|
||||
|
||||
@@ -34,7 +34,7 @@ import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Image(object):
|
||||
class Image:
|
||||
"""
|
||||
:ivar table: The Table of Contents for this image.
|
||||
:vartype table: table.Table
|
||||
|
||||
@@ -157,7 +157,7 @@ class Index:
|
||||
self.number, self.absolute, self.path, self.relative, self.counter)
|
||||
|
||||
|
||||
class Table(object):
|
||||
class Table:
|
||||
"""
|
||||
I represent a table of indexes on a CD.
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class Sources:
|
||||
return self._sources[-1][1]
|
||||
|
||||
|
||||
class TocFile(object):
|
||||
class TocFile:
|
||||
|
||||
def __init__(self, path):
|
||||
"""
|
||||
|
||||
@@ -452,7 +452,7 @@ 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')
|
||||
os.fchmod(fd, 0644)
|
||||
os.fchmod(fd, 0o644)
|
||||
os.close(fd)
|
||||
self._tmpwavpath = tmppath
|
||||
|
||||
|
||||
@@ -151,8 +151,7 @@ class ReadTOCTask(task.Task):
|
||||
t_comp = os.path.abspath(self.toc_path).split(os.sep)
|
||||
t_dirn = os.sep.join(t_comp[:-1])
|
||||
# If the output path doesn't exist, make it recursively
|
||||
if not os.path.isdir(t_dirn):
|
||||
os.makedirs(t_dirn)
|
||||
os.makedirs(t_dirn, exist_ok=True)
|
||||
t_dst = truncate_filename(
|
||||
os.path.join(t_dirn, t_comp[-1] + '.toc'))
|
||||
shutil.copy(self.tocfile, os.path.join(t_dirn, t_dst))
|
||||
|
||||
@@ -119,7 +119,7 @@ class RipResult:
|
||||
return None
|
||||
|
||||
|
||||
class Logger(object):
|
||||
class Logger:
|
||||
"""
|
||||
I log the result of a rip.
|
||||
"""
|
||||
@@ -140,7 +140,7 @@ class Logger(object):
|
||||
# A setuptools-like entry point
|
||||
|
||||
|
||||
class EntryPoint(object):
|
||||
class EntryPoint:
|
||||
name = 'whipper'
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -163,7 +163,8 @@ class LoggerTestCase(unittest.TestCase):
|
||||
Dumper=ruamel.yaml.RoundTripDumper
|
||||
)
|
||||
)
|
||||
log_body = "\n".join(actualLines[:-1]).encode()
|
||||
self.assertEqual(
|
||||
parsedLog['SHA-256 hash'],
|
||||
hashlib.sha256("\n".join(actualLines[:-1])).hexdigest().upper()
|
||||
hashlib.sha256(log_body).hexdigest().upper()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user