~ion/restricted-manager/ion

35.1.5 by Johan Kiviniemi
* RestrictedManager/core.py: Added support for a modalias.override file,
1
#!/usr/bin/ruby
2
3
# nvidia_supported – create a modules.alias compatible listing of devices
4
# supported by nvidia drivers
5
#
6
# Copyright © 2007  Canonical Ltd.
7
#
8
# Author: Johan Kiviniemi <debian@johan.kiviniemi.name>
9
#
10
# This program is free software; you can redistribute it and/or modify it under
11
# the terms of the GNU General Public License as published by the Free Software
12
# Foundation; either version 2 of the License, or (at your option) any later
13
# version.
14
#
15
# This program is distributed in the hope that it will be useful, but WITHOUT
16
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18
# details.
19
#
20
# You should have received a copy of the GNU General Public License along with
21
# this program; if not, write to the Free Software Foundation, Inc., 51
22
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
41.1.2 by Johan Kiviniemi
* modalias_override/nvidia_supported: Remove the hard dependency on
24
begin
25
  require 'rubygems'
26
rescue LoadError
27
  # It's ok if mechanize has been installed via something else than rubygems.
28
end
29
35.1.5 by Johan Kiviniemi
* RestrictedManager/core.py: Added support for a modalias.override file,
30
require 'mechanize'
31
require 'logger'
32
33
def main
34
  usage if ARGV.empty?
35
36
  versions = []
37
  ARGV.each do |arg|
38
    driver, version = arg.split /:/, 2
39
    usage unless driver and version
40
    versions << [driver, version]
41
  end
42
43
  scraper = NvidiaSupported.new
44
  scraper.log = Logger.new $stderr
45
  scraper.log.level = Logger::INFO
46
47
  puts "# Listing generated by nvidia_supported. Do not edit manually."
48
49
  vendor_id = 0x10DE
50
51
  versions.each do |driver, version|
52
    puts "# #{driver}: #{version}"
53
    scraper.process(version).each do |dev_id|
54
      puts 'alias pci:v%08Xd%08Xsv*sd*bc*sc*i* %s' % [vendor_id,
55
        dev_id, driver]
56
    end
57
  end
58
59
  puts
60
end
61
62
def usage
63
  $stderr.puts "USAGE: #$0 nvidia:1.0-9876 nvidia_legacy:1.0-1234 ..."
64
  exit 1
65
end
66
67
class NvidiaSupported < WWW::Mechanize
68
  def initialize
69
    super
70
    get 'http://www.nvidia.com/object/linux_display_archive.html'
71
  end
72
73
  def process version
74
    transact do
75
      log.info "Clicking the driver link, version #{version}"
76
      link_re = Regexp.new '_v?' + Regexp.quote(version) + '\.html$'
77
      click page.links.with.href(link_re)
78
79
      log.info "Clicking the Supported Products List link"
80
      click page.links.with.text(/Supported Products List/)
81
41.1.1 by Johan Kiviniemi
* modalias_override/nvidia_supported: Add a workaround for older hpricot
82
      # A workaround for older hpricot (< 0.5) without support for expressions
83
      # like td[text() = ...]. The original form would be faster.
84
      #(page / 'td[text() ^= "0x"]').map {|td| td.inner_html.strip.hex }
85
86
      (page / 'td').
87
        map {|td| td.inner_html.strip }.
88
        find_all {|text| text =~ /^0x/ }.
89
        map {|text| text.hex }
35.1.5 by Johan Kiviniemi
* RestrictedManager/core.py: Added support for a modalias.override file,
90
    end
91
  end
92
end
93
94
main if $0 == __FILE__