miga-base 1.3.15.8 → 1.3.15.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67a4b45cec67cd472fc681bd0993b0ba7bb3f36229e0a6cf5120333131a65b72
4
- data.tar.gz: 968803414089403de2f50e4fe11624b57dc6b69ddeb37a22e5fac365b8fd8224
3
+ metadata.gz: 064e93465ac48e77eb31406064706cc7a10e1b34b73fea9216a7759f23f4982c
4
+ data.tar.gz: 2818f9708bfbaa8e43f6742c5bfb963a00f68737a07b4afdb3a693ce58a49f40
5
5
  SHA512:
6
- metadata.gz: bee8323fb44d70b5577baa076b77ebe7a8cdc69ffb40a535fdd714d299d09a08dd3dc73352325d11f1ade061ffca222d53e98602486bfd7571a773dca7ad2f47
7
- data.tar.gz: 245b2f64128473dcda952e82874fa3c1fad2a0b7aa0b82c8a57bb9a13f01c16094b5a9249899e4212224e10d9853e8b99d3c1c83bef7229a70c07b454ee09513
6
+ metadata.gz: b6b8df2cfd819f69fcc5bf922d0a57d0cb33f48a4bf6371fc1a5433c9571902ca3f1ed8a8c7df5c1df2b35f05da820545b51e046e60ba692eeff7e77e46d1699
7
+ data.tar.gz: '024922760df8f9cffdc72fb96df36fe8d4805b41b885164280af6633cf45f6da95fa5cb647d44a8149d1e81026d41e397888c453f97adc0ee7ea176b50ff6507'
@@ -139,7 +139,7 @@ class MiGA::Cli::Action::Db < MiGA::Cli::Action
139
139
  MiGA::MiGA.download_file_ftp(ftp, path, file) do |n, size|
140
140
  cli.advance("#{path}:", n, size) if cli[:pb]
141
141
  end
142
- cli.print "\n" if cli[:pb]
142
+ cli.say '' if cli[:pb]
143
143
  end
144
144
  file
145
145
  end
@@ -225,11 +225,16 @@ class MiGA::Cli::Action::Db < MiGA::Cli::Action
225
225
  cli.say 'Checking MD5 digest'
226
226
  cli.say "Expected: #{ver[:MD5]}"
227
227
  md5 = Digest::MD5.new
228
+ size = File.size(file)
229
+ n = 0
228
230
  File.open(file, 'rb') do |fh|
229
231
  until fh.eof?
230
- md5.update fh.read(1024)
232
+ md5 << fh.read(1024)
233
+ n += 1024
234
+ cli.advance('Processed:', [n, size].min, size) if cli[:pb]
231
235
  end
232
236
  end
237
+ cli.say '' if cli[:pb]
233
238
  dig = md5.hexdigest
234
239
  cli.say "Observed: #{dig}"
235
240
  raise 'Corrupt file, MD5 does not match' unless dig == ver[:MD5]
data/lib/miga/common.rb CHANGED
@@ -64,25 +64,33 @@ class MiGA::MiGA
64
64
  # The report goes to $stderr iff --verbose
65
65
  def advance(step, n = 0, total = nil, bin = true)
66
66
  # Initialize advance timing
67
- @_advance_time ||= { last: nil, n: 0, avg: nil }
68
- if @_advance_time[:n] > n
67
+ @_advance_time ||= { last: nil, n: 0, avg: nil, total: total }
68
+ if @_advance_time[:n] > n || total != @_advance_time[:total]
69
69
  @_advance_time[:last] = nil
70
70
  @_advance_time[:n] = 0
71
71
  @_advance_time[:avg] = nil
72
+ @_advance_time[:total] = total
72
73
  end
73
74
 
74
75
  # Estimate timing
75
76
  adv_n = n - @_advance_time[:n]
76
77
  if total.nil? || @_advance_time[:last].nil? || adv_n.negative?
78
+ # Initial report
77
79
  @_advance_time[:last] = Time.now
78
80
  @_advance_time[:n] = n
79
81
  elsif adv_n > 0.001 * total
82
+ # Advance report (if change > 0.1% change and time > 1 second)
80
83
  this_time = (Time.now - @_advance_time[:last]).to_f
84
+ return if this_time < 1.0 && n < total
85
+
81
86
  this_avg = this_time / adv_n
82
87
  @_advance_time[:avg] ||= this_avg
83
88
  @_advance_time[:avg] = 0.9 * @_advance_time[:avg] + 0.1 * this_avg
84
89
  @_advance_time[:last] = Time.now
85
90
  @_advance_time[:n] = n
91
+ else
92
+ # Final report (if the last update was too small) or ignore update
93
+ return if n < total
86
94
  end
87
95
 
88
96
  # Report
data/lib/miga/version.rb CHANGED
@@ -12,7 +12,7 @@ module MiGA
12
12
  # - String indicating release status:
13
13
  # - rc* release candidate, not released as gem
14
14
  # - [0-9]+ stable release, released as gem
15
- VERSION = [1.3, 15, 8].freeze
15
+ VERSION = [1.3, 15, 9].freeze
16
16
 
17
17
  ##
18
18
  # Nickname for the current major.minor version.
data/test/common_test.rb CHANGED
@@ -76,23 +76,26 @@ class CommonTest < Test::Unit::TestCase
76
76
  def test_advance
77
77
  m = MiGA::MiGA.new
78
78
 
79
- # Check advance when missing total
79
+ # Check advance when missing total and n
80
80
  o = capture_stderr { m.advance('x', 0) }.string
81
81
  assert_match(%r{\] x *\r}, o)
82
82
 
83
+ # Check advance when missing total
84
+ o = capture_stderr { m.advance('x', 10) }.string
85
+ assert_match(%r{\] x 10 *\r}, o)
86
+
83
87
  # Initialize advance
84
88
  o = capture_stderr { m.advance('x', 0, 1001) }.string
85
89
  assert_match(%r{\] x 0\.0% \(0/1001\) *\r}, o)
86
90
 
87
91
  # Insufficient data for prediction
88
- sleep(1)
89
92
  o = capture_stderr { m.advance('x', 1, 1000) }.string
90
93
  assert_match(%r{\] x 0\.1% \(1/1000\) *\r}, o)
91
94
 
92
95
  # Predict time
93
- sleep(1)
94
- o = capture_stderr { m.advance('x', 2, 1000) }.string
95
- assert_match(%r{\] x 0\.2% \(2/1000\) 1\d\.\dm left *\r}, o)
96
+ sleep(1.01)
97
+ o = capture_stderr { m.advance('x', 4, 1000) }.string
98
+ assert_match(%r{\] x 0\.4% \(4/1000\) \d\.\dm left *\r}, o)
96
99
  end
97
100
 
98
101
  def test_num_suffix
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.15.8
4
+ version: 1.3.15.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R