right_scraper 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
@@ -39,6 +39,10 @@ module RightScale
|
|
39
39
|
# Not used for 'download' repositories
|
40
40
|
attr_accessor :tag
|
41
41
|
|
42
|
+
# (Array) List of directories containing cookbooks in repository
|
43
|
+
# Root directory is used if this is nil or empty
|
44
|
+
attr_accessor :cookbooks_path
|
45
|
+
|
42
46
|
# (String) Optional, SVN username or git private SSH key content
|
43
47
|
attr_accessor :first_credential
|
44
48
|
|
@@ -33,10 +33,24 @@ module RightScale
|
|
33
33
|
# false:: Otherwise
|
34
34
|
def incremental_update?
|
35
35
|
return false unless File.directory?(@current_repo_dir)
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
inc = false
|
37
|
+
cookbooks_path = repo.cookbooks_path || []
|
38
|
+
cookbooks_path = [ cookbooks_path ] unless cookbooks_path.is_a?(Array)
|
39
|
+
if cookbooks_path.empty?
|
40
|
+
Dir.chdir(@current_repo_dir) do
|
41
|
+
info = `svn info`
|
42
|
+
inc = $?.success? && info =~ (/^URL: (.*)$/) && $1 == @repo.url
|
43
|
+
end
|
44
|
+
else
|
45
|
+
cookbooks_path.each do |path|
|
46
|
+
Dir.chdir(File.join(@current_repo_dir, path)) do
|
47
|
+
info = `svn info`
|
48
|
+
inc = $?.success? && info =~ (/^URL: (.*)$/) && $1 == File.join(@repo.url, path)
|
49
|
+
break unless inc
|
50
|
+
end
|
51
|
+
end
|
39
52
|
end
|
53
|
+
inc
|
40
54
|
end
|
41
55
|
|
42
56
|
# Scrape SVN repository, see RightScale::Scraper#scrape
|
@@ -47,27 +61,57 @@ module RightScale
|
|
47
61
|
msg = @incremental ? "Updating " : "Checking out "
|
48
62
|
msg += "SVN repository '#{@repo.display_name}'"
|
49
63
|
@callback.call(msg, is_step=true) if @callback
|
64
|
+
cookbooks_path = repo.cookbooks_path || []
|
65
|
+
cookbooks_path = [ cookbooks_path ] unless cookbooks_path.is_a?(Array)
|
50
66
|
if @incremental
|
51
67
|
svn_cmd = "svn update --no-auth-cache --non-interactive --quiet" +
|
52
68
|
(@repo.first_credential ? " --username #{@repo.first_credential}" : '') +
|
53
69
|
(@repo.second_credential ? " --password #{@repo.second_credential}" : '') +
|
54
70
|
' 2>&1'
|
55
|
-
|
56
|
-
|
57
|
-
|
71
|
+
if cookbooks_path.empty?
|
72
|
+
Dir.chdir(@current_repo_dir) do
|
73
|
+
res = @watcher.launch_and_watch(svn_cmd, @current_repo_dir)
|
74
|
+
handle_watcher_result(res, 'SVN update', update=true)
|
75
|
+
end
|
76
|
+
else
|
77
|
+
cookbooks_path.each do |path|
|
78
|
+
break unless succeeded?
|
79
|
+
full_path = File.join(@current_repo_dir, path)
|
80
|
+
Dir.chdir(full_path) do
|
81
|
+
res = @watcher.launch_and_watch(svn_cmd, @current_repo_dir)
|
82
|
+
handle_watcher_result(res, 'SVN update', update=true)
|
83
|
+
end
|
84
|
+
end
|
58
85
|
end
|
59
86
|
end
|
60
87
|
if !@incremental && succeeded?
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
88
|
+
if cookbooks_path.empty?
|
89
|
+
res = @watcher.launch_and_watch(svn_checkout_cmd, @current_repo_dir)
|
90
|
+
handle_watcher_result(res, 'SVN checkout', update=false)
|
91
|
+
else
|
92
|
+
cookbooks_path.each do |path|
|
93
|
+
break unless succeeded?
|
94
|
+
res = @watcher.launch_and_watch(svn_checkout_cmd(path), @current_repo_dir)
|
95
|
+
handle_watcher_result(res, 'SVN checkout', update=false)
|
96
|
+
end
|
97
|
+
end
|
68
98
|
end
|
69
99
|
true
|
70
100
|
end
|
71
101
|
|
102
|
+
# SVN checkout command using current repo definition and given path into it
|
103
|
+
#
|
104
|
+
# === Parameters
|
105
|
+
# path(String):: Relative path inside repo that should be checked out
|
106
|
+
#
|
107
|
+
# === Return
|
108
|
+
# svn_cmd(String):: Corresponding SVN command line
|
109
|
+
def svn_checkout_cmd(path='')
|
110
|
+
svn_cmd = "svn checkout \"#{File.join(@repo.url, path)}\" \"#{File.join(@current_repo_dir, path)}\" --no-auth-cache --non-interactive --quiet" +
|
111
|
+
(!@repo.tag.nil? && !@repo.tag.empty? ? " --revision #{@repo.tag}" : '') +
|
112
|
+
(@repo.first_credential ? " --username #{@repo.first_credential}" : '') +
|
113
|
+
(@repo.second_credential ? " --password #{@repo.second_credential}" : '') +
|
114
|
+
' 2>&1'
|
115
|
+
end
|
72
116
|
end
|
73
117
|
end
|
@@ -82,7 +82,7 @@ module RightScale
|
|
82
82
|
|
83
83
|
# Run external process and monitor it in a new thread, platform specific
|
84
84
|
pid = monitor.spawn(cmd) do |data|
|
85
|
-
output << data[:output] if data
|
85
|
+
output << data[:output] if data[:output]
|
86
86
|
exit_code = data[:exit_code] if data.include?(:exit_code)
|
87
87
|
end
|
88
88
|
|
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.12'
|
27
27
|
spec.authors = ['Raphael Simon']
|
28
28
|
spec.email = 'raphael@rightscale.com'
|
29
29
|
spec.homepage = 'https://github.com/rightscale/right_scraper'
|
@@ -70,6 +70,7 @@ describe RightScale::DownloadScraper do
|
|
70
70
|
@repo = RightScale::Repository.from_hash(:display_name => 'test repo',
|
71
71
|
:repo_type => :download,
|
72
72
|
:url => "file:///#{@download_file}")
|
73
|
+
FileUtils.rm_rf(RightScale::ScraperBase.repo_dir(@repo_path, @repo))
|
73
74
|
end
|
74
75
|
|
75
76
|
after(:all) do
|
@@ -82,7 +83,7 @@ describe RightScale::DownloadScraper do
|
|
82
83
|
puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
|
83
84
|
@scraper.succeeded?.should be_true
|
84
85
|
messages.size.should == 1
|
85
|
-
File.directory?(@scraper.current_repo_dir.should be_true
|
86
|
+
File.directory?(@scraper.current_repo_dir).should be_true
|
86
87
|
extract_file_layout(@scraper.current_repo_dir).should == @repo_content
|
87
88
|
end
|
88
89
|
|
data/spec/git_scraper_spec.rb
CHANGED
@@ -75,6 +75,7 @@ describe RightScale::GitScraper do
|
|
75
75
|
@repo = RightScale::Repository.from_hash(:display_name => 'test repo',
|
76
76
|
:repo_type => :git,
|
77
77
|
:url => @origin_path)
|
78
|
+
FileUtils.rm_rf(RightScale::ScraperBase.repo_dir(@repo_path, @repo))
|
78
79
|
end
|
79
80
|
|
80
81
|
after(:all) do
|
@@ -87,7 +88,7 @@ describe RightScale::GitScraper do
|
|
87
88
|
puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
|
88
89
|
@scraper.succeeded?.should be_true
|
89
90
|
messages.size.should == 1
|
90
|
-
File.directory?(@scraper.current_repo_dir.should be_true
|
91
|
+
File.directory?(@scraper.current_repo_dir).should be_true
|
91
92
|
extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ]).should == @repo_content
|
92
93
|
end
|
93
94
|
|
@@ -100,7 +101,7 @@ describe RightScale::GitScraper do
|
|
100
101
|
puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
|
101
102
|
@scraper.succeeded?.should be_true
|
102
103
|
messages.size.should == 1
|
103
|
-
File.directory?(@scraper.current_repo_dir.should be_true
|
104
|
+
File.directory?(@scraper.current_repo_dir).should be_true
|
104
105
|
extract_file_layout(@scraper.current_repo_dir, [ '.git', '.ssh' ]).should == @repo_content
|
105
106
|
end
|
106
107
|
|
data/spec/svn_scraper_spec.rb
CHANGED
@@ -37,7 +37,9 @@ describe RightScale::SvnScraper do
|
|
37
37
|
def setup_svn_repo
|
38
38
|
@svn_repo_path = File.expand_path(File.join(File.dirname(__FILE__), '__svn_repo'))
|
39
39
|
@repo_path = File.join(File.dirname(__FILE__), '__repo')
|
40
|
-
@repo_content = [ 'file1', { 'folder1' => [ 'file2', 'file3' ] },
|
40
|
+
@repo_content = [ 'file1', { 'folder1' => [ 'file2', 'file3' ] },
|
41
|
+
{ 'folder2' => [ { 'folder3' => [ 'file4' ] },
|
42
|
+
{ 'folder5' => [ 'file6' ] } ] } ]
|
41
43
|
FileUtils.rm_rf(@svn_repo_path)
|
42
44
|
res, status = exec("svnadmin create \"#{@svn_repo_path}\"")
|
43
45
|
raise "Failed to initialize SVN repository: #{res}" unless status.success?
|
@@ -73,6 +75,7 @@ describe RightScale::SvnScraper do
|
|
73
75
|
@repo = RightScale::Repository.from_hash(:display_name => 'test repo',
|
74
76
|
:repo_type => :svn,
|
75
77
|
:url => "#{file_prefix}#{@svn_repo_path}")
|
78
|
+
FileUtils.rm_rf(RightScale::ScraperBase.repo_dir(@repo_path, @repo))
|
76
79
|
end
|
77
80
|
|
78
81
|
after(:all) do
|
@@ -85,7 +88,7 @@ describe RightScale::SvnScraper do
|
|
85
88
|
puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
|
86
89
|
@scraper.succeeded?.should be_true
|
87
90
|
messages.size.should == 1
|
88
|
-
File.directory?(@scraper.current_repo_dir.should be_true
|
91
|
+
File.directory?(@scraper.current_repo_dir).should be_true
|
89
92
|
extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == @repo_content
|
90
93
|
end
|
91
94
|
|
@@ -99,10 +102,36 @@ describe RightScale::SvnScraper do
|
|
99
102
|
puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
|
100
103
|
@scraper.succeeded?.should be_true
|
101
104
|
messages.size.should == 1
|
102
|
-
File.directory?(@scraper.current_repo_dir.should be_true
|
105
|
+
File.directory?(@scraper.current_repo_dir).should be_true
|
103
106
|
extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == @repo_content
|
104
107
|
end
|
105
108
|
|
109
|
+
it 'should only scrape cookbooks directories' do
|
110
|
+
messages = []
|
111
|
+
@repo.cookbooks_path = [ 'folder1', File.join('folder2', 'folder3') ]
|
112
|
+
@scraper.scrape(@repo) { |m, progress| messages << m if progress }
|
113
|
+
puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
|
114
|
+
@scraper.succeeded?.should be_true
|
115
|
+
messages.size.should == 1
|
116
|
+
File.directory?(@scraper.current_repo_dir).should be_true
|
117
|
+
extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => ['folder3' => [ 'file4' ] ] } ]
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should only scrape cookbooks directories incrementally' do
|
121
|
+
pending "File URLs comparison on Windows is tricky" if RUBY_PLATFORM=~/mswin/
|
122
|
+
@repo.cookbooks_path = [ 'folder1', File.join('folder2', 'folder3') ]
|
123
|
+
@scraper.scrape(@repo)
|
124
|
+
puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
|
125
|
+
@scraper.incremental_update?.should be_true
|
126
|
+
messages = []
|
127
|
+
@scraper.scrape(@repo) { |m, progress| messages << m if progress }
|
128
|
+
puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
|
129
|
+
@scraper.succeeded?.should be_true
|
130
|
+
messages.size.should == 1
|
131
|
+
File.directory?(@scraper.current_repo_dir).should be_true
|
132
|
+
extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => ['folder3' => [ 'file4' ] ] } ]
|
133
|
+
end
|
134
|
+
|
106
135
|
end
|
107
136
|
|
108
137
|
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.12
|
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-
|
12
|
+
date: 2010-03-26 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|