Created
May 1, 2015 13:46
-
-
Save pedrocr/427dd6bf045f646b2c6a to your computer and use it in GitHub Desktop.
Script to check correspondence between cameras.xml and adobe_coeffs.c
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 | |
require 'nokogiri' | |
if ARGV.size != 2 | |
$stderr.puts "Usage: check-cameras <path/to/cameras.xml> <path/to/adobe_coeff.c>" | |
exit 2 | |
end | |
def munge_make_model(make, model) | |
if make.split[0] == model.split[0] | |
model | |
elsif model[0..6] == "FinePix" | |
"#{make.split[0]} #{model[7..-1].strip}" | |
else | |
"#{make.split[0]} #{model}" | |
end.strip.upcase | |
end | |
rawspeed_cameras = [] | |
File.open(ARGV[0]) do |f| | |
xml_doc = Nokogiri::XML(f) | |
xml_doc.css("Camera").each do |c| | |
make = c.attribute("make").value | |
model = c.attribute("model").value | |
supported = !c.attribute("supported") || c.attribute("supported").value == "yes" | |
if true #supported | |
#rawspeed_cameras << munge_make_model(make, model) | |
c.css("Alias").each do |a| | |
rawspeed_cameras << munge_make_model(make, a.content) | |
end | |
end | |
end | |
end | |
coeffs_cameras = {} | |
File.open(ARGV[1]) do |f| | |
f.each do |line| | |
if line[0..4] == " {" | |
coeffs_cameras[line.split('"')[1].strip.upcase] = 0 | |
end | |
end | |
end | |
puts "Found #{rawspeed_cameras.size} cameras in cameras.xml and #{coeffs_cameras.size} in adobe_coeffs" | |
unmatched_cameras = [] | |
rawspeed_cameras.each do |c| | |
if !coeffs_cameras[c] | |
unmatched_cameras << c | |
else | |
coeffs_cameras[c] += 1 | |
end | |
end | |
unmatched_coeffs = [] | |
coeffs_cameras.each do |c, num| | |
if num == 0 | |
unmatched_coeffs << c | |
end | |
end | |
puts "Found #{unmatched_cameras.size} cameras without adobe_coeff and #{unmatched_coeffs.size} adobe_coeffs with no camera" | |
puts "\nUnmatched Cameras\n" | |
unmatched_cameras.each {|c| puts c} | |
puts "\nUnmatched Coeffs\n" | |
unmatched_coeffs.each {|c| puts c} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment