Class: Rubble::Executor::Base
- Inherits:
-
Object
- Object
- Rubble::Executor::Base
- Defined in:
- lib/rubble/executor/base.rb
Instance Method Summary collapse
- #convert_options(options) ⇒ Object
- #exec(*command) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#redirect { ... } ⇒ String
Redirect stdout and return output.
- #rsync(*parameters) ⇒ Object
- #rsync_includes(filesets) ⇒ Object
- #rsync_remote_prefix ⇒ Object
Constructor Details
Instance Method Details
#convert_options(options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rubble/executor/base.rb', line 20 def () switches = [] .each do |k, v| if not v.nil? then switches << "--#{k.to_s.gsub(/_/, '-')}" if not v == true then switches << v end end end switches end |
#exec(*command) ⇒ Object
16 17 18 |
# File 'lib/rubble/executor/base.rb', line 16 def exec(*command) run(*command) end |
#redirect { ... } ⇒ String
Redirect stdout and return output
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rubble/executor/base.rb', line 119 def redirect begin old_stdout = $stdout old_stderr = $stderr $stdout = StringIO.new('', 'w') $stderr = $stdout result = yield [result, $stdout.string] ensure $stdout = old_stdout $stderr = old_stderr end end |
#rsync(*parameters) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rubble/executor/base.rb', line 60 def rsync(*parameters) paths = [] = { :recursive => nil, :dirs => nil, :delete => nil, :delete_excluded => nil, :include_from => nil, :rsh => 'ssh -o ClearAllForwardings=Yes', :verbose => nil } includes = [] parameters.each do |parameter| if parameter.is_a?(Hash) then parameter.each do |name, value| if name.to_s == 'includes' then Array(value).each do |v| includes << v end elsif .include?(name) then [name] = value else raise "Unknown rsync parameter #{name}." end end else paths << parameter end end begin tempfile = nil if not includes.empty? then tempfile = Tempfile.new(['includes', '.rsync']) begin includes.each do |f| tempfile.puts f end end tempfile.close [:include_from] = tempfile.path end command = ['rsync'].concat(['-vv']).concat(()).concat(paths) @log.info("Rsyncing #{paths[0..-2].join(', ')} to #{paths[-1]}.") run(*command) ensure tempfile && tempfile.close! end end |
#rsync_includes(filesets) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubble/executor/base.rb', line 35 def rsync_includes(filesets) dirs = [] files = Set.new filesets.each do |fileset| dirs << "#{fileset.dir.to_s}/" fileset.files.each do |file| until file.to_s == '.' files << "+ #{file.to_s}" file = file.parent end end end files = files.to_a.sort files << '- *' SyncList.new(dirs, files) end |
#rsync_remote_prefix ⇒ Object
56 57 58 |
# File 'lib/rubble/executor/base.rb', line 56 def rsync_remote_prefix '' end |