module Processor def copy(source, target, options={}) begin if not options[:match].nil? and File.directory? source Dir.glob(File.join(source, "*")) do |entry| if File.fnmatch(options[:match], entry) $log.writer.debug "Copy #{entry} to #{target}" FileUtils.cp_r(entry, target) end end else $log.writer.debug "Copy #{source} to #{target}" FileUtils.cp_r(source, target) end rescue Exception => e $log.writer.error "Can not copy #{source} to #{target}" $log.writer.error e.message exit 1 end end module_function :copy def mkdir(directory) begin FileUtils.mkdir_p(directory) $log.writer.debug "Create directory #{directory}" rescue Exception => e $log.writer.error "Can not create directory #{directory}" $log.writer.error e.message exit 1 end end module_function :mkdir def chmod(file, mode, options={}) begin if not options[:recursive].nil? and options[:recursive] == true FileUtils.chmod_R(mode, file) else FileUtils.chmod(mode, file) end $log.writer.debug "Chmod #{file} to #{mode}" rescue Exception => e $log.writer.error "Can not change mode on file #{file}" $log.writer.error e.message exit 1 end end module_function :chmod def remove(file) begin FileUtils.rm_rf(file) $log.writer.debug "Delete #{file}" rescue Exception => e $log.writer.error "Can not delete file #{file}" $log.writer.error e.message exit 1 end end module_function :remove def mklink(source, target) if not File.exists? source $log.writer.debug \ "Create link to nowhere, this deployment is broken by design!" end begin $log.writer.debug "Create link from #{source} to #{target}" FileUtils.ln_s(source, target) rescue Exception => e $log.writer.error "Can not create link #{target}" $log.writer.error e.message exit 1 end end module_function :mklink def check_filelist(list, target) CSV.foreach(list) do |file| if not file.nil? and not file.first.nil? $log.writer.debug "Checking file #{File.join(target, file.first)}" if not File.exists?( File.join(target, file.first) ) $log.writer.error "Necessary file not found: #{file}" exit 1 end end end end module_function :check_filelist end