From 80867bbc54718d56abddf1c60e79fdd7d748664f Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Tue, 4 Jan 2011 21:08:28 -0800 Subject: [PATCH] Make directory settable. --- lib/data_conversion/base.rb | 11 ++++------- lib/data_conversion/export_from_mongo.rb | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/data_conversion/base.rb b/lib/data_conversion/base.rb index 0a0d70141..871a6297d 100644 --- a/lib/data_conversion/base.rb +++ b/lib/data_conversion/base.rb @@ -4,10 +4,11 @@ module DataConversion class Base - attr_accessor :start_time + attr_accessor :start_time, :directory def initialize(start_time = Time.now) @start_time = start_time + @directory = "tmp/export-for-mysql" end def log(message) @@ -17,12 +18,8 @@ module DataConversion Rails.logger.debug(message) if Rails.logger end - def export_directory - "tmp/export-for-mysql" - end - - def export_path - "#{Rails.root}/#{export_directory}" + def full_path + "#{Rails.root}/#{directory}" end end end \ No newline at end of file diff --git a/lib/data_conversion/export_from_mongo.rb b/lib/data_conversion/export_from_mongo.rb index 2967cab5e..80c2442f2 100644 --- a/lib/data_conversion/export_from_mongo.rb +++ b/lib/data_conversion/export_from_mongo.rb @@ -22,9 +22,9 @@ module DataConversion end def clear_dir - `rm -rf #{export_path}` - `mkdir -p #{export_path}/json` - `mkdir -p #{export_path}/csv` + `rm -rf #{full_path}` + `mkdir -p #{full_path}/json` + `mkdir -p #{full_path}/csv` end def db_name @@ -64,10 +64,10 @@ module DataConversion log "Starting JSON export..." models.each do |model| log "Starting #{model[:name]} JSON export..." - filename ="#{export_path}/json/#{model[:name]}.json" + filename ="#{full_path}/json/#{model[:name]}.json" model[:json_file] = filename `#{json_for_model(model[:name])} > #{filename}` - log "Completed #{model[:name]} JSON export to #{export_directory}/json/#{model[:name]}.json." + log "Completed #{model[:name]} JSON export to #{directory}/json/#{model[:name]}.json." end log "JSON export complete." end @@ -82,7 +82,7 @@ module DataConversion log "Converting #{model_hash[:name]} json to csv" json_file = File.open(model_hash[:json_file]) - csv = CSV.open("#{export_path}/csv/#{model_hash[:name]}.csv", 'w') + csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w') csv << model_hash[:attrs] json_file.each do |aspect_json| @@ -140,10 +140,10 @@ module DataConversion log "Converting #{model_hash[:name]} json to csv" json_file = File.open(model_hash[:json_file]) - people_csv = CSV.open("#{export_path}/csv/#{model_hash[:name]}.csv", 'w') + people_csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w') people_csv << model_hash[:attrs] - profiles_csv = CSV.open("#{export_path}/csv/profiles.csv", 'w') + profiles_csv = CSV.open("#{full_path}/csv/profiles.csv", 'w') profiles_csv << model_hash[:profile_attrs] json_file.each do |aspect_json| @@ -209,10 +209,10 @@ module DataConversion log "Converting #{model_hash[:name]} json to two csvs" json_file = File.open(model_hash[:json_file]) - main_csv = CSV.open("#{export_path}/csv/#{model_hash[:name]}.csv", 'w') + main_csv = CSV.open("#{full_path}/csv/#{model_hash[:name]}.csv", 'w') main_csv << model_hash[:main_attrs] - join_csv = CSV.open("#{export_path}/csv/#{model_hash[:join_table_name]}.csv", 'w') + join_csv = CSV.open("#{full_path}/csv/#{model_hash[:join_table_name]}.csv", 'w') join_csv << model_hash[:join_table_attrs] json_file.each do |aspect_json|