Fix some deprecated for ruby 2.7.

This commit is contained in:
BoHung Chiu 2022-08-30 10:51:32 +08:00
parent bfc4014bd0
commit 3c68b65803
2 changed files with 44 additions and 14 deletions

View File

@ -7,6 +7,20 @@ require 'yaml'
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag
env_pwd = ENV['PWD']
begin
require ::File.expand_path('app/helpers/bundler_helper.rb', env_pwd)
extend BundlerHelper
rescue LoadError
def bundler_with_clean_env
if block_given?
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env(&Proc.new)
else
Bundler.with_clean_env(&Proc.new)
end
end
end
end
if File.exist?("#{env_pwd}/app/models/google.rb")
system("rm -f #{env_pwd}/app/models/google.rb")
end
@ -17,11 +31,11 @@ if bundle_update_flag
new_gemfile_text = File.read(app_path+'/temp_file/Gemfile')
old_gemfile_text = File.read(env_pwd+'/Gemfile')
check_texts = ['@import "../../bootstrap/variables";',".response-content {\n justify-self: auto;\n}\n"]
git_url = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git config --get remote.origin.url].split("\n")[0]}
git_remote = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git remote].split("\n")[0]}
git_url = bundler_with_clean_env{%x[cd '#{env_pwd}' && git config --get remote.origin.url].split("\n")[0]}
git_remote = bundler_with_clean_env{%x[cd '#{env_pwd}' && git remote].split("\n")[0]}
if git_url != 'http://ruling.digital/git'
puts 'changing remote url'
Bundler.with_clean_env{system("cd #{env_pwd} && git remote set-url #{git_remote} http://ruling.digital/git")}
bundler_with_clean_env{system("cd #{env_pwd} && git remote set-url #{git_remote} http://ruling.digital/git")}
end
default_announcement_widget_info = JSON.parse(File.read("#{app_path}/modules/announcement/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
all_template.each do |folder|
@ -99,7 +113,7 @@ if bundle_update_flag
end
begin
puts "updating announcement show page"
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/announcement/show.html.erb #{folder}modules/announcement/show.html.erb]}
bundler_with_clean_env{%x[cp -f #{app_path}/modules/announcement/show.html.erb #{folder}modules/announcement/show.html.erb]}
rescue
puts "There has some error in updating announcement show page"
end
@ -131,9 +145,9 @@ if bundle_update_flag
copy_h["name"][locale] = copy_h["name"][locale].sub(/\d+/){|ff| last_index.to_s}
end
widget_info << copy_h
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/announcement/_#{h["filename"]}.html.erb #{folder}modules/announcement/_#{copy_h["filename"]}.html.erb]}
bundler_with_clean_env{%x[cp -f #{app_path}/modules/announcement/_#{h["filename"]}.html.erb #{folder}modules/announcement/_#{copy_h["filename"]}.html.erb]}
elsif h["force_cover"] == "true"
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/announcement/_#{h["filename"]}.html.erb #{folder}modules/announcement/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
bundler_with_clean_env{%x[cp -f #{app_path}/modules/announcement/_#{h["filename"]}.html.erb #{folder}modules/announcement/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
end
end
if update_flag
@ -146,7 +160,7 @@ if bundle_update_flag
end
File.open(info_json_file,"w+"){|f| f.write(info_json)}
end
Bundler.with_clean_env{%x[cp -rn #{app_path}/modules/announcement/thumbs/* #{folder}modules/announcement/thumbs/.]}
bundler_with_clean_env{%x[cp -rn #{app_path}/modules/announcement/thumbs/* #{folder}modules/announcement/thumbs/.]}
end
end
rescue => e
@ -170,8 +184,8 @@ if bundle_update_flag
end
end
end
Bundler.with_clean_env{%x[cp -f '#{env_pwd}'/Gemfile '#{env_pwd}'/Gemfile.bak123]}
Bundler.with_clean_env{%x[cp -f '#{app_path}'/temp_file/Gemfile '#{env_pwd}'/Gemfile]}
bundler_with_clean_env{%x[cp -f '#{env_pwd}'/Gemfile '#{env_pwd}'/Gemfile.bak123]}
bundler_with_clean_env{%x[cp -f '#{app_path}'/temp_file/Gemfile '#{env_pwd}'/Gemfile]}
check_version = %x[cd #{env_pwd} && git rev-list `git rev-parse --abbrev-ref HEAD` | grep 2f23511469505bd114df2c863a477a8730bcdefa]
if check_version.strip != '' #update mongoid version
command4 = ""
@ -190,7 +204,7 @@ if bundle_update_flag
dir_name = env_pwd.split('/')[-1]
watch_dog = %x[screen -ls auto_reopen_#{dir_name}]
if watch_dog.scan("auto_reopen_#{dir_name}").count != 0
Bundler.with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
bundler_with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
end
if %x[ruby -v].scan(/\d\.\d\.\d/)[0] == '2.1.3'
install_cmd = 'rvm install 2.1.10 && rvm use default 2.1.10;'
@ -227,7 +241,7 @@ if bundle_update_flag
restart_cmd = "UNICORN_PID=\"`fuser tmp/pids/unicorn.sock tmp/sockets/unicorn.sock tmp/unicorn.sock` `cat tmp/pids/unicorn.pid `\" && kill -s TERM $UNICORN_PID ; while (kill -0 $UNICORN_PID > /dev/null 2>&1) ; do printf '.' && sleep 1 ; done ; unset UNICORN_FD; bundle exec unicorn_rails -c config/unicorn.rb -D -E #{mode}"
a = Thread.start do
Bundler.with_clean_env do
bundler_with_clean_env do
puts env_pwd
puts mode
exec("cd #{env_pwd} && env -i HOME=\"$HOME\" bash -l -c \"#{all_command}\" ;screen -d -m -S auto_reopen_#{dir_name} bash -c \"#{use_cmd} #{restart_cmd};#{watch_dog_cmd}\" ")
@ -242,7 +256,7 @@ if bundle_update_flag
dir_name = env_pwd.split('/')[-1]
watch_dog = %x[screen -ls auto_reopen_#{dir_name}]
if watch_dog.scan("auto_reopen_#{dir_name}").count != 0
Bundler.with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
bundler_with_clean_env{%x[screen -ls | grep auto_reopen_#{dir_name} | cut -d. -f1 | awk '{print $1}' | xargs kill]}
end
#system("cp -rf #{app_path}/temp_file/app #{env_pwd}")
end

View File

@ -1,8 +1,24 @@
begin
require ::File.expand_path('../app/helpers/bundler_helper.rb', __FILE__)
extend BundlerHelper
rescue LoadError
def bundler_with_clean_env
if block_given?
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env(&Proc.new)
else
Bundler.with_clean_env(&Proc.new)
end
end
end
end
source 'https://rubygems.org'
#update all site!!!!!!!!
if $0.to_s.scan('bundle').length==0
Bundler.with_clean_env{
flag = system("bundle show announcement")
self.bundler_with_clean_env{
# Deprecated: bundle show => bundle list, bundle show gem => bundle info gem --path
# Tested: bundler >= 1.17 will have bundle info and bundle list
flag = system("bundle info announcement --path >/dev/null 2>&1 || bundle show announcement >/dev/null 2>&1")
system("bundle install") if !flag
}
end