pep8 fixes

This commit is contained in:
Thomas Vander Stichele
2012-11-29 19:54:46 +00:00
parent f0cb567a0d
commit cba7dbe41a
14 changed files with 68 additions and 32 deletions

View File

@@ -150,7 +150,8 @@ class ChecksumTask(log.Loggable, gstreamer.GstPipelineTask):
self.debug('stopped')
if not self._last:
# see http://bugzilla.gnome.org/show_bug.cgi?id=578612
self.debug('not a single buffer gotten, setting exception EmptyError')
self.debug(
'not a single buffer gotten, setting exception EmptyError')
self.setException(common.EmptyError('not a single buffer gotten'))
else:
self._checksum = self._checksum % 2 ** 32

View File

@@ -300,6 +300,7 @@ def shrinkPath(path):
path = os.path.join(*parts)
return path
def getRealPath(refPath, filePath):
"""
Translate a .cue or .toc's FILE to an existing path.
@@ -339,6 +340,7 @@ def getRealPath(refPath, filePath):
raise KeyError("Cannot find file for %r" % filePath)
def getRelativePath(targetPath, collectionPath):
"""
Get a relative path from the directory of collectionPath to

View File

@@ -90,7 +90,8 @@ def _getMetadata(release):
metadata.release = release.getEarliestReleaseDate()
metadata.mbid = urlparse.urlparse(release.id)[2].split("/")[-1]
metadata.mbidArtist = urlparse.urlparse(release.artist.id)[2].split("/")[-1]
metadata.mbidArtist = urlparse.urlparse(
release.artist.id)[2].split("/")[-1]
metadata.url = release.getId()
tainted = False
@@ -131,7 +132,8 @@ def _getMetadata(release):
return metadata
# see http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/ripper.py
# see http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/
# ripper.py
def musicbrainz(discid):

View File

@@ -204,7 +204,8 @@ def _getMetadata(release, discid):
return metadata
# see http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/ripper.py
# see http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/
# ripper.py
def musicbrainz(discid, record=False):

View File

@@ -198,7 +198,8 @@ class Program(log.Loggable):
if i > 0:
try:
v['a'] = filterForPath(self.metadata.tracks[i - 1].artist)
v['s'] = filterForPath(self.metadata.tracks[i - 1].sortName)
v['s'] = filterForPath(
self.metadata.tracks[i - 1].sortName)
v['n'] = filterForPath(self.metadata.tracks[i - 1].title)
except IndexError, e:
print 'ERROR: no track %d found, %r' % (i, e)
@@ -359,7 +360,8 @@ class Program(log.Loggable):
ret = gst.TagList()
# gst-python 0.10.15.1 does not handle unicode -> utf8 string conversion
# gst-python 0.10.15.1 does not handle unicode -> utf8 string
# conversion
# see http://bugzilla.gnome.org/show_bug.cgi?id=584445
if self.metadata and self.metadata.various:
ret["album-artist"] = albumArtist.encode('utf-8')
@@ -380,8 +382,8 @@ class Program(log.Loggable):
# 0.10.15.1
# FIXME: The dates are strings and must have the format 'YYYY',
# 'YYYY-MM' or 'YYYY-MM-DD'.
# GstDate expects a full date, so default to Jan and 1st if MM and DD
# are missing
# GstDate expects a full date, so default to
# Jan and 1st if MM and DD are missing
date = self.metadata.release
if date:
log.debug('metadata',

View File

@@ -6,6 +6,7 @@ import os
__thisdir = os.path.dirname(os.path.abspath(__file__))
def get():
return {
'isinstalled': False,

View File

@@ -110,7 +110,7 @@ class TocFile(object, log.Loggable):
trackNumber = 0
indexNumber = 0
absoluteOffset = 0 # running absolute offset of where each track starts
relativeOffset = 0 # running relative offset, relative to counter source
relativeOffset = 0 # running relative offset, relative to counter src
currentLength = 0 # accrued during TRACK record parsing, current track
totalLength = 0 # accrued during TRACK record parsing, total disc
pregapLength = 0 # length of the pre-gap, current track
@@ -163,7 +163,8 @@ class TocFile(object, log.Loggable):
# FIXME: why not set absolute offsets too ?
currentTrack.index(1, path=currentFile.path,
absolute=absoluteOffset + pregapLength,
relative=relativeOffset + pregapLength, counter=counter)
relative=relativeOffset + pregapLength,
counter=counter)
self.debug('track %d, added index %r',
currentTrack.number, currentTrack.getIndex(1))
@@ -223,7 +224,8 @@ class TocFile(object, log.Loggable):
if not currentFile or filePath != currentFile.path:
counter += 1
relativeOffset = 0
self.debug('track %d, switched to new FILE, increased counter to %d',
self.debug('track %d, switched to new FILE, '
'increased counter to %d',
trackNumber, counter)
currentFile = File(filePath, start, length)
#absoluteOffset += common.msfToFrames(start)
@@ -240,7 +242,8 @@ class TocFile(object, log.Loggable):
if not currentFile or filePath != currentFile.path:
counter += 1
relativeOffset = 0
self.debug('track %d, switched to new FILE, increased counter to %d',
self.debug('track %d, switched to new FILE, '
'increased counter to %d',
trackNumber, counter)
# FIXME: assume that a MODE2_FORM_MIX track always starts at 0
currentFile = File(filePath, 0, length)

View File

@@ -525,7 +525,8 @@ class ReadVerifyTrackTask(log.Loggable, task.MultiSeparateTask):
self.path = common.shrinkPath(self.path)
shutil.move(self._tmppath, self.path)
except Exception, e:
self.debug('Exception while moving to final path %r: %r',
self.debug('Exception while moving to final path %r: '
'%r',
self.path, log.getExceptionMessage(e))
self.exception = e
else:
@@ -537,7 +538,8 @@ class ReadVerifyTrackTask(log.Loggable, task.MultiSeparateTask):
task.MultiSeparateTask.stop(self)
_VERSION_RE = re.compile("^cdparanoia (?P<version>.+) release (?P<release>.+) \(.*\)")
_VERSION_RE = re.compile(
"^cdparanoia (?P<version>.+) release (?P<release>.+) \(.*\)")
def getCdparanoiaVersion():

View File

@@ -26,6 +26,7 @@ from morituri.common import common
from morituri.configure import configure
from morituri.result import result
class MorituriLogger(result.Logger):
def log(self, ripResult, epoch=time.time()):

View File

@@ -141,6 +141,7 @@ class Logger(object):
# A setuptools-like entry point
class EntryPoint(object):
name = 'morituri'

View File

@@ -75,8 +75,7 @@ Log files will log the path to tracks relative to this directory.
default='morituri',
help="logger to use "
"(default '%default', choose from '" +
"', '".join(loggers) + "')"
)
"', '".join(loggers) + "')")
# FIXME: get from config
default = 0
self.parser.add_option('-o', '--offset',
@@ -86,8 +85,7 @@ Log files will log the path to tracks relative to this directory.
self.parser.add_option('-O', '--output-directory',
action="store", dest="output_directory",
help="output directory "
"(defaults to absolute path to current directory) "
)
"(defaults to absolute path to current directory) ")
# FIXME: have a cache of these pickles somewhere
self.parser.add_option('-T', '--toc-pickle',
action="store", dest="toc_pickle",
@@ -150,10 +148,10 @@ Log files will log the path to tracks relative to this directory.
from pkg_resources import parse_version as V
# we've built a cdrdao 1.2.3rc2 modified package with the patch
if V(version) < V('1.2.3rc2p1'):
self.stdout.write('''
Warning: cdrdao older than 1.2.3 has a pre-gap length bug.
See http://sourceforge.net/tracker/?func=detail&aid=604751&group_id=2171&atid=102171
''')
self.stdout.write('Warning: cdrdao older than 1.2.3 has a '
'pre-gap length bug.\n'
'See http://sourceforge.net/tracker/?func=detail'
'&aid=604751&group_id=2171&atid=102171\n')
ptoc.persist(t.table)
ittoc = ptoc.object
assert ittoc.hasTOC()

View File

@@ -11,18 +11,28 @@ from morituri.test import common as tcommon
class ShrinkTestCase(tcommon.TestCase):
def testSufjan(self):
path = u'morituri/Sufjan Stevens - Illinois/02. Sufjan Stevens - The Black Hawk War, or, How to Demolish an Entire Civilization and Still Feel Good About Yourself in the Morning, or, We Apologize for the Inconvenience but You\'re Going to Have to Leave Now, or, "I Have Fought the Big Knives and Will Continue to Fight Them Until They Are Off Our Lands!".flac'
path = (u'morituri/Sufjan Stevens - Illinois/02. Sufjan Stevens - '
'The Black Hawk War, or, How to Demolish an Entire '
'Civilization and Still Feel Good About Yourself in the '
'Morning, or, We Apologize for the Inconvenience but '
'You\'re Going to Have to Leave Now, or, "I Have Fought '
'the Big Knives and Will Continue to Fight Them Until They '
'Are Off Our Lands!".flac')
shorter = common.shrinkPath(path)
self.failUnless(os.path.splitext(path)[0].startswith(
os.path.splitext(shorter)[0]))
self.failIfEquals(path, shorter)
class FramesTestCase(tcommon.TestCase):
def testFrames(self):
self.assertEquals(common.framesToHMSF(123456), '00:27:26.06')
class FormatTimeTestCase(tcommon.TestCase):
def testFormatTime(self):
self.assertEquals(common.formatTime(7202), '02:00:02.000')

View File

@@ -9,7 +9,9 @@ from morituri.test import common as tcommon
def h(i):
return "0x%08x" % i
class TrackTestCase(tcommon.TestCase):
def testRepr(self):
track = table.Track(1)
self.assertEquals(repr(track), "<Track 01>")
@@ -17,6 +19,7 @@ class TrackTestCase(tcommon.TestCase):
track.index(1, 100)
self.failUnless(repr(track.indexes[1]).startswith('<Index 01 '))
class LadyhawkeTestCase(tcommon.TestCase):
# Ladyhawke - Ladyhawke - 0602517818866
# contains 12 audio tracks and one data track
@@ -50,7 +53,9 @@ class LadyhawkeTestCase(tcommon.TestCase):
def testMusicBrainz(self):
# output from mb-submit-disc:
# http://mm.musicbrainz.org/bare/cdlookup.html?toc=1+12+195856+150+15687+31841+51016+66616+81352+99559+116070+133243+149997+161710+177832&tracks=12&id=KnpGsLhvH.lPrNc1PBL21lb9Bg4-
# http://mm.musicbrainz.org/bare/cdlookup.html?toc=1+12+195856+150+
# 15687+31841+51016+66616+81352+99559+116070+133243+149997+161710+
# 177832&tracks=12&id=KnpGsLhvH.lPrNc1PBL21lb9Bg4-
# however, not (yet) in musicbrainz database
self.assertEquals(self.table.getMusicBrainzDiscId(),
@@ -60,7 +65,8 @@ class LadyhawkeTestCase(tcommon.TestCase):
self.assertEquals(self.table.getAccurateRipIds(), (
"0013bd5a", "00b8d489"))
self.assertEquals(self.table.getAccurateRipURL(),
"http://www.accuraterip.com/accuraterip/a/5/d/dBAR-012-0013bd5a-00b8d489-c60af50d.bin")
"http://www.accuraterip.com/accuraterip/a/5/d/"
"dBAR-012-0013bd5a-00b8d489-c60af50d.bin")
def testDuration(self):
self.assertEquals(self.table.duration(), 2761413)
@@ -91,6 +97,7 @@ class MusicBrainzTestCase(tcommon.TestCase):
self.assertEquals(self.table.getMusicBrainzDiscId(),
'49HHV7Eb8UKF3aQiNmu1GR8vKTY-')
class PregapTestCase(tcommon.TestCase):
def setUp(self):
@@ -108,5 +115,3 @@ class PregapTestCase(tcommon.TestCase):
def testPreGap(self):
self.assertEquals(self.table.tracks[0].getPregap(), 0)
self.assertEquals(self.table.tracks[1].getPregap(), 200)

View File

@@ -93,7 +93,6 @@ class CureTestCase(common.TestCase):
'http://www.accuraterip.com/accuraterip/'
'3/c/4/dBAR-013-0019d4c3-00fe8924-b90c650d.bin')
def testGetRealPath(self):
self.assertRaises(KeyError, self.toc.getRealPath, u'track01.wav')
(fd, path) = tempfile.mkstemp(suffix=u'.morituri.test.wav')
@@ -211,7 +210,10 @@ class LadyhawkeTestCase(common.TestCase):
self.assertEquals(self.toc.table.getMusicBrainzDiscId(),
"KnpGsLhvH.lPrNc1PBL21lb9Bg4-")
self.assertEquals(self.toc.table.getMusicBrainzSubmitURL(),
"http://mm.musicbrainz.org/bare/cdlookup.html?toc=1+12+195856+150+15687+31841+51016+66616+81352+99559+116070+133243+149997+161710+177832&tracks=12&id=KnpGsLhvH.lPrNc1PBL21lb9Bg4-")
"http://mm.musicbrainz.org/bare/cdlookup.html?toc="
"1+12+195856+150+15687+31841+51016+66616+81352+99559+"
"116070+133243+149997+161710+177832&"
"tracks=12&id=KnpGsLhvH.lPrNc1PBL21lb9Bg4-")
# FIXME: I don't trust this toc, but I can't find the CD anymore
@@ -227,6 +229,7 @@ class LadyhawkeTestCase(common.TestCase):
lines = data.split("\n")
self.assertEquals(lines[0], "REM DISCID C60AF50D")
class CapitalMergeTestCase(common.TestCase):
def setUp(self):
@@ -249,15 +252,19 @@ class CapitalMergeTestCase(common.TestCase):
self.table.absolutize()
self.assertEquals(self.table.getCDDBDiscId(), 'b910140c')
# output from cd-discid:
# b910140c 12 24320 44855 64090 77885 88095 104020 118245 129255 141765 164487 181780 209250 4440
# b910140c 12 24320 44855 64090 77885 88095 104020 118245 129255 141765
# 164487 181780 209250 4440
def testMusicBrainz(self):
# URL to submit: http://mm.musicbrainz.org/bare/cdlookup.html?toc=1+11+197850+24320+44855+64090+77885+88095+104020+118245+129255+141765+164487+181780&tracks=11&id=MAj3xXf6QMy7G.BIFOyHyq4MySE-
# URL to submit: http://mm.musicbrainz.org/bare/cdlookup.html?toc=1+11+
# 197850+24320+44855+64090+77885+88095+104020+118245+129255+141765+
# 164487+181780&tracks=11&id=MAj3xXf6QMy7G.BIFOyHyq4MySE-
self.assertEquals(self.table.getMusicBrainzDiscId(),
"MAj3xXf6QMy7G.BIFOyHyq4MySE-")
def testDuration(self):
# this matches track 11 end sector - track 1 start sector on musicbrainz
# this matches track 11 end sector - track 1 start sector on
# musicbrainz
# compare to 3rd and 4th value in URL above
self.assertEquals(self.table.getFrameLength(), 173530)
self.assertEquals(self.table.duration(), 2313733)