Class: Superset::Dashboard::Export

Inherits:
Request
  • Object
show all
Includes:
FileUtilities
Defined in:
lib/superset/dashboard/export.rb

Constant Summary collapse

TMP_SUPERSET_DASHBOARD_PATH =
'/tmp/superset_dashboard_exports'

Constants inherited from Request

Request::PAGE_SIZE

Instance Attribute Summary collapse

Attributes inherited from Request

#page_num

Instance Method Summary collapse

Methods inherited from Request

call, #query_params, #result, #superset_host

Methods included from Superset::Display

#display_headers, #headings, #list, #list_attributes, #result, #rows, #table, #title

Constructor Details

#initialize(dashboard_id:, destination_path:) ⇒ Export

Returns a new instance of Export.



20
21
22
23
# File 'lib/superset/dashboard/export.rb', line 20

def initialize(dashboard_id: , destination_path: )
  @dashboard_id = dashboard_id
  @destination_path = destination_path.chomp('/')
end

Instance Attribute Details

#dashboard_idObject (readonly)

Returns the value of attribute dashboard_id.



18
19
20
# File 'lib/superset/dashboard/export.rb', line 18

def dashboard_id
  @dashboard_id
end

#destination_pathObject (readonly)

Returns the value of attribute destination_path.



18
19
20
# File 'lib/superset/dashboard/export.rb', line 18

def destination_path
  @destination_path
end

Instance Method Details

#performObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/superset/dashboard/export.rb', line 25

def perform
  logger.info("Exporting dashboard: #{dashboard_id}")
  create_tmp_dir
  save_exported_zip_file
  unzip_files
  clean_destination_directory
  copy_export_files_to_destination_path if destination_path

  Dir.glob("#{destination_path_with_dash_id}/**/*").select { |f| File.file?(f) }
rescue StandardError => e
  raise
ensure
  cleanup_temp_dir
end

#responseObject



40
41
42
43
44
45
46
# File 'lib/superset/dashboard/export.rb', line 40

def response
  @response ||= client.call(
    :get,
    client.url(route),
    client.param_check(params)
  )
end

#zip_file_nameObject



48
49
50
# File 'lib/superset/dashboard/export.rb', line 48

def zip_file_name
  @zip_file_name ||= "#{tmp_uniq_dashboard_path}/dashboard_#{dashboard_id}_export_#{datestamp}.zip"
end