Module: Capsaicin::Files::Local
- Includes:
- FileUtils::Verbose
- Defined in:
- lib/capsaicin/files/local.rb
Instance Method Summary collapse
- #cd(dir, options = {}) ⇒ Object
- #download(from, to) ⇒ Object
- #put(from, to) ⇒ Object
- #tail_f(file, n = 10) ⇒ Object
- #tar_c(dest, src, options = {}, &filter) ⇒ Object
- #tar_cz(dest, src, options = {}, &filter) ⇒ Object
- #tar_t(src, options = {}, &block) ⇒ Object
- #tar_tz(src, options = {}, &block) ⇒ Object
- #tar_x(src, options = {}, &block) ⇒ Object
- #tar_xz(src, options = {}, &block) ⇒ Object
- #upload(from, to) ⇒ Object
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, ={}) 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, ={}, &filter) logger and logger.trace "tar -cf #{dest} #{Array(src).map{|s| s.gsub ' ', '\\ '}.join(' ')}" _tar File.open(dest, 'wb'), src, , &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, ={}, &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, , &filter end |
#tar_t(src, options = {}, &block) ⇒ Object
60 61 62 63 |
# File 'lib/capsaicin/files/local.rb', line 60 def tar_t(src, ={}, &block) logger and logger.trace "tar -tf #{src}" _lstar File.open(src, 'wb'), , &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, ={}, &block) require 'zlib' unless defined? Zlib::GzipWriter logger and logger.trace "tar -tzf #{src}" _lstar Zlib::GzipReader.new(File.open(src, 'rb')), , &block end |
#tar_x(src, options = {}, &block) ⇒ Object
71 72 73 74 |
# File 'lib/capsaicin/files/local.rb', line 71 def tar_x(src, ={}, &block) logger and logger.trace "tar -xf #{src}" _untar File.open(src, 'wb'), [:chdir]||'.', , &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, ={}, &block) require 'zlib' unless defined? Zlib::GzipWriter logger and logger.trace "tar -xzf #{src}" _untar Zlib::GzipReader.new(File.open(src, 'rb')), [:chdir]||'.', , &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 |