[refs #789] fixed hardcoding file-store url

This commit is contained in:
Alexander Machehin 2012-12-20 17:53:25 +06:00
parent e138d05fc3
commit ee38193efc
5 changed files with 10 additions and 8 deletions

View File

@ -13,7 +13,7 @@
%tr %tr
- sha1 = item['sha1'] - sha1 = item['sha1']
- filename = item['file_name'] - filename = item['file_name']
- url = "#{APP_CONFIG['file_store_url']}/#{sha1}" - url = "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
- url << '.log?show=true' if filename =~ /.*\.(log|txt)$/ - url << '.log?show=true' if filename =~ /.*\.(log|txt)$/
%td= link_to filename, url %td= link_to filename, url
%td= sha1 %td= sha1

View File

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# argv[0] user token; argv[1] url to file-store
require 'json' require 'json'
require 'rest-client' require 'rest-client'
@ -9,8 +10,7 @@ old_sources = if File.exist? abf_yml
[] []
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 = "#{ARGF.argv[1]}/api/v1"
#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("*.{bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z,xz,lzma}").uniq.sort.each do |file| Dir.glob("*.{bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z,xz,lzma}").uniq.sort.each do |file|
@ -18,7 +18,7 @@ Dir.glob("*.{bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z,xz,lzma}").uniq.sort.each do |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}/file_stores", :params => {:hash => sha1})
if resp[0].respond_to?('[]') && resp[0]['file_name'] && resp[0]['sha1_hash'] if resp[0].respond_to?('[]') && resp[0]['file_name'] && resp[0]['sha1_hash']
# file already exists at file-store # file already exists at file-store
new_sources << " \"#{file}\": #{sha1}" new_sources << " \"#{file}\": #{sha1}"
@ -26,7 +26,7 @@ Dir.glob("*.{bz2,rar,gz,tar,tbz2,tgz,zip,Z,7z,xz,lzma}").uniq.sort.each do |file
puts " file \"#{file}\" already exists in the file-store" puts " file \"#{file}\" already exists in the file-store"
elsif resp == [] elsif resp == []
# try to put file at file-store # try to put file at file-store
resp = JSON `curl --user #{ARGF.argv[0]}: -POST -F "file_store[file]=@#{file}" http://file-store.rosalinux.ru/api/v1/upload` resp = JSON `curl --user #{ARGF.argv[0]}: -POST -F "file_store[file]=@#{file}" #{url}/upload`
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

View File

@ -6,6 +6,7 @@ git_path=$2
git_branch=$3 git_branch=$3
script=$4 script=$4
token=$5 token=$5
file_store_url=$6
name=$(rpm -q --qf '[%{Name}]' -p $srpm_path) name=$(rpm -q --qf '[%{Name}]' -p $srpm_path)
version=$(rpm -q --qf '[%{Version}-%{Release}]' -p $srpm_path) version=$(rpm -q --qf '[%{Version}-%{Release}]' -p $srpm_path)
tmp_dir=/tmp/$name-$version-$RANDOM tmp_dir=/tmp/$name-$version-$RANDOM
@ -32,7 +33,7 @@ cpio -idv < srpm.cpio
rm -f srpm.cpio rm -f srpm.cpio
# Remove archives # Remove archives
$script $token $script $token $file_store_url
# Commit and push changes # Commit and push changes
git add -A . git add -A .

View File

@ -53,7 +53,7 @@ module AbfWorker
select{ |r| r['file_name'] !~ /.*\.log$/ }.first select{ |r| r['file_name'] !~ /.*\.log$/ }.first
sha1 = container ? container['sha1'] : nil sha1 = container ? container['sha1'] : nil
if sha1 if sha1
bl.container_path = "#{APP_CONFIG['file_store_url']}/#{sha1}" bl.container_path = "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
bl.save! bl.save!
end end
update_results(bl, options) update_results(bl, options)

View File

@ -93,7 +93,8 @@ module Modules
def import_srpm(srpm_path = srpm.path, branch_name = 'import') def import_srpm(srpm_path = srpm.path, branch_name = 'import')
token = User.find_by_uname('rosa_system').authentication_token token = User.find_by_uname('rosa_system').authentication_token
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm_path} #{path} #{branch_name} #{Rails.root.join('bin', 'file-store.rb')} #{token} >> /dev/null 2>&1") opts = [srpm_path, path, branch_name, Rails.root.join('bin', 'file-store.rb'), token, APP_CONFIG['file_store_url']].join(' ')
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{opts} >> /dev/null 2>&1")
end end
protected protected