right_scraper 1.0.26 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/Gemfile +16 -0
  2. data/README.rdoc +9 -28
  3. data/Rakefile +51 -39
  4. data/lib/right_scraper/builders/base.rb +64 -0
  5. data/lib/right_scraper/builders/filesystem.rb +96 -0
  6. data/lib/right_scraper/builders/union.rb +57 -0
  7. data/lib/right_scraper/logger.rb +102 -0
  8. data/lib/right_scraper/loggers/noisy.rb +85 -0
  9. data/lib/right_scraper/processes/ssh.rb +188 -0
  10. data/lib/right_scraper/repositories/base.rb +299 -0
  11. data/lib/right_scraper/repositories/download.rb +90 -0
  12. data/lib/right_scraper/repositories/git.rb +92 -0
  13. data/lib/right_scraper/repositories/mock.rb +70 -0
  14. data/lib/right_scraper/repositories/svn.rb +96 -0
  15. data/lib/right_scraper/resources/base.rb +70 -0
  16. data/{spec/scraper_base_spec.rb → lib/right_scraper/resources/cookbook.rb} +9 -23
  17. data/lib/right_scraper/resources/workflow.rb +55 -0
  18. data/lib/right_scraper/retrievers/base.rb +114 -0
  19. data/lib/right_scraper/retrievers/checkout.rb +79 -0
  20. data/lib/right_scraper/retrievers/download.rb +97 -0
  21. data/lib/right_scraper/retrievers/git.rb +140 -0
  22. data/lib/right_scraper/retrievers/svn.rb +87 -0
  23. data/lib/right_scraper/scanners/base.rb +111 -0
  24. data/lib/right_scraper/scanners/cookbook_manifest.rb +59 -0
  25. data/lib/right_scraper/scanners/cookbook_metadata.rb +69 -0
  26. data/lib/right_scraper/scanners/cookbook_s3_upload.rb +84 -0
  27. data/lib/right_scraper/scanners/union.rb +89 -0
  28. data/lib/right_scraper/scanners/workflow_manifest.rb +86 -0
  29. data/lib/right_scraper/scanners/workflow_metadata.rb +70 -0
  30. data/lib/right_scraper/scanners/workflow_s3_upload.rb +85 -0
  31. data/lib/right_scraper/scraper.rb +81 -57
  32. data/lib/right_scraper/scraper_logger.rb +61 -0
  33. data/lib/right_scraper/scrapers/base.rb +262 -0
  34. data/lib/right_scraper/scrapers/cookbook.rb +73 -0
  35. data/lib/right_scraper/scrapers/workflow.rb +88 -0
  36. data/lib/right_scraper/svn_client.rb +101 -0
  37. data/lib/right_scraper/version.rb +28 -0
  38. data/lib/right_scraper.rb +35 -11
  39. data/right_scraper.gemspec +26 -13
  40. data/right_scraper.rconf +13 -0
  41. data/spec/builder_spec.rb +50 -0
  42. data/spec/cookbook_helper.rb +73 -0
  43. data/spec/cookbook_manifest_spec.rb +55 -0
  44. data/spec/cookbook_s3_upload_spec.rb +152 -0
  45. data/spec/download/download_retriever_spec.rb +118 -0
  46. data/spec/download/download_retriever_spec_helper.rb +72 -0
  47. data/spec/download/download_spec.rb +130 -0
  48. data/spec/download/multi_dir_spec.rb +106 -0
  49. data/spec/download/multi_dir_spec_helper.rb +40 -0
  50. data/spec/git/cookbook_spec.rb +166 -0
  51. data/spec/git/demokey +27 -0
  52. data/spec/git/demokey.pub +1 -0
  53. data/spec/git/password_key +30 -0
  54. data/spec/git/password_key.pub +1 -0
  55. data/spec/git/repository_spec.rb +110 -0
  56. data/spec/git/retriever_spec.rb +505 -0
  57. data/spec/git/retriever_spec_helper.rb +112 -0
  58. data/spec/git/scraper_spec.rb +136 -0
  59. data/spec/git/ssh_spec.rb +170 -0
  60. data/spec/git/url_spec.rb +103 -0
  61. data/spec/logger_spec.rb +185 -0
  62. data/spec/repository_spec.rb +89 -23
  63. data/spec/{scraper_spec_helper_base.rb → retriever_spec_helper.rb} +41 -27
  64. data/spec/scanner_spec.rb +61 -0
  65. data/spec/scraper_helper.rb +96 -0
  66. data/spec/scraper_spec.rb +123 -45
  67. data/spec/spec_helper.rb +87 -14
  68. data/spec/svn/cookbook_spec.rb +97 -0
  69. data/spec/svn/multi_svn_spec.rb +64 -0
  70. data/spec/svn/multi_svn_spec_helper.rb +40 -0
  71. data/spec/svn/repository_spec.rb +72 -0
  72. data/spec/svn/retriever_spec.rb +261 -0
  73. data/spec/svn/scraper_spec.rb +90 -0
  74. data/spec/svn/{svn_scraper_spec_helper.rb → svn_retriever_spec_helper.rb} +46 -27
  75. data/spec/svn/url_spec.rb +47 -0
  76. data/spec/url_spec.rb +164 -0
  77. metadata +203 -31
  78. data/lib/right_scraper/linux/process_monitor.rb +0 -84
  79. data/lib/right_scraper/repository.rb +0 -78
  80. data/lib/right_scraper/scraper_base.rb +0 -175
  81. data/lib/right_scraper/scrapers/download_scraper.rb +0 -67
  82. data/lib/right_scraper/scrapers/git_scraper.rb +0 -283
  83. data/lib/right_scraper/scrapers/svn_scraper.rb +0 -119
  84. data/lib/right_scraper/watcher.rb +0 -158
  85. data/lib/right_scraper/win32/process_monitor.rb +0 -98
  86. data/spec/download/download_scraper_spec.rb +0 -94
  87. data/spec/git/git_scraper_spec.rb +0 -165
  88. data/spec/git/git_scraper_spec_helper.rb +0 -72
  89. data/spec/rcov.opts +0 -1
  90. data/spec/spec.opts +0 -2
  91. data/spec/svn/svn_scraper_spec.rb +0 -148
  92. data/spec/watcher_spec.rb +0 -74
@@ -1,72 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 RightScale, Inc.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # 'Software'), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
- # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
- # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
- # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
- # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'scraper_spec_helper_base'))
25
-
26
- module RightScale
27
-
28
- # Git implementation of scraper spec helper
29
- # See parent class for methods headers comments
30
- class GitScraperSpecHelper < ScraperSpecHelperBase
31
-
32
- def setup_test_repo
33
- FileUtils.rm_rf(repo_path)
34
- FileUtils.mkdir_p(repo_path)
35
- Dir.chdir(repo_path) do
36
- res, status = exec('git init')
37
- raise "Failed to initialize bare git repository: #{res}" unless status.success?
38
- end
39
- create_file_layout(repo_path, repo_content)
40
- commit_content(repo_path)
41
- end
42
-
43
- def commit_content(commit_message='commit')
44
- Dir.chdir(repo_path) do
45
- res, status = exec('git add .')
46
- res, status = exec("git commit --quiet -m \"#{commit_message}\"") if status.success?
47
- raise "Failed to commit changes from #{repo_path}: #{res}" unless status.success?
48
- end
49
- end
50
-
51
- def setup_branch(branch, new_content=nil)
52
- Dir.chdir(repo_path) do
53
- res, status = exec("git checkout -b #{branch}")
54
- raise "Failed to setup branch #{branch}: #{res}" unless status.success?
55
- end
56
- unless new_content.nil?
57
- create_file_layout(repo_path, new_content)
58
- commit_content("Branch #{branch}")
59
- end
60
- end
61
-
62
- def commit_id(index_from_last=0)
63
- res = nil
64
- Dir.chdir(repo_path) do
65
- res, status = exec("git log --format=%H -#{index_from_last + 1}")
66
- raise "Failed to retrieve commit sha #{index_from_last}: #{res}" unless status.success?
67
- end
68
- commit_id = res.split("\n").last
69
- end
70
-
71
- end
72
- end
data/spec/rcov.opts DELETED
@@ -1 +0,0 @@
1
- --exclude "spec/*"~
data/spec/spec.opts DELETED
@@ -1,2 +0,0 @@
1
- --colour
2
- --format=nested
@@ -1,148 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 RightScale, Inc.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # 'Software'), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
- # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
- # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
- # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
- # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- require File.expand_path(File.join(File.dirname(__FILE__), 'svn_scraper_spec_helper'))
25
- require 'scraper_base'
26
- require 'repository'
27
- require 'watcher'
28
- require File.join('scrapers', 'svn_scraper')
29
- require 'set'
30
-
31
- describe RightScale::SvnScraper do
32
-
33
- context 'given a SVN repository' do
34
-
35
- before(:each) do
36
- @helper = RightScale::SvnScraperSpecHelper.new
37
- @helper.setup_test_repo
38
- @scrape_dir = File.expand_path(File.join(File.dirname(__FILE__), '__scrape'))
39
- @scraper = RightScale::SvnScraper.new(@scrape_dir, max_bytes=1024**2, max_seconds=20)
40
- @repo = RightScale::Repository.from_hash(:display_name => 'test repo',
41
- :repo_type => :svn,
42
- :url => @helper.repo_url)
43
- FileUtils.rm_rf(RightScale::ScraperBase.repo_dir(@helper.repo_path, @repo))
44
- end
45
-
46
- after(:each) do
47
- @helper.delete_test_repo
48
- FileUtils.rm_rf(@helper.svn_repo_path)
49
- FileUtils.rm_rf(@scrape_dir)
50
- end
51
-
52
- it 'should scrape' do
53
- messages = []
54
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
55
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
56
- @scraper.succeeded?.should be_true
57
- messages.size.should == 1
58
- File.directory?(@scraper.current_repo_dir).should be_true
59
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ])).should ==
60
- Set.new(@helper.repo_content)
61
- end
62
-
63
- it 'should scrape incrementally' do
64
- pending "File URLs comparison on Windows is tricky" if RUBY_PLATFORM=~/mswin/
65
- @scraper.scrape(@repo)
66
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
67
- @scraper.incremental_update?.should be_true
68
- @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
69
- @helper.commit_content
70
- messages = []
71
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
72
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
73
- @scraper.succeeded?.should be_true
74
- messages.size.should == 1
75
- File.directory?(@scraper.current_repo_dir).should be_true
76
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ])).should ==
77
- Set.new(@helper.repo_content + @helper.additional_content)
78
- end
79
-
80
- it 'should only scrape cookbooks directories' do
81
- messages = []
82
- @repo.cookbooks_path = [ 'folder1', File.join('folder2', 'folder3') ]
83
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
84
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
85
- @scraper.succeeded?.should be_true
86
- messages.size.should == 1
87
- File.directory?(@scraper.current_repo_dir).should be_true
88
- @helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => ['folder3' => [ 'file4' ] ] } ]
89
- end
90
-
91
- it 'should only scrape cookbooks directories incrementally' do
92
- pending "File URLs comparison on Windows is tricky" if RUBY_PLATFORM=~/mswin/
93
- @repo.cookbooks_path = [ 'folder1', File.join('folder2', 'folder3') ]
94
- @scraper.scrape(@repo)
95
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
96
- @scraper.incremental_update?.should be_true
97
- messages = []
98
- @scraper.scrape(@repo) { |m, progress| messages << m if progress }
99
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
100
- @scraper.succeeded?.should be_true
101
- messages.size.should == 1
102
- File.directory?(@scraper.current_repo_dir).should be_true
103
- @helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ]).should == [ { 'folder1' => [ 'file2', 'file3' ] }, { 'folder2' => ['folder3' => [ 'file4' ] ] } ]
104
- end
105
-
106
- context 'and a revision' do
107
-
108
- before(:each) do
109
- @helper.create_file_layout(@helper.repo_path, @helper.branch_content)
110
- @helper.commit_content
111
- @rev_repo = RightScale::Repository.from_hash(:display_name => 'test repo',
112
- :repo_type => :svn,
113
- :url => @helper.repo_url,
114
- :tag => @helper.commit_id(1))
115
- end
116
-
117
- it 'should scrape a revision' do
118
- messages = []
119
- @scraper.scrape(@rev_repo) { |m, progress| messages << m if progress }
120
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
121
- @scraper.succeeded?.should be_true
122
- messages.size.should == 1
123
- File.directory?(@scraper.current_repo_dir).should be_true
124
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ])).should ==
125
- Set.new(@helper.repo_content)
126
- end
127
-
128
- it 'should scrape a revision incrementally' do
129
- @scraper.scrape(@rev_repo)
130
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
131
- @scraper.incremental_update?.should be_true
132
- @helper.create_file_layout(@helper.repo_path, @helper.additional_content)
133
- @helper.commit_content
134
- messages = []
135
- @scraper.scrape(@rev_repo) { |m, progress| messages << m if progress }
136
- puts "\n **ERRORS: #{@scraper.errors.join("\n")}\n" unless @scraper.succeeded?
137
- @scraper.succeeded?.should be_true
138
- messages.size.should == 1
139
- @scraper.instance_variable_get(:@incremental).should == true
140
- File.directory?(@scraper.current_repo_dir).should be_true
141
- Set.new(@helper.extract_file_layout(@scraper.current_repo_dir, [ '.svn' ])).should ==
142
- Set.new(@helper.repo_content)
143
- end
144
-
145
- end
146
- end
147
-
148
- end
data/spec/watcher_spec.rb DELETED
@@ -1,74 +0,0 @@
1
- #--
2
- # Copyright: Copyright (c) 2010 RightScale, Inc.
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # 'Software'), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
- # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
- # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
- # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
- # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- require File.join(File.dirname(__FILE__), 'spec_helper')
25
- require 'watcher'
26
-
27
- describe RightScale::Watcher do
28
-
29
- before(:each) do
30
- @dest_dir = File.join(File.dirname(__FILE__), '__destdir')
31
- FileUtils.mkdir_p(@dest_dir)
32
- end
33
-
34
- after(:each) do
35
- FileUtils.rm_rf(@dest_dir)
36
- end
37
-
38
- it 'should launch and watch well-behaved processes' do
39
- watcher = RightScale::Watcher.new(max_bytes=1, max_seconds=5)
40
- ruby = "trap('INT', 'IGNORE'); puts 42; exit 42"
41
- status = watcher.launch_and_watch('ruby', ['-e', ruby], @dest_dir)
42
- status.status.should == :success
43
- status.exit_code.should == 42
44
- status.output.should == "42\n"
45
- end
46
-
47
- it 'should report timeouts' do
48
- watcher = RightScale::Watcher.new(max_bytes=1, max_seconds=2)
49
- ruby = "trap('INT', 'IGNORE'); STDOUT.sync = true; puts 42; sleep 5"
50
- status = watcher.launch_and_watch('ruby', ['-e', ruby], @dest_dir)
51
- status.status.should == :timeout
52
- status.exit_code.should == -1
53
- status.output.should == "42\n"
54
- end
55
-
56
- it 'should report size exceeded' do
57
- watcher = RightScale::Watcher.new(max_bytes=1, max_seconds=5)
58
- ruby = "trap('INT', 'IGNORE'); STDOUT.sync = true; puts 42; File.open(File.join('#{@dest_dir}', 'test'), 'w') { |f| f.puts 'MORE THAN 2 CHARS' }; sleep 5 rescue nil"
59
- status = watcher.launch_and_watch('ruby', ['-e', ruby], @dest_dir)
60
- status.status.should == :size_exceeded
61
- status.exit_code.should == -1
62
- status.output.should == "42\n"
63
- end
64
-
65
- it 'should allow infinite size and timeout' do
66
- watcher = RightScale::Watcher.new(max_bytes=-1, max_seconds=-1)
67
- ruby = "trap('INT', 'IGNORE'); STDOUT.sync = true; puts 42; File.open(File.join('#{@dest_dir}', 'test'), 'w') { |f| f.puts 'MORE THAN 2 CHARS' }; sleep 2 rescue nil"
68
- status = watcher.launch_and_watch('ruby', ['-e', ruby], @dest_dir)
69
- status.status.should == :success
70
- status.exit_code.should == 0
71
- status.output.should == "42\n"
72
- end
73
-
74
- end