class Roby::CLI::Main

Public Instance Methods

add_robot(robot_name) click to toggle source
# File lib/roby/cli/main.rb, line 11
def add_robot(robot_name)
    gen('robot', robot_name)
end
check(app_dir = nil, *extra_files) click to toggle source
# File lib/roby/cli/main.rb, line 137
def check(app_dir = nil, *extra_files)
    app = Roby.app
    if app_dir
        app.app_dir = app_dir
    end
    app.require_app_dir
    app.robot(options[:robot])
    begin app.setup
        extra_files.each do |path|
            app.require(File.expand_path(path))
        end
    ensure app.cleanup
    end
end
display_notifications(interface) click to toggle source
# File lib/roby/cli/main.rb, line 72
def display_notifications(interface)
    while !interface.closed?
        interface.poll
        while interface.has_notifications?
            _, (source, level, message) = interface.pop_notification
            Robot.send(level.downcase, message)
        end
        while interface.has_job_progress?
            _, (kind, job_id, job_name) = interface.pop_job_progress
            Robot.info "[#{job_id}] #{job_name}: #{kind}"
        end
        sleep 0.01
    end
end
init(*dir) click to toggle source
# File lib/roby/cli/main.rb, line 17
def init(*dir)
    gen('app', *dir)
end
parse_host_option() click to toggle source
# File lib/roby/cli/main.rb, line 25
def parse_host_option
    if url = options[:host]
        if url =~ /(.*):(\d+)$/
            return Hash[host: $1, port: Integer($2)]
        else
            return Hash[host: url]
        end
    elsif url = options[:vagrant]
        require 'roby/app/vagrant'
        if vagrant_name =~ /(.*):(\d+)$/
            vagrant_name, port = $1, Integer($2)
        end
        return Hash[host: Roby::App::Vagrant.resolve_ip(vagrant_name),
                    port: port]
    else Hash.new
    end
end
quit() click to toggle source
# File lib/roby/cli/main.rb, line 95
def quit
    timeout = options[:retry] if options[:retry] != 0
    interface = setup_interface(
        retry_connection: !!options[:retry],
        timeout: timeout)
    Robot.info "connected"
    interface.quit
    begin
        Robot.info "waiting for remote app to terminate"
        display_notifications(interface)
    rescue Roby::Interface::ComError
        Robot.info "closed communication"
    rescue Interrupt
        Robot.info "CTRL+C detected, forcing remote quit. Press CTRL+C once more to terminate this script"
        interface.quit
        display_notifications(interface)
    end
ensure
    interface.close if interface && !interface.closed?
end
setup_interface(app = Roby.app, retry_connection: false, timeout: nil) click to toggle source
# File lib/roby/cli/main.rb, line 43
def setup_interface(app = Roby.app, retry_connection: false, timeout: nil)
    host_port = parse_host_option
    host = host_port[:host] || app.shell_interface_host || 'localhost'
    port = host_port[:port] || app.shell_interface_port || Interface::DEFAULT_PORT

    app.guess_app_dir
    app.shell
    app.single
    app.load_base_config

    interface = nil
    if retry_connection && timeout
        deadline = Time.now + timeout
    end
    while true
        begin
            return Roby::Interface.connect_with_tcp_to(host, port)
        rescue Roby::Interface::ConnectionError => e
            if deadline && deadline > Time.now
                Robot.warn "failed to connect to #{host}:#{port}: #{e.message}, retrying"
                sleep 0.05
            elsif !retry_connection || deadline
                raise
            end
        rescue Interrupt
            raise
        end
    end
end
wait() click to toggle source
# File lib/roby/cli/main.rb, line 123
def wait
    interface = setup_interface(
        retry_connection: true,
        timeout: options[:timeout])
ensure
    interface.close if interface && !interface.closed?
end