Module: RemoteMethods
- Defined in:
- lib/lsync/shell_client.rb
Class Method Summary collapse
-
.mkdir_p(path) ⇒ Object
Recursively make a directory (typically the server.root + directory).
-
.run_command(cmd) ⇒ Object
Run a command in the local environment.
-
.run_script(name, code, arguments) ⇒ Object
Run a script (given the code) in the local environment.
-
.set_working_dir(path) ⇒ Object
Set the working directory (typically the server.root).
Class Method Details
.mkdir_p(path) ⇒ Object
Recursively make a directory (typically the server.root + directory)
65 66 67 |
# File 'lib/lsync/shell_client.rb', line 65 def self.mkdir_p(path) FileUtils.mkdir_p(path) end |
.run_command(cmd) ⇒ Object
Run a command in the local environment.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lsync/shell_client.rb', line 20 def self.run_command(cmd) $logger.info("Running #{cmd.inspect}...") $connection.send_object([:info, "Running #{cmd.inspect}..."]) cin, cout, cerr = Open3.popen3(*cmd) cin.close pipes = [cout, cerr] while pipes.size > 0 ready = IO.select(pipes) ready[0].each do |pipe| # Delete the pipe when it has become closed if pipe.closed? || pipe.eof? pipes.delete(pipe) next end line = pipe.readline.chomp mode = (pipe == cout ? :info : :error) $logger.send(mode, line) $connection.send_object([mode, line]) end end $logger.info "Done running command." $connection.send_object(:done) end |
.run_script(name, code, arguments) ⇒ Object
Run a script (given the code) in the local environment.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/lsync/shell_client.rb', line 52 def self.run_script(name, code, arguments) path = script_path(name) File.open(path, "w") do |f| f.write(code) end FileUtils.chmod 0755, path run_command([path] + arguments) end |
.set_working_dir(path) ⇒ Object
Set the working directory (typically the server.root)
70 71 72 |
# File 'lib/lsync/shell_client.rb', line 70 def self.set_working_dir(path) Dir.chdir(path) end |