right_scraper 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/right_scraper/scraper.rb +13 -2
- data/lib/right_scraper/scraper_base.rb +23 -9
- data/lib/right_scraper/scrapers/download_scraper.rb +3 -3
- data/lib/right_scraper/scrapers/git_scraper.rb +6 -6
- data/lib/right_scraper/scrapers/svn_scraper.rb +5 -5
- data/right_scraper.gemspec +1 -1
- data/spec/download_scraper_spec.rb +2 -2
- data/spec/git_scraper_spec.rb +4 -4
- data/spec/scraper_base_spec.rb +6 -1
- data/spec/scraper_spec.rb +4 -4
- data/spec/svn_scraper_spec.rb +4 -4
- metadata +2 -2
@@ -34,7 +34,7 @@ module RightScale
|
|
34
34
|
|
35
35
|
# (String) Path to directory where remote repository was downloaded
|
36
36
|
# Note: This will be a subfolder of the scrape directory (directory given to initializer)
|
37
|
-
attr_reader :
|
37
|
+
attr_reader :last_repo_dir
|
38
38
|
|
39
39
|
# Initialize scrape destination directory
|
40
40
|
#
|
@@ -72,9 +72,20 @@ module RightScale
|
|
72
72
|
raise "Invalid repository type" unless SCRAPERS.include?(repo.repo_type)
|
73
73
|
@scraper = @scrapers[repo.repo_type] ||= SCRAPERS[repo.repo_type].new(@scrape_dir)
|
74
74
|
@scraper.scrape(repo, &callback)
|
75
|
-
@
|
75
|
+
@last_repo_dir = @scraper.current_repo_dir
|
76
76
|
@scraper.succeeded?
|
77
77
|
end
|
78
|
+
|
79
|
+
# Retrieve directory path where repo was or would be downloaded
|
80
|
+
#
|
81
|
+
# === Parameters
|
82
|
+
# repo(Hash|RightScale::Repository):: Remote repository corresponding to local directory
|
83
|
+
#
|
84
|
+
# === Return
|
85
|
+
# repo_dir(String):: Path to local directory that corresponds to given repository
|
86
|
+
def repo_dir(repo)
|
87
|
+
repo_dir = RightScale::ScraperBase.repo_dir(scrape_dir, repo)
|
88
|
+
end
|
78
89
|
|
79
90
|
# Error messages in case of failure
|
80
91
|
#
|
@@ -39,7 +39,7 @@ module RightScale
|
|
39
39
|
attr_reader :errors
|
40
40
|
|
41
41
|
# (String) Path to local directory where repository was downloaded
|
42
|
-
attr_reader :
|
42
|
+
attr_reader :current_repo_dir
|
43
43
|
|
44
44
|
# Set path to directory containing all scraped repos
|
45
45
|
#
|
@@ -54,17 +54,31 @@ module RightScale
|
|
54
54
|
# after this method initializes all the scraper attributes properly.
|
55
55
|
# See RightScale::Scraper#scrape
|
56
56
|
def scrape(repo, &callback)
|
57
|
-
@repo
|
58
|
-
@callback
|
59
|
-
@
|
60
|
-
@scrape_dir_path
|
61
|
-
@
|
62
|
-
@
|
63
|
-
@
|
64
|
-
FileUtils.rm_rf(@repo_dir) unless @incremental
|
57
|
+
@repo = repo
|
58
|
+
@callback = callback
|
59
|
+
@current_repo_dir = ScraperBase.repo_dir(root_dir, repo)
|
60
|
+
@scrape_dir_path = File.expand_path(File.join(@current_repo_dir, '..'))
|
61
|
+
@incremental = incremental_update?
|
62
|
+
@errors = []
|
63
|
+
FileUtils.rm_rf(@current_repo_dir) unless @incremental
|
65
64
|
scrape_imp
|
66
65
|
true
|
67
66
|
end
|
67
|
+
|
68
|
+
# Path to directory where given repo should be or was downloaded
|
69
|
+
#
|
70
|
+
# === Parameters
|
71
|
+
# root_dir(String):: Path to directory containing all scraped repositories
|
72
|
+
# repo(Hash|RightScale::Repository):: Remote repository corresponding to local directory
|
73
|
+
#
|
74
|
+
# === Return
|
75
|
+
# repo_dir(String):: Path to local directory that corresponds to given repository
|
76
|
+
def self.repo_dir(root_dir, repo)
|
77
|
+
repo = Repository.from_hash(repo) if repo.is_a?(Hash)
|
78
|
+
dir_name = Digest::MD5.hexdigest(repo.to_s)
|
79
|
+
dir_path = File.join(root_dir, dir_name)
|
80
|
+
repo_dir = "#{dir_path}/repo"
|
81
|
+
end
|
68
82
|
|
69
83
|
# Was last call to scrapesuccessful?
|
70
84
|
# Call errors to get error messages if false
|
@@ -34,8 +34,8 @@ module RightScale
|
|
34
34
|
@callback.call(msg, is_step=true) if @callback
|
35
35
|
filename = @repo.url.split('/').last
|
36
36
|
user_opt = @repo.first_credential && @repo.second_credential ? "--user #{@repo.first_credential}:#{@repo.second_credential}" : ''
|
37
|
-
cmd = "curl --fail --silent --show-error --insecure --location #{user_opt} --output '#{@
|
38
|
-
FileUtils.mkdir_p(@
|
37
|
+
cmd = "curl --fail --silent --show-error --insecure --location #{user_opt} --output '#{@current_repo_dir}/#{filename}' '#{@repo.url}' 2>&1"
|
38
|
+
FileUtils.mkdir_p(@current_repo_dir)
|
39
39
|
res = `#{cmd}`
|
40
40
|
@errors << res if $? != 0
|
41
41
|
if succeeded?
|
@@ -44,7 +44,7 @@ module RightScale
|
|
44
44
|
when 'tgz', 'gzip' then 'z'
|
45
45
|
else ''
|
46
46
|
end
|
47
|
-
Dir.chdir(@
|
47
|
+
Dir.chdir(@current_repo_dir) do
|
48
48
|
cmd = "tar x#{unzip_opt}f #{filename} 2>&1"
|
49
49
|
res = `#{cmd}`
|
50
50
|
@errors << res if $? != 0
|
@@ -32,8 +32,8 @@ module RightScale
|
|
32
32
|
# incremental updates
|
33
33
|
# false:: Otherwise
|
34
34
|
def incremental_update?
|
35
|
-
return false unless File.directory?(@
|
36
|
-
Dir.chdir(@
|
35
|
+
return false unless File.directory?(@current_repo_dir)
|
36
|
+
Dir.chdir(@current_repo_dir) do
|
37
37
|
remote_url = `git config --get remote.origin.url`.chomp
|
38
38
|
$?.success? && remote_url == @repo.url
|
39
39
|
end
|
@@ -53,7 +53,7 @@ module RightScale
|
|
53
53
|
is_branch = nil
|
54
54
|
|
55
55
|
if @incremental
|
56
|
-
Dir.chdir(@
|
56
|
+
Dir.chdir(@current_repo_dir) do
|
57
57
|
is_tag, is_branch, res = git_tag_kind(ssh_cmd)
|
58
58
|
if !is_tag && !is_branch
|
59
59
|
@callback.call("Nothing to update: repo tag refers to neither a branch nor a tag", is_step=false)
|
@@ -66,17 +66,17 @@ module RightScale
|
|
66
66
|
res += `#{ssh_cmd} git pull --quiet --depth 1 origin #{tag} 2>&1`
|
67
67
|
if $? != 0
|
68
68
|
@callback.call("Failed to pull repo: #{res}, falling back to cloning", is_step=false) if @callback
|
69
|
-
FileUtils.rm_rf(@
|
69
|
+
FileUtils.rm_rf(@current_repo_dir)
|
70
70
|
@incremental = false
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
75
|
if !@incremental
|
76
|
-
res += `#{ssh_cmd} git clone --quiet --depth 1 #{@repo.url} #{@
|
76
|
+
res += `#{ssh_cmd} git clone --quiet --depth 1 #{@repo.url} #{@current_repo_dir} 2>&1`
|
77
77
|
@errors << res if $? != 0
|
78
78
|
if !@repo.tag.nil? && !@repo.tag.empty? && @repo.tag != 'master' && succeeded?
|
79
|
-
Dir.chdir(@
|
79
|
+
Dir.chdir(@current_repo_dir) do
|
80
80
|
if is_tag.nil?
|
81
81
|
is_tag, is_branch, out = git_tag_kind(ssh_cmd)
|
82
82
|
res += out
|
@@ -32,8 +32,8 @@ module RightScale
|
|
32
32
|
# incremental updates
|
33
33
|
# false:: Otherwise
|
34
34
|
def incremental_update?
|
35
|
-
return false unless File.directory?(@
|
36
|
-
Dir.chdir(@
|
35
|
+
return false unless File.directory?(@current_repo_dir)
|
36
|
+
Dir.chdir(@current_repo_dir) do
|
37
37
|
info = `svn info`
|
38
38
|
$?.success? && info =~ (/^URL: (.*)$/) && $1 == @repo.url
|
39
39
|
end
|
@@ -52,17 +52,17 @@ module RightScale
|
|
52
52
|
(@repo.first_credential ? " --username #{@repo.first_credential}" : '') +
|
53
53
|
(@repo.second_credential ? " --password #{@repo.second_credential}" : '') +
|
54
54
|
' 2>&1'
|
55
|
-
Dir.chdir(@
|
55
|
+
Dir.chdir(@current_repo_dir) do
|
56
56
|
res = `#{svn_cmd}`
|
57
57
|
if $? != 0
|
58
58
|
@callback.call("Failed to update repo: #{res}, falling back to checkout", is_step=false) if @callback
|
59
|
-
FileUtils.rm_rf(@
|
59
|
+
FileUtils.rm_rf(@current_repo_dir)
|
60
60
|
@incremental = false
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
if !@incremental
|
65
|
-
svn_cmd = "svn checkout #{@repo.url} #{@
|
65
|
+
svn_cmd = "svn checkout #{@repo.url} #{@current_repo_dir} --non-interactive --quiet" +
|
66
66
|
(!@repo.tag.nil? && !@repo.tag.empty? ? " --revision #{@repo.tag}" : '') +
|
67
67
|
(@repo.first_credential ? " --username #{@repo.first_credential}" : '') +
|
68
68
|
(@repo.second_credential ? " --password #{@repo.second_credential}" : '') +
|
data/right_scraper.gemspec
CHANGED
@@ -23,7 +23,7 @@ require 'rubygems'
|
|
23
23
|
|
24
24
|
spec = Gem::Specification.new do |spec|
|
25
25
|
spec.name = 'right_scraper'
|
26
|
-
spec.version = '1.0.
|
26
|
+
spec.version = '1.0.1'
|
27
27
|
spec.authors = ['Raphael Simon']
|
28
28
|
spec.email = 'raphael@rightscale.com'
|
29
29
|
spec.homepage = 'https://github.com/rightscale/right_scraper'
|
@@ -78,8 +78,8 @@ describe RightScale::DownloadScraper do
|
|
78
78
|
puts "\n **ERRORS: #{@scraper.error_message}\n" unless @scraper.succeeded?
|
79
79
|
@scraper.succeeded?.should be_true
|
80
80
|
messages.size.should == 1
|
81
|
-
File.directory?(@scraper.
|
82
|
-
extract_file_layout(@scraper.
|
81
|
+
File.directory?(@scraper.current_repo_dir.should be_true)
|
82
|
+
extract_file_layout(@scraper.current_repo_dir).should == @repo_content
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
data/spec/git_scraper_spec.rb
CHANGED
@@ -86,8 +86,8 @@ describe RightScale::GitScraper do
|
|
86
86
|
puts "\n **ERRORS: #{@scraper.error_message}\n" unless @scraper.succeeded?
|
87
87
|
@scraper.succeeded?.should be_true
|
88
88
|
messages.size.should == 1
|
89
|
-
File.directory?(@scraper.
|
90
|
-
extract_file_layout(@scraper.
|
89
|
+
File.directory?(@scraper.current_repo_dir.should be_true)
|
90
|
+
extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ]).should == @repo_content
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should scrape incrementally' do
|
@@ -99,8 +99,8 @@ describe RightScale::GitScraper do
|
|
99
99
|
puts "\n **ERRORS: #{@scraper.error_message}\n" unless @scraper.succeeded?
|
100
100
|
@scraper.succeeded?.should be_true
|
101
101
|
messages.size.should == 1
|
102
|
-
File.directory?(@scraper.
|
103
|
-
extract_file_layout(@scraper.
|
102
|
+
File.directory?(@scraper.current_repo_dir.should be_true)
|
103
|
+
extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ]).should == @repo_content
|
104
104
|
end
|
105
105
|
|
106
106
|
end
|
data/spec/scraper_base_spec.rb
CHANGED
@@ -38,4 +38,9 @@ describe RightScale::ScraperBase do
|
|
38
38
|
@base.send(:incremental_update?).should be_false
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
it 'should allow retrieving the download directory path' do
|
42
|
+
repo_dir = RightScale::ScraperBase.repo_dir('root_dir', { :repo_type => :git, :url => 'git://github.com/rightscale/right_scraper.git' })
|
43
|
+
repo_dir.should =~ /^root_dir\//
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/scraper_spec.rb
CHANGED
@@ -45,22 +45,22 @@ describe RightScale::Scraper do
|
|
45
45
|
repo.repo_type = :mock
|
46
46
|
@mock_scraper.should_receive(:scrape).with(repo, Proc).and_return(true)
|
47
47
|
@mock_scraper.should_receive(:succeeded?).and_return(true)
|
48
|
-
@mock_scraper.should_receive(:
|
48
|
+
@mock_scraper.should_receive(:current_repo_dir).and_return('42')
|
49
49
|
@scraper.scrape(repo) { }.should be_true
|
50
|
-
@scraper.
|
50
|
+
@scraper.last_repo_dir.should == '42'
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should scrape from a hash' do
|
54
54
|
@mock_scraper.should_receive(:scrape).with(RightScale::Repository, Proc).and_return(true)
|
55
55
|
@mock_scraper.should_receive(:succeeded?).and_return(true)
|
56
|
-
@mock_scraper.should_receive(:
|
56
|
+
@mock_scraper.should_receive(:current_repo_dir).and_return('42')
|
57
57
|
@scraper.scrape({:repo_type => :mock}) { }.should be_true
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'should report failures' do
|
61
61
|
@mock_scraper.should_receive(:scrape).with(RightScale::Repository, Proc).and_return(true)
|
62
62
|
@mock_scraper.should_receive(:succeeded?).and_return(false)
|
63
|
-
@mock_scraper.should_receive(:
|
63
|
+
@mock_scraper.should_receive(:current_repo_dir).and_return('42')
|
64
64
|
@scraper.scrape({:repo_type => :mock}) { }.should be_false
|
65
65
|
end
|
66
66
|
|
data/spec/svn_scraper_spec.rb
CHANGED
@@ -82,8 +82,8 @@ describe RightScale::SvnScraper do
|
|
82
82
|
puts "\n **ERRORS: #{@scraper.error_message}\n" unless @scraper.succeeded?
|
83
83
|
@scraper.succeeded?.should be_true
|
84
84
|
messages.size.should == 1
|
85
|
-
File.directory?(@scraper.
|
86
|
-
extract_file_layout(@scraper.
|
85
|
+
File.directory?(@scraper.current_repo_dir.should be_true)
|
86
|
+
extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == @repo_content
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'should scrape incrementally' do
|
@@ -95,8 +95,8 @@ describe RightScale::SvnScraper do
|
|
95
95
|
puts "\n **ERRORS: #{@scraper.error_message}\n" unless @scraper.succeeded?
|
96
96
|
@scraper.succeeded?.should be_true
|
97
97
|
messages.size.should == 1
|
98
|
-
File.directory?(@scraper.
|
99
|
-
extract_file_layout(@scraper.
|
98
|
+
File.directory?(@scraper.current_repo_dir.should be_true)
|
99
|
+
extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == @repo_content
|
100
100
|
end
|
101
101
|
|
102
102
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphael Simon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-26 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|