Sha256: 4cee0b6d5bcdf6ba67e1829e558b3bcf0eb25deb9439c76e7526061385abc618

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby
#$Id: cdchange.rb,v 1.2 2007/10/13 23:31:51 rocky Exp $ -*- Python -*-
# 
# A Program to show CD media changing
#
#
#    Copyright (C) 2007 Rocky Bernstein <rocky@gnu.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
mypath = File.dirname(__FILE__)

if(File::exists?(mypath + "/../lib/cdio.rb"))
  $: << File.dirname(__FILE__) + '/../lib'
  $: << File.dirname(__FILE__) + '/../ext/cdio'
else
  require 'rubygems'
end
require "cdio"

sleep_time = 15
if ARGV[0]
    begin
        d = Cdio::Device.new(ARGV.first)
    rescue IOError
      print "Problem opening CD-ROM: %s" % sys.argv[1]
      exit 1
    end
    if ARGV[1]
      begin
        sleep_time = ARGV[1].to_i
      rescue
        print "Invalid sleep parameter #{ARGV[1]}"
        exit 2
      end
    end
else
    begin
        d = Cdio::Device.new(nil, Rubycdio::DRIVER_UNKNOWN)
    rescue IOError
      print "Problem finding a CD-ROM"
      exit 1
    end
end

if d.media_changed?
  print "Initial media status: changed"
else
  print "Initial media status: not changed"
end

print "Giving you #{sleep_time} seconds to change CD if you want to do so."
sleep(sleep_time)
if d.media_changed?
  print "Media status: changed"
else
    print "Media status: not changed"
end
d.close()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rbcdio-0.02 example/cdchange.rb