Refactoring : in tasks, replace puts by rake_puts (#4397)

Refactoring : in tasks, replace `puts` by `rake_puts`
This commit is contained in:
Pierre de La Morinerie 2019-10-09 10:17:09 +02:00 committed by GitHub
commit 51c194e253
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 28 additions and 24 deletions

View file

@ -1,3 +1,5 @@
require Rails.root.join("lib", "tasks", "task_helper")
namespace :cloudstorage do
task init: :environment do
os_config = (YAML.load_file(Fog.credentials_path))['default']
@ -28,7 +30,7 @@ namespace :cloudstorage do
if !(content.current_path.nil? || File.exist?(File.dirname(content.current_path) + '/uploaded'))
secure_token = SecureRandom.uuid
filename = "#{entry.class.to_s.underscore}-#{secure_token}#{File.extname(content.current_path)}"
puts "Uploading #{content.current_path}"
rake_puts "Uploading #{content.current_path}"
begin
@cont.create_object(filename, {}, File.open(content.current_path))
@ -39,7 +41,7 @@ namespace :cloudstorage do
entry.update_column(c == Procedure ? :logo : :content, filename)
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token)
rescue Errno::ENOENT
puts "ERROR: #{content.current_path} does not exist!"
rake_puts "ERROR: #{content.current_path} does not exist!"
File.open('upload_errors.report', "a+") { |f| f.write(content.current_path) }
error_count += 1
end
@ -51,15 +53,15 @@ namespace :cloudstorage do
entry.update_column(c == Procedure ? :logo : :content, filename)
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token)
puts "RESTORE IN DATABASE: #{filename} "
rake_puts "RESTORE IN DATABASE: #{filename} "
elsif content.current_path.present?
puts "Skipping #{content.current_path}"
rake_puts "Skipping #{content.current_path}"
end
end
end
end
puts "There were #{error_count} errors while uploading files. See upload_errors.report file for details."
rake_puts "There were #{error_count} errors while uploading files. See upload_errors.report file for details."
puts 'Enf of migration'
end
@ -77,7 +79,7 @@ namespace :cloudstorage do
entry.update_column(c == Procedure ? :logo : :content, previous_filename)
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, nil)
puts "restoring #{content.current_path} db data to #{previous_filename}"
rake_puts "restoring #{content.current_path} db data to #{previous_filename}"
@cont.delete_object(File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "r").read)
@ -95,7 +97,7 @@ namespace :cloudstorage do
Rake::Task['cloudstorage:init'].invoke
@cont.objects.each do |object|
puts "Removing #{object}"
rake_puts "Removing #{object}"
@cont.delete_object(object)
end
end

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: fix_email_templates_subjects'
task fix_email_templates_subjects: :environment do
puts "Running deploy task 'fix_email_templates_subjects'"
rake_puts "Running deploy task 'fix_email_templates_subjects'"
klasses = [
Mails::ClosedMail,

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: migrate_types_de_champ_options_to_json'
task migrate_types_de_champ_options_to_json: :environment do
puts "Running deploy task 'migrate_types_de_champ_options_to_json'"
rake_puts "Running deploy task 'migrate_types_de_champ_options_to_json'"
dirty_tdcs = TypeDeChamp.where.not(options: nil)
progress = ProgressReport.new(dirty_tdcs.count)

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: fix_macedonia'
task fix_macedonia: :environment do
puts "Running deploy task 'fix_macedonia'"
rake_puts "Running deploy task 'fix_macedonia'"
# Put your task implementation HERE.

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: create_default_path_for_brouillons'
task create_default_path_for_brouillons: :environment do
puts "Running deploy task 'create_default_path_for_brouillons'"
rake_puts "Running deploy task 'create_default_path_for_brouillons'"
# Put your task implementation HERE.

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: migrate_mail_body_to_actiontext'
task migrate_mail_body_to_actiontext: :environment do
puts "Running deploy task 'migrate_mail_body_to_actiontext'"
rake_puts "Running deploy task 'migrate_mail_body_to_actiontext'"
# Put your task implementation HERE.

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: add_missing_dossier_id_to_repetitions'
task add_missing_dossier_id_to_repetitions: :environment do
puts "Running deploy task 'add_missing_dossier_id_to_repetitions'"
rake_puts "Running deploy task 'add_missing_dossier_id_to_repetitions'"
champs = Champ.where(dossier_id: nil)
progress = ProgressReport.new(champs.count)

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: set_declarative_procedures'
task set_declarative_procedures: :environment do
puts "Running deploy task 'set_declarative_procedures'"
rake_puts "Running deploy task 'set_declarative_procedures'"
Delayed::Job.where.not(cron: nil).find_each do |job|
job_data = YAML.load_dj(job.handler).job_data

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: create_dummy_paths_for_archived_and_hidden_procedures'
task create_dummy_paths_for_archived_and_hidden_procedures: :environment do
puts "Running deploy task 'create_dummy_paths_for_archived_procedures'"
rake_puts "Running deploy task 'create_dummy_paths_for_archived_procedures'"
Procedure.unscoped.archivees.where(path: nil).each do |p|
p.update_column(:path, SecureRandom.uuid)

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: migrate_geo_area_data'
task migrate_geo_area_data: :environment do
puts "Running deploy task 'migrate_geo_area_data'"
rake_puts "Running deploy task 'migrate_geo_area_data'"
progress = ProgressReport.new(Champs::CarteChamp.count)

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: rename_active_storage_attachments'
task rename_active_storage_attachments: :environment do
puts "Running deploy task 'rename_active_storage_attachments'"
rake_puts "Running deploy task 'rename_active_storage_attachments'"
ActiveStorage::Attachment.where(name: 'logo_active_storage').update_all(name: 'logo')
ActiveStorage::Attachment.where(name: 'signature_active_storage').update_all(name: 'signature')

View file

@ -1,7 +1,7 @@
namespace :after_party do
desc 'Deployment task: migrate_flipflop_to_flipper'
task migrate_flipflop_to_flipper: :environment do
puts "Running deploy task 'migrate_flipflop_to_flipper'"
rake_puts "Running deploy task 'migrate_flipflop_to_flipper'"
Instructeur.includes(:user).find_each do |instructeur|
if instructeur.features['download_as_zip_enabled']

View file

@ -1,9 +1,11 @@
require Rails.root.join("lib", "tasks", "task_helper")
namespace :superadmin do
desc <<~EOD
List all super-admins
EOD
task list: :environment do
puts "All Administrations:"
rake_puts "All Administrations:"
Administration.all.pluck(:email).each do |a|
puts a
end
@ -15,13 +17,13 @@ namespace :superadmin do
task :create, [:email] => :environment do |_t, args|
email = args[:email]
puts "Creating Administration for #{email}"
rake_puts "Creating Administration for #{email}"
a = Administration.new(email: email, password: Devise.friendly_token[0, 20])
if a.save
puts "#{a.email} created"
rake_puts "#{a.email} created"
else
puts "An error occured: #{a.errors.full_messages}"
rake_puts "An error occured: #{a.errors.full_messages}"
end
end
@ -30,9 +32,9 @@ namespace :superadmin do
EOD
task :delete, [:email] => :environment do |_t, args|
email = args[:email]
puts "Deleting Administration for #{email}"
rake_puts "Deleting Administration for #{email}"
a = Administration.find_by(email: email)
a.destroy
puts "#{a.email} deleted"
rake_puts "#{a.email} deleted"
end
end