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
53
# 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


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

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


62
63
64
65
# File 'lib/capsaicin/files/local.rb', line 62

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


67
68
69
70
71
# File 'lib/capsaicin/files/local.rb', line 67

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


73
74
75
76
# File 'lib/capsaicin/files/local.rb', line 73

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

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


78
79
80
81
82
# File 'lib/capsaicin/files/local.rb', line 78

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, &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