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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a96f66fb14ab05d80ef7d53494ee20d2aae298397d3b787591efd3ebfb30d5ab
4
- data.tar.gz: 7dcaeb98ff526ea31b52871b492211d624b607957146aa6986eb5b6d41eba2e4
3
+ metadata.gz: 05b8ad4429bce26f6214f56945421c081f45749cda69af7183f6fb22cdac84b3
4
+ data.tar.gz: 1206a3c78638409189df999c9f935706460775be7512d99708fa4c193f05ab78
5
5
  SHA512:
6
- metadata.gz: 8c07878c8308483eebecc3e683c74dbc4ce00ee1841ac588c82ba173bd1644bde026703934e34f66ebaf8ca369091cbff3940025953992bf572d5c038718b746
7
- data.tar.gz: b8989bb876e8cafe5097bf5667a9e8fd796c7a8e9331254b4f5afef54774584a21ea0de20ea892745a9227275c21577f94d7399a76fb27963e3f0a09ca53e58f
6
+ metadata.gz: 9e7431e9bdc817caa55f7bcd78b775d7ccd22918817def1f0904123e29b14a9d3709a51e6e2b7a25a829ff463159468e521fee058511b985874fccbeb6e356aa
7
+ data.tar.gz: 7d02f3dff8cf7de87ea637783d8c4b25e4ef8c227ed42773d39cc2496902c884ee2f05f130493faf897c799698800bfa853af25282988618a5078fb2a81fcd55
data/doc/text/news.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # News
2
2
 
3
+ ## 1.3.0: 2019-06-14
4
+
5
+ ### Fixes
6
+
7
+ * Added support for timeout as string again.
8
+
3
9
  ## 1.2.9: 2019-06-13
4
10
 
5
11
  ### Improvements
data/lib/chupa-text.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
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
- warn("#{log_tag}#{tag}[invalid] <#{value}>(#{type})")
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 = parse_time(tag, timeout || self.class.default_timeout)
264
- soft_timeout = parse_time(tag, 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] <#{timeout}s>: <#{pid}>")
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}>")
@@ -123,7 +123,7 @@ module ChupaText
123
123
  end
124
124
 
125
125
  def with_timeout(data, &block)
126
- timeout = data.timeout
126
+ timeout = TimeoutValue.new("#{log_tag}[timeout]", data.timeout).raw
127
127
  if timeout
128
128
  begin
129
129
  Timeout.timeout(timeout, &block)
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
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
@@ -15,5 +15,5 @@
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
  module ChupaText
18
- VERSION = "1.2.9"
18
+ VERSION = "1.3.0"
19
19
  end
@@ -102,7 +102,7 @@ class TestExternalCommand < Test::Unit::TestCase
102
102
  assert_equal([
103
103
  [
104
104
  :info,
105
- "[external-command][timeout][use] <60.0s>: <#{pid}>",
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] <60.0s>: <#{pid}>",
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.0s>: <#{pid}>",
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.0s>: <#{pid}>",
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] <60.0s>: <#{pid}>",
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] <60.0s>: <#{pid}>",
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.0s>: <#{pid}>",
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.0s>: <#{pid}>",
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.2.9
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-13 00:00:00.000000000 Z
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