[refs file-store-4] upload to file-store
This commit is contained in:
parent
6a50e18932
commit
84920c358a
2
Gemfile
2
Gemfile
|
@ -53,6 +53,8 @@ gem 'jquery-rails', '~> 2.0.2'
|
||||||
gem 'ruby-haml-js', '~> 0.0.3'
|
gem 'ruby-haml-js', '~> 0.0.3'
|
||||||
gem 'rails-backbone', '~> 0.7.2'
|
gem 'rails-backbone', '~> 0.7.2'
|
||||||
|
|
||||||
|
gem 'rest-client', '~> 1.6.6'
|
||||||
|
|
||||||
group :assets do
|
group :assets do
|
||||||
gem 'sass-rails', '~> 3.2.5'
|
gem 'sass-rails', '~> 3.2.5'
|
||||||
gem 'coffee-rails', '~> 3.2.2'
|
gem 'coffee-rails', '~> 3.2.2'
|
||||||
|
|
|
@ -269,6 +269,8 @@ GEM
|
||||||
uuid (~> 2.3)
|
uuid (~> 2.3)
|
||||||
resque_mailer (2.1.0)
|
resque_mailer (2.1.0)
|
||||||
actionmailer (~> 3.0)
|
actionmailer (~> 3.0)
|
||||||
|
rest-client (1.6.7)
|
||||||
|
mime-types (>= 1.16)
|
||||||
rr (1.0.4)
|
rr (1.0.4)
|
||||||
rspec (2.11.0)
|
rspec (2.11.0)
|
||||||
rspec-core (~> 2.11.0)
|
rspec-core (~> 2.11.0)
|
||||||
|
@ -404,6 +406,7 @@ DEPENDENCIES
|
||||||
resque (~> 1.21.0)
|
resque (~> 1.21.0)
|
||||||
resque-status (~> 0.3.3)
|
resque-status (~> 0.3.3)
|
||||||
resque_mailer (~> 2.1.0)
|
resque_mailer (~> 2.1.0)
|
||||||
|
rest-client (~> 1.6.6)
|
||||||
rr (~> 1.0.4)
|
rr (~> 1.0.4)
|
||||||
rspec-rails (~> 2.11.0)
|
rspec-rails (~> 2.11.0)
|
||||||
ruby-haml-js (~> 0.0.3)
|
ruby-haml-js (~> 0.0.3)
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
pwd=`pwd`
|
pwd=`pwd`
|
||||||
command="$(pwd)/calc_sha_help $2"
|
command="$(pwd)/calc_sha_help $2"
|
||||||
cd $1
|
cd $1
|
||||||
git filter-branch --tree-filter "$pwd/bin/calc_sha_help $2" --prune-empty --tag-name-filter cat -- --all
|
git filter-branch --tree-filter "$pwd/bin/file-store" --prune-empty --tag-name-filter cat -- --all
|
||||||
cd ..
|
cd ..
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
find . -regex ".*\.\(tar\.bz2\|tar\.gz\|bz2\|rar\|gz\|tar\|tbz2\|tgz\|zip\|Z\|7z\)" -size +2M | sort | while read file;
|
|
||||||
do
|
|
||||||
res=`sha1sum "$file"`
|
|
||||||
sha=( $res )
|
|
||||||
if [ -d "$1/$sha" ]
|
|
||||||
then
|
|
||||||
filename=`ls "$1/$sha"`
|
|
||||||
else
|
|
||||||
filename=${file:2}
|
|
||||||
mkdir -p $1/$sha
|
|
||||||
cp -n "$file" "$1/$sha/"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo " \"${filename}\": $sha" >> abf_temp_temp.yml
|
|
||||||
rm -rf "$file"
|
|
||||||
done
|
|
||||||
if [ -e abf_temp_temp.yml ]
|
|
||||||
then
|
|
||||||
echo 'sources:' > abf.yml
|
|
||||||
cat abf_temp_temp.yml >> abf.yml
|
|
||||||
rm -rf abf_temp_temp.yml
|
|
||||||
fi
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
require 'json'
|
||||||
|
require 'rest-client'
|
||||||
|
|
||||||
|
abf_yml, new_sources = 'abf.yml', []
|
||||||
|
old_sources = if File.exist? abf_yml
|
||||||
|
File.read(abf_yml).split("\n").reject {|line| line =~ /sources/}
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
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'
|
||||||
|
user, pass = ARGF.argv[0] || 'CENSORED', ARGF.argv[1] || 'CENSORED' # FIXME
|
||||||
|
rclient = RestClient::Resource.new(url, user, pass)
|
||||||
|
|
||||||
|
Dir.glob("*.{tar\.bz2,tar\.gz,bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z}").uniq.sort.each do |file|
|
||||||
|
begin
|
||||||
|
puts "Work with file \"#{file}\""
|
||||||
|
next if File.size(file) < MAX_SIZE
|
||||||
|
|
||||||
|
sha1 = Digest::SHA1.file(file).hexdigest
|
||||||
|
resp = JSON(RestClient.get url, :params => {:hash => sha1})
|
||||||
|
if resp[0].respond_to?('[]') && resp[0]['file_name'] && resp[0]['sha1_hash']
|
||||||
|
# file already exists at file-store
|
||||||
|
new_sources << " \"#{file}\": #{sha1}"
|
||||||
|
FileUtils.rm_rf file
|
||||||
|
elsif resp == []
|
||||||
|
# try to put file at file-store
|
||||||
|
resp = JSON(rclient.post :file_store => {:file => File.new(file, 'rb')})
|
||||||
|
unless resp['sha1_hash'].nil?
|
||||||
|
new_sources << " \"#{file}\" #{sha1}"
|
||||||
|
FileUtils.rm_rf file
|
||||||
|
end
|
||||||
|
else
|
||||||
|
raise "Response unknown!\n #{resp}"
|
||||||
|
end
|
||||||
|
|
||||||
|
#rescue => e
|
||||||
|
# e.response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
File.open(abf_yml, 'w') do |abf|
|
||||||
|
abf.puts 'sources:'
|
||||||
|
(old_sources | new_sources).sort.each {|line| abf.puts line}
|
||||||
|
end
|
Loading…
Reference in New Issue