def __init__(self):
        '''
        Initializing the class by getting command list
        from the server.
        '''
        self.__match_list = None

        #Setting readline properties
        readline.set_history_length(50)

        history_file = os.path.join(os.environ["HOME"], ".dschistory")
        #Try to read history file.
        if os.path.exists(history_file):
            readline.read_history_file(history_file)
        #Saving history at exit.
        atexit.register(readline.write_history_file, history_file)

        #Setting up the completer.
        try:
            executer = service_manager.CommandExecuter()
            self.__commands_list = executer.execute_command('command.list()')
            #Setting the compelter.
            readline.set_completer(self.completer)
            readline.parse_and_bind('tab: complete')
        except Exception:
            #We couldn't get the command's list. So remove the completer
            #methods from the readline.
            readline.set_completer()
Exemplo n.º 2
0
def __get_app_name():
    """Try to get application name, that we're connected to.
    If it couldn't get the name, it returns empty string.
    """
    executer = service_manager.CommandExecuter()
    try:
        app_info = executer.execute_command('app.introduce()')
        return app_info['name']
    except Exception:
        #In case of any error, return empty string.
        return ''
Exemplo n.º 3
0
def _execute_script(script_content):
    """Execute the given script"""
    script_content = _replace_commands_in_script(script_content)

    #EXECUTER is used inside the script_content.
    command_executer = service_manager.CommandExecuter()
    EXECUTER = command_executer.execute_parsed_command

    try:
        exec(script_content)
    except Exception, error:
        raise ScriptExecutionError(error)
def _re_login(arguments):
    """
    Relogin to the server.
    """
    if len(arguments) != 0:
        raise ExecutionError("Login takes no arguments.")

    user_name = raw_input('User: '******'t reach this line.
    return 'Login done successfully.'
def _watch_command(arguments):
    """
    this command can be used for executing a server command
    periodically.
    Example:
       watch 3 batch.status('IS_EOY_BRN')
    
    The first argument is in seconds, and represents how
    often the command should be executed. The second argument
    is the command to execute.
    """
    if len(arguments) < 2:
        raise ExecutionError('watch takes exactly two arguments.')

    try:
        period = float(arguments[0])
        #The 'local_command_parser' assumes that argumets separates by empty
        #spaces. But this command is an exception. So we have to append all of
        #the arguments to make the command string.
        command_string = ''
        for arg in arguments[1:]:
            command_string += arg
    except ValueError:
        raise ExecutionError("Invalid arguments")

    import service_manager
    import output_handler
    executer = service_manager.CommandExecuter()

    while True:
        try:
            output_handler.output_printer(
                executer.execute_command(command_string))
            output_handler.print_horizonal_line()
            time.sleep(period)
        except Exception, error:
            raise ExecutionError(error)
        except KeyboardInterrupt:
            return
Exemplo n.º 6
0
    hooks_package_path = os.path.join(
        os.path.abspath(os.path.dirname(service_manager.__file__)), 'hooks')
    for root, dirs, files in os.walk(hooks_package_path):
        for hookfile in files:
            if hookfile.endswith('.py'):
                try:
                    module_name = 'hooks.{0}'.format(hookfile[:-3])
                    module = __import__(module_name, globals(), locals(), [])
                except ImportError:
                    raise
                    continue


command_line_args = utils.get_configurations(sys.argv)

executer = service_manager.CommandExecuter()
executer.configure(command_line_args)
load_hooks()

utils.print_welcome(__version__)

#Getting username and password.
try:
    if command_line_args.user is None:
        user_name = raw_input("User: ")
    else:
        user_name = command_line_args.user

    password = getpass.getpass()
    #Login to the server.
    #executer.login(user_name, password, channel=CHANNEL_NAME)