Commit 40a891fbc91b8a5f3296ce67775fb27f2b7f31bc

Authored by Arthur Esposte
1 parent 417f1c7e
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Change export task destination directory to /tmp/

Showing 1 changed file with 109 additions and 58 deletions   Show diff stats
lib/tasks/export.rake
@@ -6,77 +6,128 @@ namespace :export do @@ -6,77 +6,128 @@ namespace :export do
6 task :csv => :environment do 6 task :csv => :environment do
7 Environment.all.each do |env| 7 Environment.all.each do |env|
8 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("SoftwareCommunitiesPlugin") 8 if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("SoftwareCommunitiesPlugin")
9 - CSV.open('softwares.csv', 'w') do |csv| 9 + softwares_to_csv
  10 + categories_to_csv
  11 + software_categories_to_csv
  12 +
  13 + compress_files
  14 + end
  15 + end
  16 + end
  17 + end
  18 +
  19 + def softwares_to_csv
  20 + print "Exporting softwares to softwares.csv: "
  21 +
  22 + CSV.open('/tmp/softwares.csv', 'w') do |csv|
  23 + csv << [
  24 + "id",
  25 + "community_id",
  26 + "identifier",
  27 + "name",
  28 + "finality",
  29 + "acronym",
  30 + "created_at",
  31 + "image_filename",
  32 + "home_page_name",
  33 + "home_page_slug",
  34 + "home_page_path",
  35 + "home_page_body",
  36 + "home_page_abstract",
  37 + "home_page_published_at"
  38 + ]
  39 +
  40 + SoftwareInfo.all.each do |software|
  41 + if software.community
  42 + begin
10 csv << [ 43 csv << [
11 - "id",  
12 - "community_id",  
13 - "identifier",  
14 - "name",  
15 - "finality",  
16 - "acronym",  
17 - "created_at",  
18 - "image_filename",  
19 - "home_page_name",  
20 - "home_page_slug",  
21 - "home_page_path",  
22 - "home_page_body",  
23 - "home_page_abstract",  
24 - "home_page_published_at" 44 + software.id,
  45 + software.community.id,
  46 + software.community.identifier,
  47 + software.community.name,
  48 + software.finality,
  49 + software.acronym,
  50 + software.community.created_at,
  51 + (software.community.image.nil? ? nil : software.community.image.filename),
  52 + (software.community.home_page.nil? ? nil : software.community.home_page.name),
  53 + (software.community.home_page.nil? ? nil : software.community.home_page.slug),
  54 + (software.community.home_page.nil? ? nil : software.community.home_page.path),
  55 + (software.community.home_page.nil? ? nil : software.community.home_page.body),
  56 + (software.community.home_page.nil? ? nil : software.community.home_page.abstract),
  57 + (software.community.home_page.nil? ? nil : software.community.home_page.published_at),
25 ] 58 ]
26 59
27 - SoftwareInfo.all.each do |software|  
28 - csv << [  
29 - software.id,  
30 - software.community.id,  
31 - software.community.identifier,  
32 - software.community.name,  
33 - software.finality,  
34 - software.acronym,  
35 - software.community.created_at,  
36 - (software.community.image.nil? ? nil : software.community.image.filename),  
37 - (software.community.home_page.nil? ? nil : software.community.home_page.name),  
38 - (software.community.home_page.nil? ? nil : software.community.home_page.slug),  
39 - (software.community.home_page.nil? ? nil : software.community.home_page.path),  
40 - (software.community.home_page.nil? ? nil : software.community.home_page.body),  
41 - (software.community.home_page.nil? ? nil : software.community.home_page.abstract),  
42 - (software.community.home_page.nil? ? nil : software.community.home_page.published_at),  
43 - ]  
44 - end 60 + print '.'
  61 + rescue
  62 + print 'F'
45 end 63 end
  64 + end
  65 + end
  66 + end
46 67
47 - CSV.open('categories.csv', 'w') do |csv|  
48 - csv << [  
49 - "id",  
50 - "name",  
51 - "path",  
52 - ] 68 + print "\n"
  69 + end
  70 +
  71 + def categories_to_csv
  72 + print "Exporting categories to categories.csv: "
53 73
54 - Category.all.each do |category| 74 + CSV.open('/tmp/categories.csv', 'w') do |csv|
  75 + csv << [
  76 + "id",
  77 + "name",
  78 + "path",
  79 + ]
  80 +
  81 + Category.all.each do |category|
  82 + begin
  83 + csv << [
  84 + category.id,
  85 + category.name,
  86 + category.path,
  87 + ]
  88 +
  89 + print '.'
  90 + rescue
  91 + print 'F'
  92 + end
  93 + end
  94 + end
  95 +
  96 + print "\n"
  97 + end
  98 +
  99 + def software_categories_to_csv
  100 + print "Exporting software and categories relation to software_categories.csv: "
  101 + CSV.open('/tmp/software_categories.csv', 'w') do |csv|
  102 + csv << [
  103 + "software_id",
  104 + "category_id"
  105 + ]
  106 +
  107 + SoftwareInfo.all.each do |software|
  108 + if software.community
  109 + software.community.categories.each do |category|
  110 + begin
55 csv << [ 111 csv << [
56 - category.id,  
57 - category.name,  
58 - category.path, 112 + software.id,
  113 + category.id
59 ] 114 ]
60 - end  
61 - end  
62 -  
63 - CSV.open('software_categories.csv', 'w') do |csv|  
64 - csv << [  
65 - "software_id",  
66 - "category_id"  
67 - ]  
68 115
69 - SoftwareInfo.all.each do |software|  
70 - software.community.categories.each do |category|  
71 - csv << [  
72 - software.id,  
73 - category.id  
74 - ]  
75 - end 116 + print '.'
  117 + rescue
  118 + print 'F'
76 end 119 end
77 end 120 end
78 end 121 end
79 end 122 end
80 end 123 end
  124 +
  125 + print "\n"
  126 + end
  127 +
  128 + def compress_files
  129 + `cd /tmp/ && tar -zcvf software_catalog_csvs.tar.gz softwares.csv categories.csv software_categories.csv`
  130 +
  131 + `cd /tmp/ && rm softwares.csv categories.csv software_categories.csv`
81 end 132 end
82 end 133 end
83 \ No newline at end of file 134 \ No newline at end of file