From ae8c3120aa84858d4b005059e2d985417ea6d7e3 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Mon, 14 Jul 2014 17:22:49 -0500 Subject: [PATCH] * wip --- ruby/lib/jam_ruby/models/country.rb | 2 +- ruby/lib/jam_ruby/models/max_mind_release.rb | 11 +++++++++-- ruby/lib/jam_ruby/models/region.rb | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ruby/lib/jam_ruby/models/country.rb b/ruby/lib/jam_ruby/models/country.rb index 18e8a97b3..3d4cb5c14 100644 --- a/ruby/lib/jam_ruby/models/country.rb +++ b/ruby/lib/jam_ruby/models/country.rb @@ -9,7 +9,7 @@ module JamRuby def self.find_iso3166 gem_dir = Gem::Specification.find_by_name("jam_ruby").gem_dir - File.join(gem_dir, 'lib', 'jam_ruby', 'geo_data', 'iso3166.csv') + File.join(gem_dir, 'lib', 'jam_ruby', 'geodata', 'iso3166.csv') end def self.import_from_iso3166(file = find_iso3166) diff --git a/ruby/lib/jam_ruby/models/max_mind_release.rb b/ruby/lib/jam_ruby/models/max_mind_release.rb index 1c77dd974..2409b69d9 100644 --- a/ruby/lib/jam_ruby/models/max_mind_release.rb +++ b/ruby/lib/jam_ruby/models/max_mind_release.rb @@ -59,7 +59,7 @@ module JamRuby @@log.debug("working on field=#{field}, filename #{downloaded_filename}") if File.exists?(downloaded_filename) - if matched_md5(downloaded_filename, md5) + if matching_md5(downloaded_filename, md5) @@log.debug("#{downloaded_filename} file has matching md5") return downloaded_filename else @@ -88,6 +88,12 @@ module JamRuby downloaded_filename end + def matching_md5(downloaded_filename, md5) + computed_md5 = Digest::MD5.new + File.open(downloaded_filename, 'rb').each {|line| computed_md5.update(line)} + computed_md5.to_s == md5 + end + def unzip(working_dir, downloaded_filename) result = {} @@ -107,9 +113,10 @@ module JamRuby # Extract to file/directory/symlink entry_output_dir = File.join(Dir.pwd, output_dir, File.dirname(entry.name)) - res = FileUtils.mkdir_p(entry_output_dir) + FileUtils.mkdir_p(entry_output_dir) output_filename = File.join(output_dir, entry.name) + File.delete(output_filename) if File.exists?(output_filename) entry.extract(output_filename) result[File.basename(entry.name)] = output_filename end diff --git a/ruby/lib/jam_ruby/models/region.rb b/ruby/lib/jam_ruby/models/region.rb index 56ef29443..ce02a012d 100644 --- a/ruby/lib/jam_ruby/models/region.rb +++ b/ruby/lib/jam_ruby/models/region.rb @@ -9,7 +9,7 @@ module JamRuby def self.find_region_codes gem_dir = Gem::Specification.find_by_name("jam_ruby").gem_dir - File.join(gem_dir, 'lib', 'jam_ruby', 'geo_data', 'region_codes.csv') + File.join(gem_dir, 'lib', 'jam_ruby', 'geodata', 'region_codes.csv') end def self.import_from_region_codes(file = find_region_codes)