Revision: 3ea1b546d5e8
Author: Bouke Woudstra <
boukew...@gmail.com>
Date: Thu May 9 04:13:47 2013
Log: Fixed the error handling for scanDiscCdparanoia.
http://code.google.com/p/rubyripper/source/detail?r=3ea1b546d5e8
Modified:
/lib/rubyripper/disc/permissionDrive.rb
/lib/rubyripper/disc/scanDiscCdparanoia.rb
/lib/rubyripper/errors.rb
=======================================
--- /lib/rubyripper/disc/permissionDrive.rb Wed Jan 2 11:23:31 2013
+++ /lib/rubyripper/disc/permissionDrive.rb Thu May 9 04:13:47 2013
@@ -29,7 +29,7 @@
def initialize(prefs=nil, deps=nil)
@prefs = prefs ? prefs : Preferences::Main.instance
@deps = deps ? deps : Dependency.instance()
- @error = nil
+ @error = nil # Array for Error class [:symbol, parameters]
end
# before trying to query cdparanoia check if permissions of the drive
are ok
@@ -82,36 +82,21 @@
# check if it is not a fake device
def isBlockDevice?
if not File.blockdev?(@cdrom)
- @error = _("ERROR: Cdrom drive %s does not exist on your system!\n\
-Please configure your cdrom drive first.") % [@cdrom]
+ @error = [:unknownDrive, @cdrom]
end
end
# check is the user has read permissions for the drive
def isDriveReadable?
unless File.readable?(@cdrom)
- @error = _("You don't have read permissions for device\n
-%s on your system! These permissions are necessary for\n
-cdparanoia to scan your drive. You might want to add yourself\n
-to the necessary group with gpasswd.") % [@cdrom]
- if @deps.installed?('ls')
- permission = `ls -l #{@cdrom}`
- @error += _("\n\nls -l shows %s") % [permission]
- end
+ @error = [:noReadPermissionsForDrive, @cdrom]
end
end
# check if the user has write permissions for the drive
def isDriveWritable?
unless File.writable?(@cdrom)
- @error = _("You don't have write permissions for device\n
-%s on your system! These permissions are necessary for\n
-cdparanoia to scan your drive. You might want to add yourself\n
-to the necessary group with gpasswd.") % [@cdrom]
- if @deps.installed?('ls')
- permission = `ls -l #{@cdrom}`
- @error += _("\n\nls -l shows %s") % [permission]
- end
+ @error = [:noWritePermissionsForDrive, @cdrom]
end
end
@@ -129,16 +114,7 @@
# lookup the scsi device and it's permissions
def genericDeviceChecks(drive)
unless ((File.chardev?(drive) || File.blockdev?(drive)) &&
File.readable?(drive) && File.writable?(drive))
- permission = nil
- if File.chardev?(drive) && @deps.installed?('ls')
- permission = `ls -l #{drive}`
- end
-
- @error = _("You don't have read and write permission\n"\
- "for device %s on your system! These permissions are\n"\
- "necessary for cdparanoia to scan your drive.\n\n%s\n"\
- "You might want to add yourself to the necessary group with
gpasswd")\
- %[device, "#{if permission ; "ls -l shows #{permission}" end}"]
+ @error = [:noPermissionsForSCSIDrive, drive]
end
end
end
=======================================
--- /lib/rubyripper/disc/scanDiscCdparanoia.rb Wed Jan 9 14:11:49 2013
+++ /lib/rubyripper/disc/scanDiscCdparanoia.rb Thu May 9 04:13:47 2013
@@ -41,6 +41,7 @@
@prefs = prefs ? prefs : Preferences::Main.instance
@out = out ? out : $stdout
@status = nil
+ @error = nil # Array for Error class [:symbol, parameters] in case
status != 'ok'
@audiotracks = nil
end
@@ -48,11 +49,11 @@
def scan
return true if @status == 'ok'
if @perm.problems?(@prefs.cdrom)
- setError(:permissionDrive, @perm.error)
+ updateStatus(@perm.error)
else
waitForDisc()
if @error.nil? && @perm.problemsSCSI?(@query)
- setError(:permissionScsiDrive, @perm.error)
+ updateStatus(@perm.error)
elsif @error.nil?
@status = 'ok'
end
@@ -105,13 +106,13 @@
private
- def setError(code, parameters=nil)
+ def updateStatus(error)
@status = 'error'
- @error = [code, parameters]
+ @error = error
end
# new scan, new chances, so reset the error status
- def unsetError
+ def restoreStatus
@status = nil
@error = nil
end
@@ -124,7 +125,7 @@
# give the cdrom drive a few seconds to read the disc
def waitForDisc
(1..10).each do |trial|
- unsetError()
+ restoreStatus()
readDisc()
break if @error.nil? || @prefs.testdisc || $run_specs
@out.puts Errors.noDiscYet(trial)
@@ -163,15 +164,15 @@
# check the query result for errors
def isValidQuery()
if @query.nil?
- setError(:notInstalled, 'cdparanoia')
+ updateStatus([:notInstalled, 'cdparanoia'])
return false
end
@query.each do |line|
case line
- when /Unable to open disc/ then setError(:noDiscInDrive,
@prefs.cdrom) ; break
- when /USAGE/ then setError(:wrongParameters, 'cdparanoia') ; break
- when /No such file or directory/ then setError(:unknownDrive,
@prefs.cdrom) ; break
+ when /Unable to open disc/ then updateStatus([:noDiscInDrive,
@prefs.cdrom]) ; break
+ when /USAGE/ then updateStatus([:wrongParameters, 'cdparanoia']) ;
break
+ when /No such file or directory/ then updateStatus([:unknownDrive,
@prefs.cdrom]) ; break
end
end
=======================================
--- /lib/rubyripper/errors.rb Thu Dec 27 12:29:25 2012
+++ /lib/rubyripper/errors.rb Thu May 9 04:13:47 2013
@@ -26,10 +26,13 @@
:noDiscInDrive => _("There is no audio disc ready in drive %s."),
:wrongParameters => _("%s does not recognize the parameters used."),
:unknownDrive => _("The device %s doesn't exist on your system!"),
+ :noReadPermissionsForDrive => _("No read permissions for
drive %s!\nThis is required to scan the disc."),
+ :noWritePermissionsForDrive => _("No write permissions for
drive %s!\nThis is required to scan the disc."),
+ :noPermissionsForSCSIDrive => _("No read + write permissions for
drive %s!\nThis is required to rip the disc."),
:noTrackSelection => _("Please select at least one track."),
:noCodecSelected => _("Please select at least one codec."),
:noValidUserInterface => _("No update function found in the user
interface"),
- :binaryNotFound => _("%s is needed, but not detected on your system!"),
+ :binaryNotFound => _("%s is required, but not detected on your
system!"),
:cdrdaoNotFound => _("Please install cdrdao or disable cuesheet
generation."),
:failedToExecute => _("The program %s failed to execute
correctly:\n%s"),
:dirNotWritable => _("Can't create output directory!\nYou have no
writing access for directory %s"),