Created
June 30, 2009 20:10
-
-
Save jolts/138386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'rubygems' | |
{ | |
:fileutils => ['fileutils', true] | |
}.each do |key, info| | |
path, required = info[0, 2] | |
$have_lib ||= {} | |
begin | |
require path | |
$have_lib[key] = true | |
rescue LoadError | |
if required | |
abort <<-ERR | |
You're missing '#{path}'. | |
Please make sure you have the necessary rubygems installed. | |
ERR | |
else | |
$have_lib[key] = true | |
end | |
end | |
end | |
module UsbSyncer | |
class << self | |
def sync | |
end | |
end | |
module UsbUtils | |
def find_device(model) | |
IO.popen('lsusb', IO::RDONLY) { |usbdev| usbdev.read.lines }.each do |line| | |
if line.match(model) | |
bus = line.scan(/^\w{3}\s(\d{3})/)[0][0].to_i | |
device = line.scan(/\w{6}\s(\d{3})/)[0][0].to_i | |
return [true, bus, device] | |
else | |
next | |
end | |
end | |
end | |
end | |
class Device | |
include UsbSyncer::UsbUtils | |
def initialize(model = /default/) | |
@device = nil | |
@model = model | |
end | |
def init_device | |
find_device(@model) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment