* 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
76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
import os
|
|
import re
|
|
import tempfile
|
|
from subprocess import check_call, Popen, PIPE, CalledProcessError
|
|
|
|
from morituri.image.toc import TocFile
|
|
|
|
import logging
|
|
logger = logging.getLogger(__name__)
|
|
|
|
CDRDAO = 'cdrdao'
|
|
|
|
def read_toc(device, fast_toc=False):
|
|
"""
|
|
Return cdrdao-generated table of contents for 'device'.
|
|
"""
|
|
# cdrdao MUST be passed a non-existing filename as its last argument
|
|
# to write the TOC to; it does not support writing to stdout or
|
|
# overwriting an existing file, nor does linux seem to support
|
|
# locking a non-existant file. Thus, this race-condition introducing
|
|
# hack is carried from morituri to whipper and will be removed when
|
|
# cdrdao is fixed.
|
|
fd, tocfile = tempfile.mkstemp(suffix=u'.cdrdao.read-toc.whipper')
|
|
os.close(fd)
|
|
os.unlink(tocfile)
|
|
|
|
cmd = [CDRDAO, 'read-toc'] + (['--fast-toc'] if fast_toc else []) + [
|
|
'--device', device, tocfile]
|
|
# PIPE is the closest to >/dev/null we can get
|
|
try:
|
|
check_call(cmd, stdout=PIPE, stderr=PIPE)
|
|
except CalledProcessError, e:
|
|
logger.warning('cdrdao read-toc failed: return code is non-zero: ' +
|
|
str(e.returncode))
|
|
raise e
|
|
toc = TocFile(tocfile)
|
|
toc.parse()
|
|
os.unlink(tocfile)
|
|
return toc
|
|
|
|
def version():
|
|
"""
|
|
Return cdrdao version as a string.
|
|
"""
|
|
cdrdao = Popen(CDRDAO, stderr=PIPE)
|
|
out, err = cdrdao.communicate()
|
|
if cdrdao.returncode != 1:
|
|
logger.warning("cdrdao version detection failed: "
|
|
"return code is " + str(cdrdao.returncode))
|
|
return None
|
|
m = re.compile(r'^Cdrdao version (?P<version>.*) - \(C\)').search(
|
|
err.decode('utf-8'))
|
|
if not m:
|
|
logger.warning("cdrdao version detection failed: "
|
|
"could not find version")
|
|
return None
|
|
return m.group('version')
|
|
|
|
def ReadTOCTask(device):
|
|
"""
|
|
stopgap morituri-insanity compatibility layer
|
|
"""
|
|
return read_toc(device, fast_toc=True)
|
|
|
|
def ReadTableTask(device):
|
|
"""
|
|
stopgap morituri-insanity compatibility layer
|
|
"""
|
|
return read_toc(device)
|
|
|
|
def getCDRDAOVersion():
|
|
"""
|
|
stopgap morituri-insanity compatibility layer
|
|
"""
|
|
return version()
|