aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorZog2018-04-04 11:06:27 +0200
committerJohan Van Ryseghem2018-05-28 10:34:19 +0200
commitac79e03aced3969df8626f15165a0f6e6f783295 (patch)
tree63f6cfd0bf4212e184e35075484ce8ac9e45f48a /app
parent72f9cc6d810fd2a2226e9b1f0c74b8fbfbb2811c (diff)
downloadchouette-core-ac79e03aced3969df8626f15165a0f6e6f783295.tar.bz2
Refs #6216; Uniformize output folders
And fix logs
Diffstat (limited to 'app')
-rw-r--r--app/models/simple_importer.rb16
-rw-r--r--app/models/simple_interface.rb7
-rw-r--r--app/models/simple_interfaces_group.rb4
3 files changed, 17 insertions, 10 deletions
diff --git a/app/models/simple_importer.rb b/app/models/simple_importer.rb
index 4cfe90cff..d47ff6a92 100644
--- a/app/models/simple_importer.rb
+++ b/app/models/simple_importer.rb
@@ -42,8 +42,10 @@ class SimpleImporter < SimpleInterface
end
def dump_csv_from_context
- dir = context[:logs_output_dir] || "log/importers"
- filepath = File.join dir, "#{self.configuration_name}_#{Time.now.strftime "%y%m%d%H%M"}.csv"
+ dir = @output_dir
+ FileUtils.mkdir_p dir
+
+ filepath = File.join dir, "#{self.configuration_name}_#{Time.now.strftime "%y%m%d%H%M"}_dump.csv"
# for some reason, context[:csv].to_csv does not work
CSV.open(filepath, 'w') do |csv|
header = true
@@ -131,14 +133,16 @@ class SimpleImporter < SimpleInterface
@current_attribute = col[:attribute]
val = col[:value]
if val.nil? || val.is_a?(Proc)
- if row.has_key? col.name
- if val.is_a?(Proc)
+ if val.is_a?(Proc)
+ if row.has_key? col.name
val = instance_exec(row[col.name], &val)
else
- val = row[col.name]
+ val = instance_exec(&val)
end
+ elsif row.has_key? col.name
+ val = row[col.name]
else
- push_in_journal({event: :column_not_found, message: "Column not found: #{col.name}", kind: :warning})
+ push_in_journal({event: :column_not_found, message: "Column not found: #{col.name || col.attribute}", kind: :warning})
self.status ||= :success_with_warnings
end
end
diff --git a/app/models/simple_interface.rb b/app/models/simple_interface.rb
index 7b04a07df..d5feafb07 100644
--- a/app/models/simple_interface.rb
+++ b/app/models/simple_interface.rb
@@ -97,13 +97,14 @@ class SimpleInterface < ApplicationModel
def write_output_to_csv
cols = %i(line kind event message error)
- if self.journal.size > 0 && self.journal.first[:row].present?
+ journal = self.journal && self.journal.map(&:symbolize_keys)
+ if journal && journal.size > 0 && journal.first[:row].present?
log "Writing output log"
FileUtils.mkdir_p @output_dir
- keys = self.journal.first[:row].map(&:first)
+ keys = journal.first[:row].map(&:first)
CSV.open(output_filepath, "w") do |csv|
csv << cols + keys
- self.journal.each do |j|
+ journal.each do |j|
csv << cols.map{|c| j[c]} + j[:row].map(&:last)
end
end
diff --git a/app/models/simple_interfaces_group.rb b/app/models/simple_interfaces_group.rb
index 808be6570..53e28c36a 100644
--- a/app/models/simple_interfaces_group.rb
+++ b/app/models/simple_interfaces_group.rb
@@ -30,7 +30,9 @@ class SimpleInterfacesGroup
name = "### #{self.name} ###"
centered_name = " " * ([width - name.size, 0].max / 2) + name
- banner = [centered_name, ""]
+ banner = [centered_name]
+ banner << "Output to: #{shared_options[:output_dir]}" if shared_options[:output_dir]
+ banner << ""
banner << @interfaces.each_with_index.map do |interface, i|
if interface[:interface].status.present?
SimpleInterface.colorize interface[:name], SimpleInterface.status_color(interface[:interface].status)