[file-store-4] updated git task

This commit is contained in:
Alexander Machehin 2012-11-12 15:17:25 +06:00
parent daa8bc72ee
commit 9a8e142d3f
2 changed files with 17 additions and 17 deletions

View File

@ -8,15 +8,14 @@ old_sources = if File.exist? abf_yml
else else
[] []
end 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://file-store.rosalinux.ru/api/v1/file_stores.json'
#url = 'http://localhost:3001/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 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 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 sha1 = Digest::SHA1.file(file).hexdigest
resp = JSON(RestClient.get url, :params => {:hash => sha1}) 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? unless resp['sha1_hash'].nil?
new_sources << " \"#{file}\": #{sha1}" new_sources << " \"#{file}\": #{sha1}"
FileUtils.rm_rf file 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 end
else else
raise "Response unknown!\n #{resp}" 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 end
sources = (old_sources | new_sources) sources = (old_sources | new_sources)
unless sources.empty? unless sources.empty?
Dir.chdir(ARGF.argv[1]) do # Need if in filter-branch
File.open(abf_yml, 'w') do |abf| File.open(abf_yml, 'w') do |abf|
abf.puts 'sources:' abf.puts 'sources:'
(old_sources | new_sources).sort.each {|line| abf.puts line} (old_sources | new_sources).sort.each {|line| abf.puts line}
end end
end end
end

View File

@ -1,13 +1,13 @@
#!/usr/bin/env ruby #!/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 'fileutils'
require 'digest' require 'digest'
token = '[CENSORED]' token = '[CENSORED]'
owners = ARGF.argv[2] || '[a-z0-9_]*' owners = ARGF.argv[3] || '[a-z0-9_]*'
project_names = ARGF.argv[3] || '[a-zA-Z0-9_\-\+\.]*' project_names = ARGF.argv[4] || '[a-zA-Z0-9_\-\+\.]*'
begin_time = Time.now begin_time = Time.now
pr_count = total_count = 0 pr_count = total_count = 0
@ -18,6 +18,7 @@ Dir.glob(owners).each do |owner|
Dir.glob(project_names).each do |project| Dir.glob(project_names).each do |project|
name_with_owner = "#{owner}/#{project.chomp('.git')}" name_with_owner = "#{owner}/#{project.chomp('.git')}"
project_path = "#{ARGF.argv[0]}/#{name_with_owner}.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 time, total_count = Time.now, total_count + 1
Dir.chdir project_path Dir.chdir project_path
project_stats = "#{name_with_owner}: #{total_count}" project_stats = "#{name_with_owner}: #{total_count}"
@ -25,7 +26,7 @@ Dir.glob(owners).each do |owner|
p "Skipping empty project #{project_stats}" p "Skipping empty project #{project_stats}"
else else
p "Start working with #{project_stats}" 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 FileUtils.rm_rf path
#-- hack for refs/heads (else git branch return only master) #-- hack for refs/heads (else git branch return only master)
system "git clone --mirror #{project_path} #{path}/.git" system "git clone --mirror #{project_path} #{path}/.git"
@ -33,7 +34,7 @@ Dir.glob(owners).each do |owner|
#-- #--
Dir.chdir(path) Dir.chdir(path)
archives_exists = false 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? archives_exists=true and break unless `git log --all --format='%H' -- *.#{ext}`.empty?
end 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" 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 !!! # 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." p "Worked with #{name_with_owner}: #{(Time.now - time).truncate} sec."
@ -49,7 +50,7 @@ Dir.glob(owners).each do |owner|
else else
p "Skipping project with no archives #{project_stats}" p "Skipping project with no archives #{project_stats}"
end end
`rm -rf #{path}` `rm -rf #{path} && cd #{dest_project_path} && git gc --prune=now`
end end
p '-------------' p '-------------'
end end