Commit e834583d5e8efcd93d1b3cdea3a0379bface9008

Authored by Daniela Feitosa
2 parents c550c104 712caca6

Merge branch 'sisp_task_improvement' into 'master'

Sisp task improvement

Improvements on SISP task to be called from Chef.

See merge request !171
src/noosfero-spb/software_communities/lib/tasks/import_sisp_software.rake
1 # encoding: UTF-8 1 # encoding: UTF-8
2 2
3 namespace :sisp do 3 namespace :sisp do
4 - desc "Creates SISP env, template, and import data"  
5 - task :all => :environment do 4 + desc "Creates SISP env and templates"
  5 + task :prepare => :environment do
6 unless ENV["DOMAIN"].present? 6 unless ENV["DOMAIN"].present?
7 puts "You didn't choose any domain. The default domain is 'novo.sisp.gov.br'" 7 puts "You didn't choose any domain. The default domain is 'novo.sisp.gov.br'"
8 - puts "You can run rake sisp:all DOMAIN=domain.url"  
9 - puts "Continue and create SISP Environment with default domain? (y/N)"  
10 - response = $stdin.gets.strip  
11 -  
12 - unless ['y', 'yes'].include?(response.downcase)  
13 - puts "*** ABORTED."  
14 - exit 1  
15 - end 8 + puts "You can run rake sisp:prepare DOMAIN=domain.url to add a domain"
16 end 9 end
17 10
18 unless ENV["ADMINUSER"].present? 11 unless ENV["ADMINUSER"].present?
19 puts "You didn't enter any user to be selected from the default Environment" 12 puts "You didn't enter any user to be selected from the default Environment"
20 - puts "You can run rake sisp:all ADMINUSER=jose"  
21 - puts "Continue and create SISP Environment without an admin user? (y/N)"  
22 - response = $stdin.gets.strip  
23 -  
24 - unless ['y', 'yes'].include?(response.downcase)  
25 - puts "*** ABORTED."  
26 - exit 1  
27 - end 13 + puts "You can run rake sisp:prepare ADMINUSER=jose"
28 end 14 end
29 15
30 Rake::Task['sisp:create_env'].invoke 16 Rake::Task['sisp:create_env'].invoke
31 Rake::Task['noosfero:plugins:enable_all'].invoke 17 Rake::Task['noosfero:plugins:enable_all'].invoke
32 Rake::Task['sisp:create_template'].invoke 18 Rake::Task['sisp:create_template'].invoke
33 - Rake::Task['sisp:import_data'].invoke  
34 end 19 end
35 20
  21 + desc "Create SISP environment and import data"
  22 + task :all => [:prepare, :import_data]
  23 +
36 desc "Creates the SISP Environment" 24 desc "Creates the SISP Environment"
37 task :create_env => :environment do 25 task :create_env => :environment do
38 env = Environment.find_or_create_by_name("SISP") 26 env = Environment.find_or_create_by_name("SISP")
@@ -56,15 +44,8 @@ namespace :sisp do @@ -56,15 +44,8 @@ namespace :sisp do
56 sisp_user.save 44 sisp_user.save
57 sisp_user.activate 45 sisp_user.activate
58 env.add_admin sisp_user.person 46 env.add_admin sisp_user.person
59 - puts "SISP admin user created with success!"  
60 - puts "Type the password for this user"  
61 - $stdin.echo = false  
62 - sisp_user.password = $stdin.gets.strip  
63 - puts "Type the password confirmation"  
64 - sisp_user.password_confirmation = $stdin.gets.strip  
65 -  
66 - puts "Password not changed! Enter rails console and make it manually" unless sisp_user.save  
67 - $stdin.echo = true 47 +
  48 + puts "User created with a random password. You can change in the console." unless sisp_user.save
68 else 49 else
69 puts "\nWARNING!!!!!!***********************************************" 50 puts "\nWARNING!!!!!!***********************************************"
70 puts "No user found with the given login '#{ENV['ADMINUSER']}'.... skipping" 51 puts "No user found with the given login '#{ENV['ADMINUSER']}'.... skipping"
@@ -104,7 +85,7 @@ namespace :sisp do @@ -104,7 +85,7 @@ namespace :sisp do
104 template = Community.create!(name: "Sisp", identifier: "sisp", is_template: true, environment: env) 85 template = Community.create!(name: "Sisp", identifier: "sisp", is_template: true, environment: env)
105 86
106 template.home_page = template.blog 87 template.home_page = template.blog
107 - template.update_layout_template("leftbar") 88 + template.update_layout_template("nosidebars")
108 template.save 89 template.save
109 90
110 create_template_blocks template 91 create_template_blocks template
@@ -134,10 +115,14 @@ namespace :sisp do @@ -134,10 +115,14 @@ namespace :sisp do
134 115
135 desc "Import sisp software from yml" 116 desc "Import sisp software from yml"
136 task :import_data => :environment do 117 task :import_data => :environment do
137 -  
138 $imported_data = YAML.load_file('plugins/software_communities/public/static/sisp-catalog.yml') 118 $imported_data = YAML.load_file('plugins/software_communities/public/static/sisp-catalog.yml')
139 $env = Environment.find_by_name("SISP") 119 $env = Environment.find_by_name("SISP")
  120 + unless $env
  121 + puts "SISP environment not FOUND!"
  122 + exit 1
  123 + end
140 124
  125 + $license = LicenseInfo.find_or_create_by_version("Another")
141 $software_category = $env.categories.find_or_create_by_name("Software") 126 $software_category = $env.categories.find_or_create_by_name("Software")
142 $software_category.environment = $env 127 $software_category.environment = $env
143 $software_category.save! 128 $software_category.save!
@@ -205,6 +190,7 @@ def create_sisp_software_info name, finality = "blank", acronym = "" @@ -205,6 +190,7 @@ def create_sisp_software_info name, finality = "blank", acronym = ""
205 end 190 end
206 191
207 software_info = SoftwareInfo.new 192 software_info = SoftwareInfo.new
  193 + software_info.license_info = $license
208 software_info.community = community 194 software_info.community = community
209 software_info.finality = finality 195 software_info.finality = finality
210 software_info.acronym = acronym 196 software_info.acronym = acronym