Hardware authentication for Linux using ordinary USB Flash Drives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.4 KiB

  1. #!/usr/bin/env ruby
  2. #
  3. # hal_device_tree.rb
  4. #
  5. # Print a tree from the output of hal-device
  6. # Useful to analyse bug reports
  7. #
  8. require 'getopts'
  9. require 'open-uri'
  10. def parse_file(path)
  11. io = path
  12. io = open(io) if io.class != IO
  13. list = Array.new
  14. current = nil
  15. io.each_line do |line|
  16. if line =~ /^\d/
  17. list << current unless current.nil?
  18. current = Hash.new
  19. next
  20. end
  21. line.gsub!(/\(.*\)/, '')
  22. line.gsub!("'", '')
  23. k,v = line.split('=')
  24. next if k.strip.empty?
  25. current[k.strip] = v.strip
  26. end
  27. list
  28. end
  29. def print_node(node, pad = 0)
  30. print '|'
  31. pad.times { print "----" }
  32. print '-- '
  33. print "#{node['info.category']} " if node['info.category']
  34. print "#{node['info.product']} " if node['info.product']
  35. print " -> #{node['info.udi']}" if $OPT_u
  36. puts
  37. end
  38. def collect_children(list, root)
  39. root['childs'] = Array.new
  40. children = list.select { |e| e['info.parent'] == root['info.udi'] }
  41. children.each do |child|
  42. root['childs'] << child
  43. collect_children(list, child)
  44. end
  45. end
  46. def print_children(root, pad = 1)
  47. root['childs'].each do |child|
  48. print_node(child, pad)
  49. if not child['childs'].empty?
  50. print_children(child, pad + 1)
  51. end
  52. end
  53. end
  54. raise ArgumentError if getopts('uf:').nil?
  55. list = parse_file($OPT_f || STDIN)
  56. roots = list.select { |e| e['info.parent'].match(/computer/) unless e['info.parent'].nil? }
  57. roots.each do |root|
  58. collect_children(list, root)
  59. print_node(root)
  60. print_children(root)
  61. puts '|'
  62. end