chupa-text 1.2.9 → 1.3.0
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 +4 -4
- data/doc/text/news.md +6 -0
- data/lib/chupa-text.rb +3 -1
- data/lib/chupa-text/external-command.rb +5 -4
- data/lib/chupa-text/extractor.rb +1 -1
- data/lib/chupa-text/loggable.rb +5 -1
- data/lib/chupa-text/timeout-value.rb +76 -0
- data/lib/chupa-text/version.rb +1 -1
- data/test/test-external-command.rb +8 -8
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05b8ad4429bce26f6214f56945421c081f45749cda69af7183f6fb22cdac84b3
|
4
|
+
data.tar.gz: 1206a3c78638409189df999c9f935706460775be7512d99708fa4c193f05ab78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e7431e9bdc817caa55f7bcd78b775d7ccd22918817def1f0904123e29b14a9d3709a51e6e2b7a25a829ff463159468e521fee058511b985874fccbeb6e356aa
|
7
|
+
data.tar.gz: 7d02f3dff8cf7de87ea637783d8c4b25e4ef8c227ed42773d39cc2496902c884ee2f05f130493faf897c799698800bfa853af25282988618a5078fb2a81fcd55
|
data/doc/text/news.md
CHANGED
data/lib/chupa-text.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Kouhei
|
1
|
+
# Copyright (C) 2013-2019 Sutou Kouhei <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -26,6 +26,8 @@ require "chupa-text/logger"
|
|
26
26
|
require "chupa-text/loggable"
|
27
27
|
require "chupa-text/unzippable"
|
28
28
|
|
29
|
+
require "chupa-text/timeout-value"
|
30
|
+
|
29
31
|
require "chupa-text/configuration"
|
30
32
|
require "chupa-text/configuration-loader"
|
31
33
|
require "chupa-text/mime-type"
|
@@ -255,20 +255,21 @@ module ChupaText
|
|
255
255
|
end
|
256
256
|
|
257
257
|
def log_invalid_value(tag, value, type)
|
258
|
-
|
258
|
+
super("#{log_tag}#{tag}", value, type)
|
259
259
|
end
|
260
260
|
|
261
261
|
def wait_process(pid, timeout, soft_timeout)
|
262
262
|
tag = "[timeout]"
|
263
|
-
timeout =
|
264
|
-
soft_timeout =
|
263
|
+
timeout = TimeoutValue.new(tag, timeout || self.class.default_timeout).raw
|
264
|
+
soft_timeout = TimeoutValue.new(tag, soft_timeout).raw
|
265
265
|
if timeout
|
266
266
|
timeout = soft_timeout if soft_timeout and soft_timeout < timeout
|
267
267
|
else
|
268
268
|
timeout = soft_timeout
|
269
269
|
end
|
270
270
|
if timeout
|
271
|
-
info("#{log_tag}#{tag}[use]
|
271
|
+
info("#{log_tag}#{tag}[use] " +
|
272
|
+
"<#{TimeoutValue.new(tag, timeout)}>: <#{pid}>")
|
272
273
|
status = wait_process_timeout(pid, timeout)
|
273
274
|
return status if status
|
274
275
|
info("#{log_tag}#{tag}[terminate] <#{pid}>")
|
data/lib/chupa-text/extractor.rb
CHANGED
data/lib/chupa-text/loggable.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Kouhei
|
1
|
+
# Copyright (C) 2013-2019 Sutou Kouhei <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -45,5 +45,9 @@ module ChupaText
|
|
45
45
|
def unknown(*arguments, &block)
|
46
46
|
logger.unknown(*arguments, &block)
|
47
47
|
end
|
48
|
+
|
49
|
+
def log_invalid_value(tag, value, type)
|
50
|
+
warn("#{tag}[invalid] <#{value}>(#{type})")
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Copyright (C) 2019 Sutou Kouhei <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "English"
|
18
|
+
|
19
|
+
module ChupaText
|
20
|
+
class TimeoutValue
|
21
|
+
include Comparable
|
22
|
+
include Loggable
|
23
|
+
|
24
|
+
attr_reader :raw
|
25
|
+
def initialize(tag, value)
|
26
|
+
value = parse(value) if value.is_a?(String)
|
27
|
+
@raw = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
return "" if @raw.nil?
|
32
|
+
|
33
|
+
if @raw < 1
|
34
|
+
"%.2fms" % (@raw * 1000.0)
|
35
|
+
elsif @raw < 60
|
36
|
+
"%.2fs" % @raw
|
37
|
+
elsif @raw < (60 * 60)
|
38
|
+
"%.2fm" % (@raw / 60.0)
|
39
|
+
else
|
40
|
+
"%.2fh" % (@raw / 60.0 / 60.0)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def parse(value)
|
46
|
+
case value
|
47
|
+
when nil
|
48
|
+
nil
|
49
|
+
when Numeric
|
50
|
+
value
|
51
|
+
else
|
52
|
+
return nil if value.empty?
|
53
|
+
scale = 1
|
54
|
+
case value
|
55
|
+
when /h\z/i
|
56
|
+
scale = 60 * 60
|
57
|
+
number = $PREMATCH
|
58
|
+
when /m\z/i
|
59
|
+
scale = 60
|
60
|
+
number = $PREMATCH
|
61
|
+
when /s\z/i
|
62
|
+
number = $PREMATCH
|
63
|
+
else
|
64
|
+
number = value
|
65
|
+
end
|
66
|
+
begin
|
67
|
+
number = Float(number)
|
68
|
+
rescue ArgumentError
|
69
|
+
log_invalid_value(@tag, value, "time")
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
(number * scale).to_f
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/chupa-text/version.rb
CHANGED
@@ -102,7 +102,7 @@ class TestExternalCommand < Test::Unit::TestCase
|
|
102
102
|
assert_equal([
|
103
103
|
[
|
104
104
|
:info,
|
105
|
-
"[external-command][timeout][use] <
|
105
|
+
"[external-command][timeout][use] <1.00m>: <#{pid}>",
|
106
106
|
]
|
107
107
|
],
|
108
108
|
messages)
|
@@ -117,7 +117,7 @@ class TestExternalCommand < Test::Unit::TestCase
|
|
117
117
|
assert_equal([
|
118
118
|
[
|
119
119
|
:info,
|
120
|
-
"[external-command][timeout][use] <
|
120
|
+
"[external-command][timeout][use] <1.00m>: <#{pid}>",
|
121
121
|
]
|
122
122
|
],
|
123
123
|
messages)
|
@@ -132,7 +132,7 @@ class TestExternalCommand < Test::Unit::TestCase
|
|
132
132
|
assert_equal([
|
133
133
|
[
|
134
134
|
:info,
|
135
|
-
"[external-command][timeout][use] <30.
|
135
|
+
"[external-command][timeout][use] <30.00s>: <#{pid}>",
|
136
136
|
]
|
137
137
|
],
|
138
138
|
messages)
|
@@ -147,7 +147,7 @@ class TestExternalCommand < Test::Unit::TestCase
|
|
147
147
|
assert_equal([
|
148
148
|
[
|
149
149
|
:info,
|
150
|
-
"[external-command][timeout][use] <30.
|
150
|
+
"[external-command][timeout][use] <30.00s>: <#{pid}>",
|
151
151
|
]
|
152
152
|
],
|
153
153
|
messages)
|
@@ -162,7 +162,7 @@ class TestExternalCommand < Test::Unit::TestCase
|
|
162
162
|
assert_equal([
|
163
163
|
[
|
164
164
|
:info,
|
165
|
-
"[external-command][timeout][use] <
|
165
|
+
"[external-command][timeout][use] <1.00m>: <#{pid}>",
|
166
166
|
]
|
167
167
|
],
|
168
168
|
messages)
|
@@ -178,7 +178,7 @@ class TestExternalCommand < Test::Unit::TestCase
|
|
178
178
|
assert_equal([
|
179
179
|
[
|
180
180
|
:info,
|
181
|
-
"[external-command][timeout][use] <
|
181
|
+
"[external-command][timeout][use] <1.00m>: <#{pid}>",
|
182
182
|
]
|
183
183
|
],
|
184
184
|
messages)
|
@@ -194,7 +194,7 @@ class TestExternalCommand < Test::Unit::TestCase
|
|
194
194
|
assert_equal([
|
195
195
|
[
|
196
196
|
:info,
|
197
|
-
"[external-command][timeout][use] <30.
|
197
|
+
"[external-command][timeout][use] <30.00s>: <#{pid}>",
|
198
198
|
]
|
199
199
|
],
|
200
200
|
messages)
|
@@ -209,7 +209,7 @@ class TestExternalCommand < Test::Unit::TestCase
|
|
209
209
|
assert_equal([
|
210
210
|
[
|
211
211
|
:info,
|
212
|
-
"[external-command][timeout][use] <30.
|
212
|
+
"[external-command][timeout][use] <30.00s>: <#{pid}>",
|
213
213
|
]
|
214
214
|
],
|
215
215
|
messages)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chupa-text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: archive-zip
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- lib/chupa-text/screenshot.rb
|
192
192
|
- lib/chupa-text/size-parser.rb
|
193
193
|
- lib/chupa-text/text-data.rb
|
194
|
+
- lib/chupa-text/timeout-value.rb
|
194
195
|
- lib/chupa-text/unzippable.rb
|
195
196
|
- lib/chupa-text/utf8-converter.rb
|
196
197
|
- lib/chupa-text/version.rb
|