* introduce logcommand.Lager, Whipper(); use argparse for whipper image commands, stub logging * update Lager docstring to mention config.Config() * make incorrect subcommand and --version work on toplevel command * migrate accurip show, expand Lager, do not attempt to return from Lager.__init__. * migrate offset find, add Lager.error * correct offset find drive symlink handling * migrate drive * change Lager.__init__(prog) to arg from kwarg * but actually * remove Whipper.usage * add and use Lager.device_option() context manager * help I married an axe murderer * use unified options namespace for entire command tree * migrate whipper cd without comprehensive config loading * switch to logging module - use logging instead of flog for non-extern modules - use WHIPPER_DEBUG and WHIPPER_LOGFILE env variables * convert self.log calls to logger.debug * convert self.error calls to logger.error * remove log.Loggable, use logger not logging * Logging conversion continues - Convert log.* calls to logger.* - Remove morituri.common.log imports * remove morituri.common.log from tests * remove extern/flog, bare minimum Debug conversion * update README for logging changes * update soxi to use logging * refactor Lager for more declarative subcommands * Refactor Lager.device_option: - inline into __init__ - throw IOError instead of Exception for missing drives - remove CommandError checking in rip/main * rename rip to whipper in rip.main * convert rip.debug commands * Rename logcommand.Lager to command.BaseCommand - remove command.CommandError occurrences - remove python-command external module * remove submodules from README, update rclog formatter * update minor ambiguity in readme for command invocation * update version number to match setup.py * remove gitmodules * update version number in tests as well (boo) * convert logger.error to logger.critical * Change morituri.rip to morituri.command - mv common.command to command.basecommand - move TEMPLATES used only by rip.cd out of rip.common - update entry point for command to command.main * update basecommand documentation * go pyflaking: import fixing * replace self.stdout with sys.stdout * remove BaseCommand.config, alphabetise imports * convert self.stdXXX leftovers * convert last getRootCommand to config.Config * convert last getExceptionMessage's to str * change musicbrainz useragent to whipper
88 lines
2.3 KiB
Python
88 lines
2.3 KiB
Python
# -*- Mode: Python -*-
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
import re
|
|
import os
|
|
import sys
|
|
|
|
# twisted's unittests have skip support, standard unittest don't
|
|
from twisted.trial import unittest
|
|
|
|
from morituri.configure import configure
|
|
|
|
# lifted from flumotion
|
|
|
|
|
|
def _diff(old, new, desc):
|
|
import difflib
|
|
lines = difflib.unified_diff(old, new)
|
|
lines = list(lines)
|
|
if not lines:
|
|
return
|
|
output = ''
|
|
for line in lines:
|
|
output += '%s: %s\n' % (desc, line[:-1])
|
|
|
|
raise AssertionError(
|
|
("\nError while comparing strings:\n"
|
|
"%s") % (output.encode('utf-8'), ))
|
|
|
|
|
|
def diffStrings(orig, new, desc='input'):
|
|
|
|
assert type(orig) == type(new), 'type %s and %s are different' % (
|
|
type(orig), type(new))
|
|
|
|
def _tolines(s):
|
|
return [line + '\n' for line in s.split('\n')]
|
|
|
|
return _diff(_tolines(orig),
|
|
_tolines(new),
|
|
desc=desc)
|
|
|
|
|
|
class TestCase(unittest.TestCase):
|
|
# unittest.TestCase.failUnlessRaises does not return the exception,
|
|
# and we'd like to check for the actual exception under TaskException,
|
|
# so override the way twisted.trial.unittest does, without failure
|
|
|
|
def failUnlessRaises(self, exception, f, *args, **kwargs):
|
|
try:
|
|
result = f(*args, **kwargs)
|
|
except exception, inst:
|
|
return inst
|
|
except exception, e:
|
|
raise Exception('%s raised instead of %s:\n %s' %
|
|
(sys.exec_info()[0], exception.__name__, str(e))
|
|
)
|
|
else:
|
|
raise Exception('%s not raised (%r returned)' %
|
|
(exception.__name__, result)
|
|
)
|
|
|
|
assertRaises = failUnlessRaises
|
|
|
|
def readCue(self, name):
|
|
"""
|
|
Read a .cue file, and replace the version comment with the current
|
|
version so we can use it in comparisons.
|
|
"""
|
|
ret = open(os.path.join(os.path.dirname(__file__), name)).read(
|
|
).decode('utf-8')
|
|
ret = re.sub(
|
|
'REM COMMENT "Morituri.*',
|
|
'REM COMMENT "Morituri %s"' % (configure.version),
|
|
ret, re.MULTILINE)
|
|
|
|
return ret
|
|
|
|
class UnicodeTestMixin:
|
|
# A helper mixin to skip tests if we're not in a UTF-8 locale
|
|
|
|
try:
|
|
os.stat(u'morituri.test.B\xeate Noire.empty')
|
|
except UnicodeEncodeError:
|
|
skip = 'No UTF-8 locale'
|
|
except OSError:
|
|
pass
|