class VpsbClient::Datafiles::SarManager
Attributes
sadf_runner[R]
Public Class Methods
new(orig_path, target_path, sadf = Sadf)
click to toggle source
# File lib/vpsb_client/datafiles/sar_manager.rb, line 10 def initialize(orig_path, target_path, sadf = Sadf) raise NotFoundError, "#{orig_path} is not a directory" unless File.directory?(orig_path) @orig_path = orig_path @target_path = target_path @sadf_runner = sadf end
Public Instance Methods
run()
click to toggle source
# File lib/vpsb_client/datafiles/sar_manager.rb, line 17 def run create_target_path create_daily_formatted create_current_day_temp_formatted end
Private Instance Methods
create_current_day_temp_formatted()
click to toggle source
# File lib/vpsb_client/datafiles/sar_manager.rb, line 48 def create_current_day_temp_formatted sa_filename = "#{@orig_path}/sa#{Time.now.strftime('%Y%m%d')}" formatted_filename = "#{@target_path}/formatted_sa#{Time.now.strftime('%Y%m%d')}" File.delete(formatted_filename) if File.exist?(formatted_filename) sadf(sa_filename, formatted_filename) end
create_daily_formatted()
click to toggle source
# File lib/vpsb_client/datafiles/sar_manager.rb, line 34 def create_daily_formatted raw_sar_filenames = Dir.glob("#{@orig_path}/sa*") raw_sar_filenames.each do |filename| filename.match /sa(?<num>\d+)$/ do |matchdata| fileday = matchdata[:num] next if fileday == Time.now.strftime('%Y%m%d') formatted_filename = "#{@target_path}/formatted_sa#{fileday}" next if File.exist?(formatted_filename) sadf(filename, formatted_filename) end end end
create_target_path()
click to toggle source
# File lib/vpsb_client/datafiles/sar_manager.rb, line 25 def create_target_path if File.directory?(@target_path) raise PermissionDeniedError, "#{@target_path} is not writable" unless File.writable?(@target_path) return end raise PermissionDeniedError unless File.writable?(File.dirname(@target_path)) Dir.mkdir(@target_path, 0755) end
sadf(src, dest)
click to toggle source
# File lib/vpsb_client/datafiles/sar_manager.rb, line 55 def sadf(src, dest) sadf_runner.run(src, dest) end