cdrdao no-disc ejection & --eject (#93)

* cdrdao: eject empty disc while reading toc

- introduce EjectError
- move {eject,load,unmount}_device to program.utils

* remove duplicated eject

* remove unnecessary ejection

* add --eject option
This commit is contained in:
Samantha Baldwin
2017-01-01 13:41:23 -05:00
committed by JoeLametta
parent 17021a68f2
commit a1eb3377ea
7 changed files with 83 additions and 47 deletions

View File

@@ -34,7 +34,7 @@ from morituri.command.basecommand import BaseCommand
from morituri.common import (
accurip, common, config, drive, gstreamer, program, task
)
from morituri.program import cdrdao, cdparanoia
from morituri.program import cdrdao, cdparanoia, utils
from morituri.result import result
import logging
@@ -108,8 +108,8 @@ class _CD(BaseCommand):
self.device = self.options.device
sys.stdout.write('Checking device %s\n' % self.device)
self.program.loadDevice(self.device)
self.program.unmountDevice(self.device)
utils.load_device(self.device)
utils.unmount_device(self.device)
# first, read the normal TOC, which is fast
self.ittoc = self.program.getFastToc(self.runner,
@@ -140,8 +140,8 @@ class _CD(BaseCommand):
# also used by rip cd info
if not getattr(self.options, 'unknown', False):
if self.eject:
self.program.ejectDevice(self.device)
logger.critical("unable to retrieve disc metadata, "
"--unknown not passed")
return -1
# FIXME ?????
@@ -205,8 +205,8 @@ class _CD(BaseCommand):
self.doCommand()
if self.eject:
self.program.ejectDevice(self.device)
if self.options.eject in ('success', 'always'):
utils.eject_device(self.device)
def doCommand(self):
pass
@@ -587,8 +587,6 @@ Log files will log the path to tracks relative to this directory.
# write log file
self.program.writeLog(discName, self.logger)
self.program.ejectDevice(self.device)
class CD(BaseCommand):
summary = "handle CDs"

View File

@@ -12,6 +12,7 @@ from morituri.command import cd, offset, drive, image, accurip, debug
from morituri.command.basecommand import BaseCommand
from morituri.common import common, directory
from morituri.extern.task import task
from morituri.program.utils import eject_device
import logging
logger = logging.getLogger(__name__)
@@ -26,9 +27,13 @@ def main():
)
map(pkg_resources.working_set.add, distributions)
try:
ret = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None).do()
cmd = Whipper(sys.argv[1:], os.path.basename(sys.argv[0]), None)
ret = cmd.do()
except SystemError, e:
sys.stderr.write('whipper: error: %s\n' % e.args)
sys.stderr.write('whipper: error: %s\n' % e)
if (type(e) is common.EjectError and
cmd.options.eject in ('failure', 'always')):
eject_device(e.device)
return 255
except ImportError, e:
raise ImportError(e)
@@ -77,6 +82,10 @@ You can get help on subcommands by using the -h option to the subcommand.
self.parser.add_argument('-h', '--help',
action="store_true", dest="help",
help="show this help message and exit")
self.parser.add_argument('-e', '--eject',
action="store", dest="eject", default="always",
choices=('never', 'failure', 'success', 'always'),
help="when to eject disc (default: always)")
def handle_arguments(self):
if self.options.help:

View File

@@ -31,7 +31,7 @@ gobject.threads_init()
from morituri.command.basecommand import BaseCommand
from morituri.common import accurip, common, config, drive, program
from morituri.common import task as ctask
from morituri.program import cdrdao, cdparanoia
from morituri.program import cdrdao, cdparanoia, utils
from morituri.extern.task import task
@@ -88,8 +88,8 @@ CD in the AccurateRip database."""
# if necessary, load and unmount
sys.stdout.write('Checking device %s\n' % device)
prog.loadDevice(device)
prog.unmountDevice(device)
utils.load_device(device)
utils.unmount_device(device)
# first get the Table Of Contents of the CD
t = cdrdao.ReadTOCTask(device)