right_scraper 3.2.3 → 3.2.4
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.
data/lib/right_scraper/logger.rb
CHANGED
@@ -34,6 +34,17 @@ begin
|
|
34
34
|
|
35
35
|
module Git
|
36
36
|
class Lib
|
37
|
+
# Monkey patch to prevent screw up any subsequent shell out to git
|
38
|
+
def command_with_preserved_env(cmd, opts = [], chdir = true, redirect = '', &block)
|
39
|
+
variables_to_preserve = ['GIT_DIR', 'GIT_INDEX_FILE', 'GIT_WORK_TREE']
|
40
|
+
preserved_env = Hash[variables_to_preserve.map { |var| [var, ENV[var]] }]
|
41
|
+
begin
|
42
|
+
command_without_preserved_env(cmd, opts, chdir, redirect, &block)
|
43
|
+
ensure
|
44
|
+
preserved_env.each { |var, value| ENV[var] = value }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
37
48
|
# Monkey patch to blackwinter-git that strips ANSI escape sequences
|
38
49
|
# from command output to avoid confusing the parser.
|
39
50
|
def run_command_with_color_stripping(git_cmd, &block)
|
@@ -46,6 +57,11 @@ begin
|
|
46
57
|
alias :run_command_without_color_stripping :run_command
|
47
58
|
alias :run_command :run_command_with_color_stripping
|
48
59
|
end
|
60
|
+
|
61
|
+
unless self.methods.include?('command_without_preserved_env')
|
62
|
+
alias :command_without_preserved_env :command
|
63
|
+
alias :command :command_with_preserved_env
|
64
|
+
end
|
49
65
|
end
|
50
66
|
end
|
51
67
|
rescue ::Git::GitExecuteError
|
@@ -86,12 +102,61 @@ module RightScraper
|
|
86
102
|
# fresh SSHAgent and add the credential to it.
|
87
103
|
def retrieve
|
88
104
|
raise RetrieverError.new("git retriever is unavailable") unless available?
|
105
|
+
|
106
|
+
start_time = nil
|
107
|
+
end_time = nil
|
89
108
|
RightScraper::Processes::SSHAgent.with do |agent|
|
90
109
|
unless @repository.first_credential.nil? || @repository.first_credential.empty?
|
91
110
|
agent.add_key(@repository.first_credential)
|
92
111
|
end
|
112
|
+
start_time = ::Time.now
|
93
113
|
super
|
114
|
+
end_time = ::Time.now
|
115
|
+
end
|
116
|
+
|
117
|
+
# TEAL FIX: the use of blackwinter-git has defeated the logic that
|
118
|
+
# ensured the max bytes was not exceeded during checkout. we will need
|
119
|
+
# to replace blackwinter-git in future but in the interim our only
|
120
|
+
# solution is to warn the user after the checkout has completed that we
|
121
|
+
# are going to restrict their repo size/time in an upcoming release.
|
122
|
+
if size_limit_exceeded?
|
123
|
+
message =
|
124
|
+
"The size of the downloaded repository exceeded a soft limit of" +
|
125
|
+
" #{@max_bytes / (1024 * 1024)} MB. This will become a hard limit" +
|
126
|
+
" in an upcoming release. You may avoid retrieval failure by" +
|
127
|
+
" moving some of your files to seperate repositories."
|
128
|
+
@logger.note_warning(message)
|
129
|
+
end
|
130
|
+
if @max_seconds && (end_time >= start_time + @max_seconds)
|
131
|
+
message =
|
132
|
+
"The time to download the repository exceeded a soft limit of" +
|
133
|
+
" #{@max_seconds} seconds. This will become a hard limit" +
|
134
|
+
" in an upcoming release. You may avoid retrieval failure by" +
|
135
|
+
" moving some of your files to seperate repositories."
|
136
|
+
@logger.note_warning(message)
|
137
|
+
end
|
138
|
+
true
|
139
|
+
end
|
140
|
+
|
141
|
+
# Determines if total size of files created by child process has exceeded
|
142
|
+
# the limit specified, if any.
|
143
|
+
#
|
144
|
+
# === Return
|
145
|
+
# @return [TrueClass|FalseClass] true if size limit exceeded
|
146
|
+
def size_limit_exceeded?
|
147
|
+
exceeded = false
|
148
|
+
if @max_bytes
|
149
|
+
globbie = ::File.join(@repo_dir, '**/*')
|
150
|
+
size = 0
|
151
|
+
::Dir.glob(globbie) do |f|
|
152
|
+
size += ::File.stat(f).size rescue 0 if ::File.file?(f)
|
153
|
+
if size > @max_bytes
|
154
|
+
exceeded = true
|
155
|
+
break
|
156
|
+
end
|
157
|
+
end
|
94
158
|
end
|
159
|
+
exceeded
|
95
160
|
end
|
96
161
|
|
97
162
|
# Return true if a checkout exists. Currently tests for .git in
|
@@ -24,8 +24,7 @@
|
|
24
24
|
module RightScraper
|
25
25
|
|
26
26
|
class ScraperLogger < Logger
|
27
|
-
attr_accessor :errors
|
28
|
-
attr_accessor :callback
|
27
|
+
attr_accessor :callback, :errors, :warnings
|
29
28
|
|
30
29
|
def add(severity, message=nil, progname=nil)
|
31
30
|
if severity >= (self.level || Logger::WARN)
|
@@ -46,6 +45,7 @@ module RightScraper
|
|
46
45
|
|
47
46
|
def initialize
|
48
47
|
@errors = []
|
48
|
+
@warnings = []
|
49
49
|
end
|
50
50
|
|
51
51
|
def note_phase(phase, type, explanation, exception=nil)
|
@@ -56,6 +56,11 @@ module RightScraper
|
|
56
56
|
def note_error(exception, type, explanation="")
|
57
57
|
@errors << [exception, type, explanation]
|
58
58
|
end
|
59
|
+
|
60
|
+
def note_warning(message)
|
61
|
+
@warnings << message
|
62
|
+
end
|
63
|
+
|
59
64
|
end
|
60
65
|
|
61
66
|
end
|
data/right_scraper.gemspec
CHANGED
@@ -24,7 +24,7 @@ require 'rubygems'
|
|
24
24
|
|
25
25
|
Gem::Specification.new do |spec|
|
26
26
|
spec.name = 'right_scraper'
|
27
|
-
spec.version = '3.2.
|
27
|
+
spec.version = '3.2.4'
|
28
28
|
spec.authors = ['Graham Hughes', 'Raphael Simon', 'Scott Messier']
|
29
29
|
spec.email = 'raphael@rightscale.com'
|
30
30
|
spec.homepage = 'https://github.com/rightscale/right_scraper'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 3.2.
|
9
|
+
- 4
|
10
|
+
version: 3.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Graham Hughes
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2013-
|
20
|
+
date: 2013-08-13 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|