Module: ColumbiaPrinters
- Defined in:
- lib/ColumbiaPrinters.rb
Instance Method Summary collapse
Instance Method Details
#add_printer(printer) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ColumbiaPrinters.rb', line 71 def add_printer printer puts "Installing printer #{printer["name"]}" driver_filename = case printer["driver"] when "HP LaserJet 9050 PS"; "HP\\ LaserJet\\ 9050.gz" when "HP LaserJet 9050 Series PS"; "HP\\ LaserJet\\ 9050.gz" when "HP Color LaserJet 4700 PS"; "HP\\ Color\\ LaserJet\\ 4700.gz" when "HP Color LaserJet 5500 PS"; "HP\\ Color\\ LaserJet\\ 5550.gz" when "HP LaserJet 8150 Series PS"; "HP\\ LaserJet\\ 8150\\ Series.gz" when "HP LaserJet 4200 PS"; "HP\\ LaserJet\\ 4000\\ Series.gz" when "HP LaserJet 4250 PS"; "HP\\ LaserJet\\ 4000\\ Series.gz" when "HP LaserJet 4200 Series PS"; "HP\\ LaserJet\\ 4000\\ Series.gz" when "HP LaserJet P4015"; "HP\\ LaserJet\\ 4000\\ Series.gz" when "HP LaserJet 4015 PS"; "HP\\ LaserJet\\ 4000\\ Series.gz" when "HP LaserJet 4000 PS"; "HP\\ LaserJet\\ 4000\\ Series.gz" when "HP LaserJet 4350 PS"; "HP\\ LaserJet\\ 4350.gz" when "HP LaserJet 8150 PS"; "HP\\ LaserJet\\ 8150\\ Series.gz" when "HP Color LaserJet 4650 PS"; "HP\\ Color\\ LaserJet\\ 4500.gz" when "HP LaserJet 4350 Series PS"; "HP\\ LaserJet\\ 4350.gz" when "HP LaserJet 4010 series/4510 Series PS"; "HP\\ LaserJet\\ P4010_P4510\\ Series.gz" when "HP LaserJet 4300 Series PS"; "HP\\ LaserJet\\ 4350.gz" when "HP LaserJet 5100 PS"; "HP\\ LaserJet\\ 5100\\ Series.gz" when "HP LaserJet 5200 PS"; "HP\\ LaserJet\\ 5200.gz" when "HP LaserJet 4050 Series PS"; "HP\\ LaserJet\\ 4050\\ Series.gz" when "HP LaserJet 8100 Series PS"; "HP\\ LaserJet\\ 8100\\ Series.gz" when "HP LaserJet 9000 Series PS"; "HP\\ LaserJet\\ 9000\\ Series.gz" else; printer["driver"].gsub(/PS|Series/, "").gsub("/", "_").strip.gsub(" ", '\\ ') + ".gz" end # system command to install new printer on UNIX system using lpadmin `lpadmin -p "#{printer["name"]}" -L "#{printer["place"]}" -E -v lpd://#{printer["address"]}/public -P /Library/Printers/PPDs/Contents/Resources/#{driver_filename}` end |
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ColumbiaPrinters.rb', line 10 def run url_prefix = "http://www.columbia.edu/acis/facilities/printers/" printer_src_files = [ "#{url_prefix}ninja/acis/js/printers.js", "#{url_prefix}ninja/barnard/js/printers.js", "#{url_prefix}ninja/cait/js/printers.js", "#{url_prefix}ninja/lso/js/printers.js", "#{url_prefix}ninja/meche/js/printers.js", "#{url_prefix}ninja/old_pcd/js/printers.js", "#{url_prefix}ninja/soa/js/printers.js", "#{url_prefix}ninja/ssw/js/printers.js" ] puts "Loading printers (this requires an active internet connection)..." printers = [] begin slice[0,2] printer_src_files.each do |src| doc = Nokogiri::HTML(open( src )) html = doc.to_html printer_details = html.scan( /printers\[printers.length\] = ([^;]+)/ ) printer_details.each do |p| unless p.first.nil? details = p.first.scan( /"([^"]+)"/) unless details.nil? or details.size != 5 printers << Struct::Printer.new( details[0].first.strip, details[3].first.strip, details[1].first.strip, details[2].first.strip ) end end end puts "Done loading #{src}" end rescue puts "Loading from internet failed, using default printer list" printer_details = YAML.load_file(File.join(File.dirname(__FILE__), 'printers.yaml'))["printers"] printer_details.each { |printer| printers << Struct::Printer.new(printer["name"], printer["place"],printer["address"], printer["driver"]) } end while( true ) puts "1.) Add printer\n2.) Add all printers\n3.) Quit" case gets.to_i when 1 puts "Printers" printers.each_index { |x| puts x.to_s + ".)" + printers[x]["name"] } add_printer(printers[gets.to_i]) when 2 printers.each { |x| add_printer(x) } when 3 return end end end |