77 lines
4.3 KiB
Ruby
77 lines
4.3 KiB
Ruby
require "yaml"
|
|
module PersonalPluginGenerator
|
|
class Engine < ::Rails::Engine
|
|
initializer "personal_plugin_generator" do
|
|
begin
|
|
OrbitApp.registration "PersonalPluginGenerator", :type => "OrbitMemberModule" do
|
|
base_url File.expand_path File.dirname(__FILE__)
|
|
categorizable
|
|
authorizable
|
|
side_bar do
|
|
head_label_i18n 'module_name.personal_plugin_generator', icon_class: "icons-graduation"
|
|
available_for "users"
|
|
active_for_controllers (['admin/personal_plugin_fields'])
|
|
head_link_path "admin_personal_plugin_fields_path"
|
|
context_link 'personal_plugin_generator.personal_plugin_generate',
|
|
:link_path=>"admin_personal_plugin_fields_path" ,
|
|
:priority=>1,
|
|
:active_for_action=>{'admin/personal_plugin_fields'=>'index'},
|
|
:available_for => 'users'
|
|
end
|
|
end
|
|
rescue
|
|
OrbitApp.registration "PersonalPluginGenerator", :type => "ModuleApp" do
|
|
base_url File.expand_path File.dirname(__FILE__)
|
|
categorizable
|
|
authorizable
|
|
side_bar do
|
|
head_label_i18n 'module_name.personal_plugin_generater', icon_class: "icons-graduation"
|
|
available_for "users"
|
|
active_for_controllers (['admin/personal_plugin_fields'])
|
|
head_link_path "admin_personal_plugin_fields_path"
|
|
context_link 'personal_plugin_generator.personal_plugin_generate',
|
|
:link_path=>"admin_personal_plugin_fields_path" ,
|
|
:priority=>1,
|
|
:active_for_action=>{'admin/personal_plugin_fields'=>'index'},
|
|
:available_for => 'users'
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
def self.git_reset(commit,type)
|
|
ubuntu_version = `lsb_release -a | grep Release`.scan(/\d.*\d/)[0]
|
|
git = 'git'
|
|
if Float(ubuntu_version) <= 14.04 && Float(%x[git --version].scan(/\d.\d/)[0]) < 1.9
|
|
if %x[uname -m].scan('64').count !=0
|
|
cmd0 = system("wget https://ruling.digital/uploads/asset/git_1.9.1-1_amd64.deb && dpkg -x git_1.9.1-1_amd64.deb ./git_1.9.1")
|
|
else
|
|
cmd0 = system("wget https://ruling.digital/uploads/asset/git_1.9.1-1_i386.deb && dpkg -x git_1.9.1-1_i386.deb ./git_1.9.1")
|
|
end
|
|
git = 'git_1.9.1/usr/bin/git'
|
|
end
|
|
%x(cd #{ENV['PWD']} && #{git} fetch origin)
|
|
@branch = %x(cd #{ENV['PWD']} && #{git} rev-parse --abbrev-ref HEAD).gsub("\n","")
|
|
new_commit_id = %x(cd #{ENV['PWD']} && #{git} log #{@branch}..origin/#{@branch} --pretty=format:"%H")
|
|
new_updates = %x(cd #{ENV['PWD']} && #{git} log #{@branch}..origin/#{@branch} --pretty=format:"%ad' , '%s" --date=short).split("\n").map{|log| log.gsub("'","")}
|
|
if new_commit_id.present?
|
|
git_add_except_public = Dir['*'].select{|v| v!= 'public' && v!= 'log' && v != 'dump' && v != 'tmp'}.collect do |v|
|
|
"#{git} add -f --all --ignore-errors '#{v}'"
|
|
end.join(' ; ')
|
|
git_add_custom = (Dir['*'].select{|v| v !='app' && v != 'lib' && v != 'config' && v != 'public' && v!= 'log' && v != 'dump' && v != 'tmp'} + ['app/templates','config/mongoid.yml','config/extra_lang.txt']).collect do |v|
|
|
"#{git} add -f --all --ignore-errors '#{v}'"
|
|
end.join(' ; ')
|
|
git_restore = "#{git} checkout ."
|
|
time_now = Time.now.strftime('%Y_%m_%d_%H_%M')
|
|
if %x[#{git} config user.name].empty?
|
|
%x[#{git} config --global user.name "rulingcom"]
|
|
end
|
|
if %x[#{git} config user.email].empty?
|
|
%x[#{git} config --global user.email "orbit@rulingcom.com"]
|
|
end
|
|
puts "Updating orbit-kernel..."
|
|
system("cd #{ENV['PWD']} && bash -l -c \"#{git_add_except_public} ; #{git} commit -m auto_backup_before_#{type}_#{time_now} --allow-empty && #{git} reset #{commit} --mixed ; #{git_add_custom} ; #{git_restore} ; #{git_add_except_public} ; #{git} clean -f -- app/models ; #{git} commit -m complete_#{type}_#{time_now} --allow-empty\" > /dev/null")
|
|
puts "Updated! " + new_updates.first.to_s
|
|
end
|
|
end
|
|
end |