Generic class used to handle system-wide information and methods, and parent of all other MiGA::* classes.
Reference of MiGA
# File lib/miga/version.rb, line 60 def self.CITATION CITATION end
Send debug message
# File lib/miga/common/base.rb, line 31 def DEBUG(*args) $stderr.puts(*args) if @@DEBUG $stderr.puts( caller.map { |v| v.gsub(/^/, ' ') }.join("\n") ) if @@DEBUG_TRACE end
Turn off debugging
# File lib/miga/common/base.rb, line 12 def DEBUG_OFF @@DEBUG = false end
Turn on debugging
# File lib/miga/common/base.rb, line 6 def DEBUG_ON @@DEBUG = true end
Turn off debug tracing (but not debugging)
# File lib/miga/common/base.rb, line 25 def DEBUG_TRACE_OFF @@DEBUG_TRACE = false end
Turn on debug tracing (and debugging)
# File lib/miga/common/base.rb, line 18 def DEBUG_TRACE_ON @@DEBUG_TRACE = true DEBUG_ON() end
Complete version as string
# File lib/miga/version.rb, line 42 def self.FULL_VERSION VERSION.join('.') end
Complete version with nickname and date as string
# File lib/miga/version.rb, line 48 def self.LONG_VERSION "MiGA #{VERSION.join('.')} - #{VERSION_NAME} - #{VERSION_DATE}" end
Major.minor version as Float
# File lib/miga/version.rb, line 36 def self.VERSION VERSION[0] end
Date of the current gem release
# File lib/miga/version.rb, line 54 def self.VERSION_DATE VERSION_DATE end
Has MiGA been initialized?
# File lib/miga/common.rb, line 26 def self.initialized? File.exist?(File.expand_path('.miga_rc', ENV['MIGA_HOME'])) and File.exist?(File.expand_path('.miga_daemon.json', ENV['MIGA_HOME'])) end
Reports the advance of a task at step
(String), the
n
out of total
. The advance is reported in powers
of 1,024 if bin
is true, or powers of 1,000 otherwise. The
report goes to $stderr iff –verborse
# File lib/miga/common.rb, line 56 def advance(step, n = 0, total = nil, bin = true) # Initialize advance timing @_advance_time ||= { last: nil, n: 0, avg: nil } if n <= 1 || @_advance_time[:n] > n @_advance_time[:last] = nil @_advance_time[:n] = 0 @_advance_time[:avg] = nil end # Estimate timing adv_n = n - @_advance_time[:n] unless total.nil? || @_advance_time[:last].nil? || adv_n <= 0 if adv_n.to_f/n > 0.001 this_time = (Time.now - @_advance_time[:last]).to_f this_avg = this_time / adv_n @_advance_time[:avg] ||= this_avg @_advance_time[:avg] = 0.9 * @_advance_time[:avg] + 0.1 * this_avg end end @_advance_time[:last] = Time.now @_advance_time[:n] = n # Report adv = if total.nil? (n == 0 ? '' : num_suffix(n, bin)) else vals = [100.0 * n / total, num_suffix(n, bin), num_suffix(total, bin)] ('%.1f%% (%s/%s)' % vals) end left = if @_advance_time[:avg].nil? '' else left_time = @_advance_time[:avg] * (total - n) / 60 # <- in minutes left_time < 0.01 ? ' ' : left_time < 1 ? ('%.0fs left' % (left_time * 60)) : left_time > 1440 ? ('%.1fd left' % (left_time / 1440)) : left_time > 60 ? ('%.1fh left' % (left_time / 60)) : ('%.1fm left' % left_time) end $stderr.print("[%s] %s %s %s \r" % [Time.now, step, adv, left]) end
# File lib/miga/common.rb, line 116 def like_io?(obj) obj.is_a?(IO) || obj.is_a?(StringIO) end
Return formatted number n
with the appropriate units as powers
of 1,000 (if bin
if false) or 1,024 (otherwise)
# File lib/miga/common.rb, line 103 def num_suffix(n, bin = false) p = '' { T: 4, G: 3, M: 2, K: 1 }.each do |k, x| v = (bin ? 1024 : 1e3)**x if n > v n = '%.1f' % (n / v) p = k break end end "#{n}#{p}" end
Check if the result files exist with base
name (String)
followed by the ext
values (Array of String).
# File lib/miga/common.rb, line 34 def result_files_exist?(base, ext) ext = [ext] unless ext.is_a? Array ext.all? do |f| File.exist?(base + f) or File.exist?("#{base}#{f}.gz") end end
Print par
ensuring new line at the end. Date/time-stamp each
line. If the first parameter is IO
or StringIO
the output is sent there, otherwise it's sent to +$stderr+
# File lib/miga/common.rb, line 46 def say(*par) io = like_io?(par.first) ? par.shift : $stderr io.puts(*par.map { |i| "[#{Time.now}] #{i}" }) end