right_scraper 3.2.6 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/right_scraper.rb +16 -34
- data/lib/right_scraper/builders.rb +32 -0
- data/lib/right_scraper/builders/base.rb +19 -20
- data/lib/right_scraper/builders/filesystem.rb +8 -6
- data/lib/right_scraper/builders/union.rb +4 -1
- data/lib/right_scraper/loggers.rb +31 -0
- data/lib/right_scraper/loggers/base.rb +113 -0
- data/lib/right_scraper/loggers/default.rb +98 -0
- data/lib/right_scraper/{scraper.rb → main.rb} +53 -9
- data/lib/right_scraper/processes.rb +33 -0
- data/lib/right_scraper/processes/shell.rb +227 -0
- data/lib/right_scraper/processes/{ssh.rb → ssh_agent.rb} +4 -0
- data/lib/right_scraper/processes/svn_client.rb +117 -0
- data/lib/right_scraper/processes/warden.rb +358 -0
- data/lib/right_scraper/registered_base.rb +154 -0
- data/lib/right_scraper/repositories.rb +33 -0
- data/lib/right_scraper/repositories/base.rb +271 -232
- data/lib/right_scraper/repositories/download.rb +8 -6
- data/lib/right_scraper/repositories/git.rb +8 -9
- data/lib/right_scraper/repositories/svn.rb +8 -8
- data/lib/right_scraper/resources.rb +32 -0
- data/lib/right_scraper/resources/base.rb +5 -1
- data/lib/right_scraper/resources/cookbook.rb +34 -27
- data/lib/right_scraper/resources/workflow.rb +27 -28
- data/lib/right_scraper/retrievers.rb +34 -0
- data/lib/right_scraper/retrievers/base.rb +80 -84
- data/lib/right_scraper/retrievers/checkout_base.rb +178 -0
- data/lib/right_scraper/retrievers/download.rb +125 -117
- data/lib/right_scraper/retrievers/git.rb +377 -223
- data/lib/right_scraper/retrievers/svn.rb +102 -62
- data/lib/right_scraper/scanners.rb +37 -0
- data/lib/right_scraper/scanners/base.rb +77 -80
- data/lib/right_scraper/scanners/cookbook_manifest.rb +31 -30
- data/lib/right_scraper/scanners/cookbook_metadata.rb +380 -35
- data/lib/right_scraper/scanners/cookbook_s3_upload.rb +56 -53
- data/lib/right_scraper/scanners/union.rb +61 -58
- data/lib/right_scraper/scanners/workflow_manifest.rb +55 -54
- data/lib/right_scraper/scanners/workflow_metadata.rb +41 -39
- data/lib/right_scraper/scanners/workflow_s3_upload.rb +59 -55
- data/lib/right_scraper/scrapers.rb +32 -0
- data/lib/right_scraper/scrapers/base.rb +217 -205
- data/lib/right_scraper/scrapers/cookbook.rb +42 -40
- data/lib/right_scraper/scrapers/workflow.rb +57 -58
- data/lib/right_scraper/version.rb +3 -0
- data/right_scraper.gemspec +12 -16
- metadata +57 -163
- data/Gemfile +0 -15
- data/Rakefile +0 -89
- data/lib/right_scraper/logger.rb +0 -107
- data/lib/right_scraper/loggers/noisy.rb +0 -85
- data/lib/right_scraper/repositories/mock.rb +0 -70
- data/lib/right_scraper/retrievers/checkout.rb +0 -79
- data/lib/right_scraper/scraper_logger.rb +0 -66
- data/lib/right_scraper/svn_client.rb +0 -164
- data/right_scraper.rconf +0 -13
- data/spec/builder_spec.rb +0 -50
- data/spec/cookbook_helper.rb +0 -73
- data/spec/cookbook_manifest_spec.rb +0 -93
- data/spec/cookbook_s3_upload_spec.rb +0 -159
- data/spec/download/download_retriever_spec.rb +0 -118
- data/spec/download/download_retriever_spec_helper.rb +0 -72
- data/spec/download/download_spec.rb +0 -128
- data/spec/download/multi_dir_spec.rb +0 -106
- data/spec/download/multi_dir_spec_helper.rb +0 -40
- data/spec/git/cookbook_spec.rb +0 -165
- data/spec/git/demokey +0 -27
- data/spec/git/demokey.pub +0 -1
- data/spec/git/password_key +0 -30
- data/spec/git/password_key.pub +0 -1
- data/spec/git/repository_spec.rb +0 -110
- data/spec/git/retriever_spec.rb +0 -553
- data/spec/git/retriever_spec_helper.rb +0 -112
- data/spec/git/scraper_spec.rb +0 -151
- data/spec/git/ssh_spec.rb +0 -174
- data/spec/git/url_spec.rb +0 -103
- data/spec/logger_spec.rb +0 -185
- data/spec/repository_spec.rb +0 -111
- data/spec/retriever_spec_helper.rb +0 -146
- data/spec/scanner_spec.rb +0 -61
- data/spec/scraper_helper.rb +0 -88
- data/spec/scraper_spec.rb +0 -147
- data/spec/spec_helper.rb +0 -185
- data/spec/svn/cookbook_spec.rb +0 -96
- data/spec/svn/multi_svn_spec.rb +0 -64
- data/spec/svn/multi_svn_spec_helper.rb +0 -40
- data/spec/svn/repository_spec.rb +0 -72
- data/spec/svn/retriever_spec.rb +0 -266
- data/spec/svn/scraper_spec.rb +0 -90
- data/spec/svn/svn_retriever_spec_helper.rb +0 -90
- data/spec/svn/url_spec.rb +0 -47
- data/spec/url_spec.rb +0 -164
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac45d2b026fadbb61775b0b93c9739b163ff8fcb
|
4
|
+
data.tar.gz: 14b1d686bdb7ca42b6026e4b40352e65990dac3b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45e307c5376f9fe07522f44540a49016ff1166747327b87f6b3a807408a42135a29250b560b6add6dfbfbfa4421dce95fd2dfad3a784b9e85609377cc294e455
|
7
|
+
data.tar.gz: 60f022f6c81364948e14d49066b988266db2a23c97ead1fc8c3dc8a3bcd993086decfda1430c506bc0961e60661e569fff33304a139aa4b8505a064a21a73958
|
data/lib/right_scraper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright: Copyright (c) 2010-
|
2
|
+
# Copyright: Copyright (c) 2010-2013 RightScale, Inc.
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -21,36 +21,18 @@
|
|
21
21
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'retrievers', 'checkout'))
|
40
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'retrievers', 'download'))
|
41
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'retrievers', 'git'))
|
42
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'retrievers', 'svn'))
|
43
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scanners', 'base'))
|
44
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scanners', 'cookbook_manifest'))
|
45
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scanners', 'cookbook_metadata'))
|
46
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scanners', 'cookbook_s3_upload'))
|
47
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scanners', 'union'))
|
48
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scanners', 'workflow_manifest'))
|
49
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scanners', 'workflow_metadata'))
|
50
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scraper'))
|
51
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scraper_logger'))
|
52
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scrapers', 'base'))
|
53
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scrapers', 'cookbook'))
|
54
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'scrapers', 'workflow'))
|
55
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'svn_client'))
|
56
|
-
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper', 'version'))
|
24
|
+
require 'right_scraper/version'
|
25
|
+
|
26
|
+
# Autoload everything possible
|
27
|
+
module RightScraper
|
28
|
+
autoload :Builders, 'right_scraper/builders'
|
29
|
+
autoload :Loggers, 'right_scraper/loggers'
|
30
|
+
autoload :Main, 'right_scraper/main'
|
31
|
+
autoload :Processes, 'right_scraper/processes'
|
32
|
+
autoload :RegisteredBase, 'right_scraper/registered_base'
|
33
|
+
autoload :Repositories, 'right_scraper/repositories'
|
34
|
+
autoload :Resources, 'right_scraper/resources'
|
35
|
+
autoload :Retrievers, 'right_scraper/retrievers'
|
36
|
+
autoload :Scanners, 'right_scraper/scanners'
|
37
|
+
autoload :Scrapers, 'right_scraper/scrapers'
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 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
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
# ancestor
|
24
|
+
require 'right_scraper'
|
25
|
+
|
26
|
+
module RightScraper
|
27
|
+
module Builders
|
28
|
+
autoload :Base, 'right_scraper/builders/base'
|
29
|
+
autoload :Filesystem, 'right_scraper/builders/filesystem'
|
30
|
+
autoload :Union, 'right_scraper/builders/union'
|
31
|
+
end
|
32
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright: Copyright (c) 2010-
|
2
|
+
# Copyright: Copyright (c) 2010-2013 RightScale, Inc.
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -21,43 +21,42 @@
|
|
21
21
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
24
|
+
# ancestor
|
25
|
+
require 'right_scraper/builders'
|
25
26
|
|
26
27
|
module RightScraper
|
27
28
|
module Builders
|
29
|
+
|
28
30
|
# Base class for building additional metadata from filesystem
|
29
|
-
# based checkouts.
|
31
|
+
# based checkouts. Subclasses should override #go, and possibly
|
30
32
|
# #new if they require additional arguments.
|
31
33
|
#
|
32
34
|
# The lifecycle for a builder is as follows:
|
33
35
|
# - builder = Builder.new (once)
|
34
36
|
# - builder.go(dir, resource) (many times)
|
35
37
|
# - builder.finish (once)
|
36
|
-
class
|
37
|
-
#
|
38
|
-
# options
|
39
|
-
|
40
|
-
|
41
|
-
# === Options
|
42
|
-
# <tt>:logger</tt>:: Optional. Logger currently being used
|
43
|
-
#
|
44
|
-
# === Parameters
|
45
|
-
# options(Hash):: builder options
|
46
|
-
def initialize(options={})
|
47
|
-
@logger = options.fetch(:logger, Logger.new)
|
38
|
+
class Base
|
39
|
+
# @param [Hash] options for builder
|
40
|
+
# @option options [Logger] :logger for builder
|
41
|
+
def initialize(options = {})
|
42
|
+
@logger = options[:logger] || ::RightScraper::Loggers::Default.new
|
48
43
|
end
|
49
44
|
|
50
45
|
# Run builder for this resource.
|
51
46
|
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
47
|
+
# @param [String] dir for resource
|
48
|
+
# @param [Object] resource to build
|
49
|
+
#
|
50
|
+
# @return [TrueClass] always true
|
55
51
|
def go(dir, resource)
|
52
|
+
raise NotImplementedError
|
56
53
|
end
|
57
54
|
|
58
|
-
# Notification that all scans for this repository have
|
59
|
-
#
|
55
|
+
# Notification that all scans for this repository have completed.
|
56
|
+
#
|
57
|
+
# @return [TrueClass] always true
|
60
58
|
def finish
|
59
|
+
true
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright: Copyright (c) 2010-
|
2
|
+
# Copyright: Copyright (c) 2010-2013 RightScale, Inc.
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -21,12 +21,13 @@
|
|
21
21
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
24
|
+
# ancestor
|
25
|
+
require 'right_scraper/builders'
|
25
26
|
|
26
27
|
module RightScraper
|
27
28
|
module Builders
|
28
29
|
# Build metadata by scanning the filesystem.
|
29
|
-
class Filesystem <
|
30
|
+
class Filesystem < ::RightScraper::Builders::Base
|
30
31
|
|
31
32
|
# Create a new filesystem scanner. In addition to the options
|
32
33
|
# recognized by Builder, this class recognizes <tt>:retriever</tt> and
|
@@ -85,9 +86,10 @@ module RightScraper
|
|
85
86
|
if File.directory?(fullpath)
|
86
87
|
maybe_scan(Dir.new(fullpath), relative_position)
|
87
88
|
else
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
# bind the temporary parameters to the callback in case it is not
|
90
|
+
# invoked immediately.
|
91
|
+
bind_now = lambda{|file| lambda{ open(file) {|f| f.read} } }.call(fullpath)
|
92
|
+
@scanner.notice(relative_position, &bind_now)
|
91
93
|
end
|
92
94
|
end
|
93
95
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright: Copyright (c) 2010-
|
2
|
+
# Copyright: Copyright (c) 2010-2013 RightScale, Inc.
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -21,6 +21,9 @@
|
|
21
21
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
+
# ancestor
|
25
|
+
require 'right_scraper/builders'
|
26
|
+
|
24
27
|
module RightScraper
|
25
28
|
module Builders
|
26
29
|
# Union builder, to permit running multiple builders in sequence
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 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
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
23
|
+
# ancestor
|
24
|
+
require 'right_scraper'
|
25
|
+
|
26
|
+
module RightScraper
|
27
|
+
module Loggers
|
28
|
+
autoload :Base, 'right_scraper/loggers/base'
|
29
|
+
autoload :Default, 'right_scraper/loggers/default'
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright: Copyright (c) 2013 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
|
+
# ancestor
|
25
|
+
require 'right_scraper/loggers'
|
26
|
+
|
27
|
+
require 'logger'
|
28
|
+
|
29
|
+
module RightScraper
|
30
|
+
module Loggers
|
31
|
+
class Base < ::Logger
|
32
|
+
|
33
|
+
attr_accessor :callback, :errors, :warnings
|
34
|
+
|
35
|
+
def initialize(*args)
|
36
|
+
super(*args)
|
37
|
+
@abort_seen = false
|
38
|
+
@callback = nil
|
39
|
+
@errors = []
|
40
|
+
@warnings = []
|
41
|
+
end
|
42
|
+
|
43
|
+
# Encapsulates an operation that merits logging.
|
44
|
+
#
|
45
|
+
# @param [Symbol] type of operation
|
46
|
+
# @param [String] explanation of operation or empty
|
47
|
+
#
|
48
|
+
# @yield [] operational callback (required)
|
49
|
+
#
|
50
|
+
# @return [Object] result of callback
|
51
|
+
def operation(type, explanation = '')
|
52
|
+
begin
|
53
|
+
note_phase(:begin, type, explanation)
|
54
|
+
result = yield
|
55
|
+
note_phase(:commit, type, explanation)
|
56
|
+
result
|
57
|
+
rescue Exception => e
|
58
|
+
note_phase(:abort, type, explanation, e)
|
59
|
+
raise
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Note a phase change within an operation.
|
64
|
+
#
|
65
|
+
# @param [Symbol] phase of operation; one of :begin, :commit, :abort
|
66
|
+
# @param [Symbol] type of operation
|
67
|
+
# @param [String] explanation of operation or nil
|
68
|
+
# @param [Exception] exception or nil
|
69
|
+
#
|
70
|
+
# @return [TrueClass] always true
|
71
|
+
def note_phase(phase, type, explanation, exception = nil)
|
72
|
+
@callback.call(phase, type, explanation, exception) if @callback
|
73
|
+
case phase
|
74
|
+
when :begin
|
75
|
+
@abort_seen = false
|
76
|
+
when :commit
|
77
|
+
# do nothing
|
78
|
+
when :abort
|
79
|
+
unless @abort_seen
|
80
|
+
note_error(exception, type, explanation)
|
81
|
+
@abort_seen = true
|
82
|
+
end
|
83
|
+
else
|
84
|
+
fail 'Unknown phase'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Note an error, with the given exception and explanation of what
|
89
|
+
# was going on.
|
90
|
+
#
|
91
|
+
# @param [Exception] exception or nil
|
92
|
+
# @param [Symbol] type of operation
|
93
|
+
# @param [String] explanation of operation or nil
|
94
|
+
#
|
95
|
+
# @return [TrueClass] always true
|
96
|
+
def note_error(exception, type, explanation = nil)
|
97
|
+
raise NotImplementedError
|
98
|
+
end
|
99
|
+
|
100
|
+
# Note a warning for current operation.
|
101
|
+
#
|
102
|
+
# @param [Exception] exception or nil
|
103
|
+
# @param [Symbol] type of operation
|
104
|
+
# @param [String] explanation of operation or nil
|
105
|
+
#
|
106
|
+
# @return [TrueClass] always true
|
107
|
+
def note_warning(message)
|
108
|
+
raise NotImplementedError
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright: Copyright (c) 2010-2013 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
|
+
# ancestor
|
25
|
+
require 'right_scraper/loggers'
|
26
|
+
|
27
|
+
module RightScraper::Loggers
|
28
|
+
|
29
|
+
# provides a default scraper logger implementation that accumulates errors and
|
30
|
+
# warnings but otherwise is a null logger.
|
31
|
+
class Default < ::RightScraper::Loggers::Base
|
32
|
+
|
33
|
+
def initialize(*args)
|
34
|
+
if args.empty?
|
35
|
+
is_windows = !!(RUBY_PLATFORM =~ /mswin|win32|dos|mingw|cygwin/)
|
36
|
+
super(is_windows ? 'nul' : '/dev/null')
|
37
|
+
else
|
38
|
+
super(*args)
|
39
|
+
end
|
40
|
+
self.level = ::Logger::ERROR
|
41
|
+
@recording_messages = true
|
42
|
+
end
|
43
|
+
|
44
|
+
# implements Interface#note_error
|
45
|
+
def note_error(exception, type, explanation = '')
|
46
|
+
without_recording_messages do
|
47
|
+
explanation = explanation.to_s.strip
|
48
|
+
message = "Saw #{exception ? exception.message : 'error'} during #{type}"
|
49
|
+
message += ": #{explanation}" unless explanation.empty?
|
50
|
+
error(message)
|
51
|
+
end
|
52
|
+
@errors << [exception, type, explanation]
|
53
|
+
end
|
54
|
+
|
55
|
+
# implements Interface#note_warning
|
56
|
+
def note_warning(message)
|
57
|
+
without_recording_messages { warn(message) }
|
58
|
+
@warnings << message
|
59
|
+
end
|
60
|
+
|
61
|
+
# overrides ::Logger#add in order to record errors and warnings logged via
|
62
|
+
# the normal logger interface.
|
63
|
+
def add(severity, message = nil, progname = nil)
|
64
|
+
if severity >= self.level
|
65
|
+
# super logger.
|
66
|
+
if message.nil?
|
67
|
+
if block_given?
|
68
|
+
message = yield
|
69
|
+
else
|
70
|
+
message = progname
|
71
|
+
progname = self.progname
|
72
|
+
end
|
73
|
+
end
|
74
|
+
super(severity, message, progname)
|
75
|
+
|
76
|
+
# record errors (with detail) and warnings.
|
77
|
+
if @recording_messages
|
78
|
+
if severity >= Logger::ERROR
|
79
|
+
@errors << [nil, :log, message]
|
80
|
+
elsif severity == ::Logger::WARN
|
81
|
+
@warnings << message
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
protected
|
89
|
+
|
90
|
+
def without_recording_messages
|
91
|
+
old_recording_messages = @recording_messages
|
92
|
+
@recording_messages = false
|
93
|
+
yield
|
94
|
+
ensure
|
95
|
+
@recording_messages = old_recording_messages
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|