Commit 40a891fbc91b8a5f3296ce67775fb27f2b7f31bc
1 parent
417f1c7e
Exists in
master
and in
79 other branches
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 |