Module: Capsaicin::Files::Local

Includes:
FileUtils::Verbose
Defined in:
lib/capsaicin/files/local.rb

Instance Method Summary collapse

Instance Method Details

#cd(dir, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/capsaicin/files/local.rb', line 40

def cd(dir, options={})
  if block_given?
    dir, dir2 = pwd, dir
    cd dir2
    yield
  end  
  cd dir
end

#download(from, to) ⇒ Object



32
33
34
# File 'lib/capsaicin/files/local.rb', line 32

def download(from, to)
  cp from, to
end

#put(from, to) ⇒ Object



36
37
38
# File 'lib/capsaicin/files/local.rb', line 36

def put(from, to)
  copy_stream StringIO.new(from), to
end

#tail_f(file, n = 10) ⇒ Object



21
22
23
24
25
26
# File 'lib/capsaicin/files/local.rb', line 21

def tail_f(file, n=10)
  unless defined? File::Tail::Logfile then gem 'file-tail'; require 'file/tail' end
  File::Tail::Logfile.tail(file, :backward=>n) do |line| puts line end
rescue Interrupt
  logger.trace "interrupted (Ctrl-C)" if logger
end

#tar_c(dest, src, options = {}, &filter) ⇒ Object



49
50
51
52
# File 'lib/capsaicin/files/local.rb', line 49

def tar_c(dest, src, options={}, &filter)
  logger and logger.trace "tar -cf #{dest} #{Array(src).map{|s| s.gsub ' ', '\\ '}.join(' ')}"
  _tar File.open(dest, 'wb'), src, options, &filter
end

#tar_cz(dest, src, options = {}, &filter) ⇒ Object



54
55
56
57
58
# File 'lib/capsaicin/files/local.rb', line 54

def tar_cz(dest, src, options={}, &filter)
  require 'zlib' unless defined? Zlib::GzipWriter
  logger and logger.trace "tar -czf #{dest} #{Array(src).map{|s| s.gsub ' ', '\\ ' }.join(' ')}"
  _tar Zlib::GzipWriter.new(File.open(dest, 'wb')), src, options, &filter
end

#tar_t(src, options = {}, &block) ⇒ Object



60
61
62
63
# File 'lib/capsaicin/files/local.rb', line 60

def tar_t(src, options={}, &block)
  logger and logger.trace "tar -tf #{src}"
  _lstar File.open(src, 'wb'), options, &block
end

#tar_tz(src, options = {}, &block) ⇒ Object



65
66
67
68
69
# File 'lib/capsaicin/files/local.rb', line 65

def tar_tz(src, options={}, &block)
  require 'zlib' unless defined? Zlib::GzipWriter
  logger and logger.trace "tar -tzf #{src}"
  _lstar Zlib::GzipReader.new(File.open(src, 'rb')), options, &block
end

#tar_x(src, options = {}, &block) ⇒ Object



71
72
73
74
# File 'lib/capsaicin/files/local.rb', line 71

def tar_x(src, options={}, &block)
  logger and logger.trace "tar -xf #{src}"
  _untar File.open(src, 'wb'), options[:chdir]||'.', options, &block
end

#tar_xz(src, options = {}, &block) ⇒ Object



76
77
78
79
80
# File 'lib/capsaicin/files/local.rb', line 76

def tar_xz(src, options={}, &block)
  require 'zlib' unless defined? Zlib::GzipWriter
  logger and logger.trace "tar -xzf #{src}"
  _untar Zlib::GzipReader.new(File.open(src, 'rb')), options[:chdir]||'.', options, &block
end

#upload(from, to) ⇒ Object



28
29
30
# File 'lib/capsaicin/files/local.rb', line 28

def upload(from, to)
  cp from, to
end