diff options
| author | Zog | 2018-03-02 11:17:08 +0100 |
|---|---|---|
| committer | Zog | 2018-03-02 11:17:08 +0100 |
| commit | c1ac12174b9aff7535a84af9f76d1cda95b750f4 (patch) | |
| tree | 1207cd5a338cb9d7868bb893a50ef19978515b54 /lib/tasks/helpers | |
| parent | 6e694fb2d88fe29049ecf5bb3d0e89e0585bf6c5 (diff) | |
| download | chouette-core-c1ac12174b9aff7535a84af9f76d1cda95b750f4.tar.bz2 | |
Refs #6068; Refactor import/export tasks
Diffstat (limited to 'lib/tasks/helpers')
| -rw-r--r-- | lib/tasks/helpers/simple_interfaces.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/tasks/helpers/simple_interfaces.rb b/lib/tasks/helpers/simple_interfaces.rb new file mode 100644 index 000000000..68e02e818 --- /dev/null +++ b/lib/tasks/helpers/simple_interfaces.rb @@ -0,0 +1,27 @@ +module SimpleInterfacesHelper + def self.interface_output_to_csv interface, output_dir + filepath = File.join output_dir, + "#{interface.configuration_name}_#{Time.now.strftime "%y%m%d%H%M"}_out.csv" + cols = %w(line kind event message error) + if interface.reload.journal.size > 0 + keys = interface.journal.first["row"].map(&:first) + CSV.open(filepath, "w") do |csv| + csv << cols + keys + interface.journal.each do |j| + csv << cols.map{|c| j[c]} + j["row"].map(&:last) + end + end + puts "Task Output written in #{filepath}" + end + end + + def self.run_interface_controlling_interruption interface, method, args + begin + interface.send(method, verbose: true) + rescue Interrupt + raise + ensure + puts "\n\e[33m***\e[0m Done, status: " + (interface.status == "success" ? "\e[32m" : "\e[31m" ) + (interface.status || "") + "\e[0m" + interface_output_to_csv interface, args[:logs_output_dir] + end + end +end |
