Class: Rbfs::Command
- Inherits:
-
Object
- Object
- Rbfs::Command
- Defined in:
- lib/rbfs/command.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #logger ⇒ Object
- #parse_config ⇒ Object
- #sync ⇒ Object
- #sync_host(host) ⇒ Object
- #sync_hosts ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
12 13 14 15 16 |
# File 'lib/rbfs/command.rb', line 12 def initialize @config = parse_config logger.critical "No hosts file specified" unless config[:hosts] logger.critical "Root path not specified" unless config[:root] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/rbfs/command.rb', line 10 def config @config end |
Instance Method Details
#logger ⇒ Object
31 32 33 |
# File 'lib/rbfs/command.rb', line 31 def logger @config[:logger] end |
#parse_config ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbfs/command.rb', line 18 def parse_config config = {} cmdline_args = Rbfs::Args.new.parse if cmdline_args[:config] config_args = Rbfs::Config.new(cmdline_args[:config]).parse config = config_args.merge(cmdline_args) else config = cmdline_args end config[:logger] = Logger.new(config) config end |
#sync ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rbfs/command.rb', line 35 def sync success = true results = sync_hosts results.each do |host, result| if result[:exitcode] != 0 logger.error "#{host}: #{result[:exitcode].to_i}" else logger.info "#{host}: #{result[:exitcode].to_i}" end result[:output].split("\n").each do |line| if result[:exitcode] != 0 logger.error " | #{line}" else logger.info " | #{line}" end end success = false if result[:exitcode] != 0 end success end |
#sync_host(host) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/rbfs/command.rb', line 65 def sync_host(host) if config[:threaded] Future.new do Rsync.new(config, host).sync end else Rsync.new(config, host).sync end end |
#sync_hosts ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/rbfs/command.rb', line 56 def sync_hosts config[:root] = File.join(config[:root], config[:subpath]) if config[:subpath] logger.info "Syncing #{config[:root]}..." hosts = Rbfs::HostParser.new(File.open(config[:hosts])) hosts.collect do |host| [host, sync_host(host)] end end |