Exemplo n.º 1
0
def on_key_in_tab_scripts(screen: Screen, c):
    if c in ['d', 'e', 'r', 's', 'c']:
        script_file = screen.selected_script_file()
        if script_file is None:
            raise Exception('You must select a script first.')
        if c == 'e':  # Edit
            embed_call([EDITOR, script_file.get_uri()])
            screen.load_scripts()
        elif c == 'd':  # Delete
            embed_call(['rm', script_file.get_uri()])
            screen.load_scripts()
        elif c == 'c':  # Clone
            new_script_filename = read_input(
                'Enter the name of the new script: ')
            new_uri = from_script_name_to_uri(new_script_filename)
            embed_call(['cp', script_file.get_uri(), new_uri])
            screen.load_scripts()
        elif c == 'r':  # Run.
            pthread = screen.build_pthread(script_file)
            screen.add_pthread_or_restart(pthread)
        elif c == 's' and (project := screen.picked_project):  # Add to project
            try:
                project.add_config_script(script_file.get_name())
                index = len(project.get_config_scripts()) - 1
                screen.log(
                    f'Added script in project {project.get_name()}, at the index {index}.'
                )
            except AlreadyExistsScriptFile:
                project.delete_config_script(script_file.get_name())
                screen.log(f'Detached script of project {project.get_name()}.')
Exemplo n.º 2
0
def on_key_in_tab_threads(screen: Screen, c):
    if c in ['w', 'c', 't', 'k', 'd', 'r', 'z', '+', '-']:  # Over a PThread
        pthread = screen.selected_pthread()
        if pthread is None:
            raise Exception('You must select a thread first.')

        if c == 'c':  # Close (Ctrl+C)
            pthread.send_sig_int()
        elif c == 't':  # Terminate (Ctrl+C)
            pthread.terminate_sub_p()
        elif c == 'k':  # Kill (Ctrl+C)
            pthread.kill_sub_p()
        elif c == 'w':  # Watch
            screen.watch(pthread)
        elif c == 'd':  # Delete
            screen.stop_and_pop_pthread(pthread)
        elif c == 'r':  # Run (again).
            # This will does the part 'restart' only.
            screen.add_pthread_or_restart(pthread.clone())
        elif c == 'z':
            print(pthread.execution_exception_traceback_info)
            read_input('Press Enter to continue. ')
        elif c == '-':
            pthread.add_to_nice(-1)
        elif c == '+':
            pthread.add_to_nice(1)
    elif c == 'n':
        command = read_input('Command (for instance "ping google.com"): ')
        if command:
            pthread = screen.build_pthread(
                SingleCommandVirtualScriptFile(command))
            screen.add_pthread_and_start(pthread)
    elif char_is_enter(c):
        pass
    else:
        raise UndefinedBehaviorException
Exemplo n.º 3
0
def on_key_in_tab_projects(screen: Screen, c):
    if c in ['s', 'c'] or c.isdigit():
        project = screen.selected_project()
        if project is None:
            raise Exception('You must select a thread first.')

        if c == 's':  # Select | Pick
            screen.change_tab_index(2)
            if screen.picked_project is project:
                screen.picked_project = None
            else:
                screen.picked_project = project
        elif c == 'c':  # Clear
            project.clear_config_scripts()
        elif c.isdigit():
            try:
                script_name = project.get_config_scripts()[int(c)]
                scripts_with_that_name = list(
                    filter(lambda sf: sf.name == script_name,
                           screen.script_files))
                if not scripts_with_that_name:
                    raise Exception(
                        f'Script with name {script_name} doesn\'t exists.')
                script = scripts_with_that_name[0]
                pthread = screen.build_pthread(script, project)
                screen.add_pthread_or_restart(pthread)
            except ValueError:
                raise Exception('Digit not allowed.')
            except IndexError:
                raise Exception('Index error.')

    elif char_is_enter(c):
        screen.load_projects()
        screen.load_scripts()
    else:
        raise UndefinedBehaviorException