[file-store-4] updated git task
This commit is contained in:
parent
daa8bc72ee
commit
9a8e142d3f
|
@ -8,15 +8,14 @@ old_sources = if File.exist? abf_yml
|
|||
else
|
||||
[]
|
||||
end
|
||||
MAX_SIZE = 2 * 1024 * 1024 # 2.megabytes
|
||||
#MAX_SIZE = 2 * 1024 * 1024 # 2.megabytes
|
||||
url = 'http://file-store.rosalinux.ru/api/v1/file_stores.json'
|
||||
#url = 'http://localhost:3001/api/v1/file_stores.json'
|
||||
rclient = RestClient::Resource.new(url, :user => ARGF.argv[0]) # user auth token
|
||||
|
||||
Dir.glob("*.{tar\.bz2,tar\.gz,bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z}").uniq.sort.each do |file|
|
||||
Dir.glob("*.{tar\.bz2,tar\.gz,bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z, tar\.xz}").uniq.sort.each do |file|
|
||||
begin
|
||||
#puts " work with file \"#{file}\""
|
||||
next if File.size(file) < MAX_SIZE
|
||||
#next if File.size(file) < MAX_SIZE
|
||||
|
||||
sha1 = Digest::SHA1.file(file).hexdigest
|
||||
resp = JSON(RestClient.get url, :params => {:hash => sha1})
|
||||
|
@ -31,7 +30,9 @@ Dir.glob("*.{tar\.bz2,tar\.gz,bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z}").uniq.sort.each
|
|||
unless resp['sha1_hash'].nil?
|
||||
new_sources << " \"#{file}\": #{sha1}"
|
||||
FileUtils.rm_rf file
|
||||
puts " upload file \"#{file}\" to the file-store"
|
||||
p " upload file \"#{file}\" to the file-store"
|
||||
else
|
||||
p " !Failed to upload file \"#{file}\" to the file-store!"
|
||||
end
|
||||
else
|
||||
raise "Response unknown!\n #{resp}"
|
||||
|
@ -43,10 +44,8 @@ Dir.glob("*.{tar\.bz2,tar\.gz,bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z}").uniq.sort.each
|
|||
end
|
||||
sources = (old_sources | new_sources)
|
||||
unless sources.empty?
|
||||
Dir.chdir(ARGF.argv[1]) do # Need if in filter-branch
|
||||
File.open(abf_yml, 'w') do |abf|
|
||||
abf.puts 'sources:'
|
||||
(old_sources | new_sources).sort.each {|line| abf.puts line}
|
||||
end
|
||||
File.open(abf_yml, 'w') do |abf|
|
||||
abf.puts 'sources:'
|
||||
(old_sources | new_sources).sort.each {|line| abf.puts line}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#!/usr/bin/env ruby
|
||||
# git_dir_projects[0] clone_path[1] owner[2] project_name[3]
|
||||
# git_dir_projects[0] dest_git_path[1] clone_path[2] owner[3] project_name[4]
|
||||
|
||||
require 'fileutils'
|
||||
require 'digest'
|
||||
|
||||
token = '[CENSORED]'
|
||||
|
||||
owners = ARGF.argv[2] || '[a-z0-9_]*'
|
||||
project_names = ARGF.argv[3] || '[a-zA-Z0-9_\-\+\.]*'
|
||||
owners = ARGF.argv[3] || '[a-z0-9_]*'
|
||||
project_names = ARGF.argv[4] || '[a-zA-Z0-9_\-\+\.]*'
|
||||
|
||||
begin_time = Time.now
|
||||
pr_count = total_count = 0
|
||||
|
@ -18,6 +18,7 @@ Dir.glob(owners).each do |owner|
|
|||
Dir.glob(project_names).each do |project|
|
||||
name_with_owner = "#{owner}/#{project.chomp('.git')}"
|
||||
project_path = "#{ARGF.argv[0]}/#{name_with_owner}.git"
|
||||
dest_project_path = "#{ARGF.argv[1]}/#{name_with_owner}.git"
|
||||
time, total_count = Time.now, total_count + 1
|
||||
Dir.chdir project_path
|
||||
project_stats = "#{name_with_owner}: #{total_count}"
|
||||
|
@ -25,7 +26,7 @@ Dir.glob(owners).each do |owner|
|
|||
p "Skipping empty project #{project_stats}"
|
||||
else
|
||||
p "Start working with #{project_stats}"
|
||||
path = "#{ARGF.argv[1].chomp('/')}/repos/#{name_with_owner}"
|
||||
path = "#{ARGF.argv[2].chomp('/')}/repos/#{name_with_owner}"
|
||||
FileUtils.rm_rf path
|
||||
#-- hack for refs/heads (else git branch return only master)
|
||||
system "git clone --mirror #{project_path} #{path}/.git"
|
||||
|
@ -33,7 +34,7 @@ Dir.glob(owners).each do |owner|
|
|||
#--
|
||||
Dir.chdir(path)
|
||||
archives_exists = false
|
||||
%w(tar.bz2 tar.gz bz2 rar gz tar tbz2 tgz zip Z 7z).each do |ext|
|
||||
%w(tar.bz2 tar.gz bz2 rar gz tar tbz2 tgz zip Z 7z tar.xz).each do |ext|
|
||||
archives_exists=true and break unless `git log --all --format='%H' -- *.#{ext}`.empty?
|
||||
end
|
||||
|
||||
|
@ -41,7 +42,7 @@ Dir.glob(owners).each do |owner|
|
|||
system "git filter-branch -d /dev/shm/git_task --tree-filter \"/home/rosa/git_task/file-store.rb #{token} #{path}\" --prune-empty --tag-name-filter cat -- --all"
|
||||
#####
|
||||
# This is dangerous !!!
|
||||
system "rm -rf #{project_path} && git clone --bare #{path} #{project_path}"
|
||||
system "rm -rf #{dest_project_path} && git clone --bare #{path} #{dest_project_path}"
|
||||
#####
|
||||
|
||||
p "Worked with #{name_with_owner}: #{(Time.now - time).truncate} sec."
|
||||
|
@ -49,7 +50,7 @@ Dir.glob(owners).each do |owner|
|
|||
else
|
||||
p "Skipping project with no archives #{project_stats}"
|
||||
end
|
||||
`rm -rf #{path}`
|
||||
`rm -rf #{path} && cd #{dest_project_path} && git gc --prune=now`
|
||||
end
|
||||
p '-------------'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue