class Takuhai::Core

Constants

TAKUHAI_FILE
TAKUHAI_TEMPLATE

Public Instance Methods

collect() click to toggle source
# File lib/takuhai_core.rb, line 53
def collect
  src = read_collect_define
  @dsl = Takuhai::Dsl.new
  @dsl.instance_eval src

  @outtime = DateTime.now.strftime("%Y%m%d%H%M%S")
  @target_dir_name = "#{@dsl._output_base_name}#{@outtime}"
  @tar_gz_name = "#{@dsl._output_base_name}.#{@outtime}.tar.gz"

  tar_compress_log
  down_load_tar
  create_target_dir
  move_tar
  move_to_target_dir
  extract_tar
  read_line_and_execute_defined_login
end
init() click to toggle source
# File lib/takuhai_core.rb, line 49
def init
  File.open(TAKUHAI_FILE, "w") {|f|f.puts TAKUHAI_TEMPLATE}
end

Private Instance Methods

create_target_dir() click to toggle source
# File lib/takuhai_core.rb, line 84
def create_target_dir
  Dir.mkdir(@target_dir_name) unless File.exists? @target_dir_name
end
down_load_tar() click to toggle source
# File lib/takuhai_core.rb, line 80
def down_load_tar
  `scp #{@dsl._user}@#{@dsl._server}:#{@dsl._target_dir}/#{@tar_gz_name} .`
end
extract_tar() click to toggle source
# File lib/takuhai_core.rb, line 96
def extract_tar
  `tar xvfz #{@tar_gz_name}`
end
move_tar() click to toggle source
# File lib/takuhai_core.rb, line 88
def move_tar
  `mv #{@tar_gz_name} ./#{@target_dir_name}`
end
move_to_target_dir() click to toggle source
# File lib/takuhai_core.rb, line 92
def move_to_target_dir
  Dir.chdir("./#{@target_dir_name}")
end
read_collect_define() click to toggle source
# File lib/takuhai_core.rb, line 72
def read_collect_define
  File.open(TAKUHAI_FILE) {|f|f.read}
end
read_line_and_execute_defined_login() click to toggle source
# File lib/takuhai_core.rb, line 100
def read_line_and_execute_defined_login
  total_rets = []
  targets = @dsl._targets.split(" ")
  targets.each do |target|
    Dir.glob("./#{target}") do |f|
      lines = File.open(f) {|f|f.read}
      lines.each_line {|line|total_rets << @dsl._block.call(f, line)}
    end
    File.open("../#{@target_dir_name}.#{@dsl._output_extension}", "w") {|f| f.puts total_rets.join}
  end
end
tar_compress_log() click to toggle source
# File lib/takuhai_core.rb, line 76
def tar_compress_log
  `ssh #{@dsl._user}@#{@dsl._server} 'cd #{@dsl._target_dir};tar czvf #{@tar_gz_name} #{@dsl._targets}'`
end