rake 任务导出版本库

dev_bj
jingquan huang 5 years ago
parent 40f8b52ce8
commit a45038a1e7

@ -0,0 +1,43 @@
namespace :homework do
def tran_base64_decode64 str
if str.blank?
str
else
s_size = str.size % 4
if s_size != 0
str += "=" * (4 - s_size)
end
Base64.decode64(str.tr("-_", "+/")).force_encoding("utf-8")
end
end
task :gitfiledown => :environment do
begin
puts ENV['args']
system("tmp/homework_file") if File.exist?("tmp/homework_file")
homework_common = HomeworkCommon.find(ENV['args'])
student_works = homework_common.student_works
student_works.each do |sw|
username = sw.user.try(:show_real_name)
myshixun = sw.try(:myshixun)
puts myshixun.try(:gpid)
if myshixun.try(:gpid)
content = g.files(myshixun.gpid, "PL/PL.cpp", "master").try(:content)
tran_content = tran_base64_decode64(content)
path = "tmp/homework_file/#{username}"
FileUtils.mkdir_p(path) unless File.exist?(path)
system("cd #{path}; touch PL.cpp")
aFile = File.new("#{path}/PL.cpp", "r+")
if aFile
aFile.syswrite(tran_content)
else
puts "Unable to open file!"
end
end
end
rescue Exception => e
Rails.logger.error(e.message)
end
end
end
Loading…
Cancel
Save