コード例 #1
0
def test_command_line_run_successful_json(capsys, monkeypatch):
    monkeypatch.setattr(sys, "argv", [
        'ats_hacker', 'ats_hacker/tests/test_data/simple-job.txt', '-o', 'json'
    ])
    cli = CLI()
    cli.start()
    out, _ = capsys.readouterr()
    want = '{"software": 1, "engineer": 1, "super": 1, "cool": 1, ' \
        '"company": 1, "bozeman": 1, "mt": 1, "or": 1, "remote": 1}\n'
    assert want == out
コード例 #2
0
def test_command_line_with_no_filename(capsys, monkeypatch):
    monkeypatch.setattr(sys, "argv", ['ats_hacker'])
    try:
        cli = CLI()
        cli.start()
    except SystemExit:
        pass
    _, err = capsys.readouterr()
    want = "usage: ats_hacker [-h] [-o [json]] [-r [filename]] filename\n" \
        "ats_hacker: error: the following arguments are required: filename\n"
    assert want == err
コード例 #3
0
def test_command_line_run_successful_pretty(capsys, monkeypatch):
    monkeypatch.setattr(
        sys, "argv",
        ['ats_hacker', 'ats_hacker/tests/test_data/simple-job.txt'])
    try:
        cli = CLI()
        cli.start()
    except SystemExit:
        pass
    out, _ = capsys.readouterr()
    output_words = out.split()
    print(output_words)
    for word in ["Document:", "Word", "Occurances"]:
        assert output_words.index(word)
コード例 #4
0
def test_command_line_print_help_with_dash_h_arg(capsys, monkeypatch):
    monkeypatch.setattr(sys, "argv", ['ats_hacker', '-h'])
    try:
        cli = CLI()
        cli.start()
    except SystemExit:
        pass
    out, _ = capsys.readouterr()
    want = "usage: ats_hacker [-h] [-o [json]] [-r [filename]] filename\n\n" \
        "Keyword aggregator for ATS optimization.\n\n" \
        "positional arguments:\n" \
        "  filename       txt filename for keyword aggregation\n\n" \
        "optional arguments:\n" \
        "  -h, --help     show this help message and exit\n" \
        "  -o [json]      output in raw JSON format\n" \
        "  -r [filename]  txt filename for words to remove\n"
    assert want == out
コード例 #5
0
ファイル: main.py プロジェクト: joshkelly/fuel
def main():
    '''
    load record data
    load vehicle data
    show main menu
    '''
    global debug, gui
    guiType = 0
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hdcg", ["help", "debug", "cli", "gtk"])
    except getopt.GetoptError as err:
        # print help information and exit:
        print(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)


    for o,a in opts:
        if o in ("-d", "--debug"):
            debug=True
        elif o in ("-c", "--cli"):
            guiType = 0
        elif o in ("-g", "--gtk"):
            guiType = 1
        elif o in ("-h", "--help"):
            usage()
            exit()
        else:
            assert False, "unhandled option"

    if debug:
        print('#### DEBUG MODE ####')

    if guiType == 0:
        gui = CLI()
#    elif guiType == 1:
#        gui = GUI()

    FN.load()
    for v in FN.vehicles:
        FN.fuel_graph(v)
    FN.ppl_graph()
    FN.index()
    gui.start() 
コード例 #6
0
def check_system():
    try:
        # inquiry onos info
        res_code, sys_info = CLI.req_sys_info()

        if res_code != 200:
            SYS.disconnect_type = 'disconnect'
            SCREEN.draw_event(SYS.disconnect_type)
            LOG.debug_log(
                '[SYSTEM_CHECK_THREAD] Rest server does not respond to the request. RES_CODE = '
                + str(res_code))
            return

        ret = SYS.changed_sys_info(sys_info)

        if SYS.get_sys_redraw_flag():
            if ret is True:
                SCREEN.draw_system(menu_list)
                SCREEN.draw_event(SYS.disconnect_type)
            else:
                SCREEN.draw_refresh_time(menu_list)
    except:
        LOG.exception_err_write()
コード例 #7
0
def main():
    global evt_thread
    global conn_evt_thread

    # change to script directory for relative CONFIG_FILE path
    os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))

    try:
        from PIL import Image
    except:
        print "This program requires the pillow package."
        print 'Please run \'sudo pip install pillow\' and try again.'
        return

    try:
        from asciimatics.scene import Scene
    except:
        print "This program requires the asciimatics package."
        print 'Please run \'sudo pip install asciimatics\' and try again.'
        return

    # add for readline bug fix
    os.unsetenv('LINES')
    os.unsetenv('COLUMNS')

    # read config
    if not CONFIG.init_config(LOG):
        print 'read config fail...'
        return

    # set log
    LOG.set_default_log('watchcli_err.log')

    # set history log
    history_log = USER_LOG()
    history_log.set_log('event_history.log',
                        CONFIG.get_cli_log_rotate(),
                        int(CONFIG.get_cli_log_backup()),
                        time_prefix=False)

    # set cli log
    cli_log = USER_LOG()
    cli_log.set_log('watchcli_cli.log', CONFIG.get_cli_log_rotate(),
                    int(CONFIG.get_cli_log_backup()))
    CLI.set_cli_log(cli_log, history_log)

    # read log option
    LOG.set_log_config()

    # Start RESTful server for event
    evt = multiprocessing.Event()
    disconnect_evt = multiprocessing.Event()
    rest_evt = multiprocessing.Event()

    # create listen event thread
    evt_thread = threading.Thread(target=listen_evt, args=(evt, ))
    evt_thread.daemon = False
    evt_thread.start()

    conn_evt_thread = threading.Thread(target=listen_disconnect_evt,
                                       args=(disconnect_evt, rest_evt))
    conn_evt_thread.daemon = False
    conn_evt_thread.start()

    try:
        # create rest server process
        child_pid = cli_rest.rest_server_start(evt, disconnect_evt, rest_evt,
                                               history_log)
    except:
        print 'Rest Server failed to start'
        #print 'Processing shutdown...'
        LOG.exception_err_write()
        SYS.set_sys_thr_flag(False)
        conn_evt_thread.join()
        evt_thread.join()
        return

    # regi event
    if CLI.send_regi() == False:
        print 'Event registration failed'
        #print 'Processing shutdown...'
        LOG.exception_err_write()
        SYS.set_sys_thr_flag(False)
        conn_evt_thread.join()
        evt_thread.join()
        return

    # get event list
    if CLI.get_event_list() == False:
        print 'Get Event List failed'
        #print 'Processing shutdown...'
        LOG.exception_err_write()
        SYS.set_sys_thr_flag(False)
        conn_evt_thread.join()
        evt_thread.join()
        return

    # inquiry controller info
    try:
        res_code, sys_info = CLI.req_sys_info()
    except:
        print "Cannot connect rest server."
        #print 'Processing shutdown...'
        SYS.set_sys_thr_flag(False)
        conn_evt_thread.join()
        evt_thread.join()
        return

    if res_code != 200:
        print "Rest server does not respond to the request."
        print "code = " + str(res_code)
        #print 'Processing shutdown...'
        if not SYS.disconnect_type == 'disconnect':
            CLI.send_regi('unregi')
        SYS.set_sys_thr_flag(False)
        conn_evt_thread.join()
        evt_thread.join()
        return

    SYS.set_sys_info(sys_info)

    # set command list
    CLI.set_cmd_list()

    # set search list
    CLI.set_search_list()

    set_readline_opt()

    # system check
    check_system()

    # select input menu
    select_menu()

    # exit
    #print 'Processing shutdown...'
    if not SYS.disconnect_type == 'disconnect':
        CLI.send_regi('unregi')

    SYS.set_sys_thr_flag(False)
    conn_evt_thread.join()
    evt_thread.join()

    return
コード例 #8
0
def select_menu():
    selected_menu_no = 1

    try:
        SCREEN.set_screen()

        SCREEN.draw_system(menu_list)
        SCREEN.draw_event(SYS.disconnect_type)
        SCREEN.draw_menu(menu_list, selected_menu_no)

        SYS.set_sys_redraw_flag(True)

        x = SCREEN.get_ch()

        # 27 = ESC
        while x != 27:
            if x == curses.KEY_DOWN:
                if selected_menu_no != len(menu_list):
                    selected_menu_no += 1

            elif x == curses.KEY_UP:
                if selected_menu_no != 1:
                    selected_menu_no -= 1

            elif x == ord("\n"):
                # stop timer
                SYS.set_sys_redraw_flag(False)

                SCREEN.refresh_screen()
                SCREEN.screen_exit()

                menu = menu_list[selected_menu_no - 1]
                empty_cmd = 0

                if menu in ['Monitoring Details', 'Event History', 'CLI']:
                    if menu == 'CLI':
                        #SCREEN.display_header(menu_list[selected_menu_no - 1])
                        #SCREEN.display_sys(True)
                        SCREEN.display_help()

                    elif menu == 'Monitoring Details':
                        SCREEN.display_status()
                        CLI.process_cmd("onos cluster")
                        CLI.process_cmd("onos device")
                        CLI.process_cmd("onos link")
                        CLI.process_cmd("onos app")

                    elif menu == 'Event History':
                        SCREEN.display_event()

                    readline.set_completer(CLI.pre_complete_cli)

                    while True:
                        # mac OS
                        if 'libedit' in readline.__doc__:
                            CLI.modify_flag = True
                            CLI.save_buffer = readline.get_line_buffer()

                        # select_command (handling tab event)
                        cmd = CLI.input_cmd()
                        cmd = cmd.strip()

                        # on two consecutive empty cmd input, go back to menu
                        if len(cmd) == 0:
                            empty_cmd += 1
                            if (empty_cmd >= 2):
                                break
                        else:
                            empty_cmd = 0

                        if CLI.is_menu(cmd):
                            break
                        elif CLI.is_exit(cmd):
                            return
                        elif cmd == 'help':
                            SCREEN.display_help()
                        elif cmd == 'monitoring-details':
                            SCREEN.display_status()
                        elif cmd.startswith('event-history'):
                            if len(cmd.split(' ')) == 2:
                                try:
                                    num = int(cmd.split(' ')[1])
                                    SCREEN.display_event(num)
                                except:
                                    print 'log count param is wrong. ex) event-history 15'
                            else:
                                SCREEN.display_event()
                        else:
                            # send command
                            CLI.process_cmd(cmd)

                            while not CLI.get_cli_ret_flag():
                                time.sleep(SLEEP_TIME)

                elif menu == 'Flow Trace':
                    from asciimatics.screen import Screen
                    from asciimatics.exceptions import ResizeScreenError

                    # clear screen
                    SCREEN.get_screen().clear()
                    SCREEN.screen_exit()

                    last_scene = None

                    while True:
                        try:
                            Screen.wrapper(SCREEN.start_screen,
                                           catch_interrupt=True,
                                           arguments=[last_scene])

                            if SCREEN.quit_flag:
                                return
                            elif SCREEN.menu_flag:
                                SCREEN.set_screen()
                                SCREEN.main_scr.timeout(-1)
                                break
                            elif SCREEN.resize_err_flag:
                                SCREEN.screen_exit()
                                SCREEN.menu_flag = True
                                return

                        except ResizeScreenError as e:
                            last_scene = e.scene

                elif menu == 'Exit':
                    break

            SCREEN.draw_system(menu_list)
            SCREEN.draw_event(SYS.disconnect_type)
            SCREEN.draw_menu(menu_list, selected_menu_no)
            SCREEN.refresh_screen()

            SYS.set_sys_redraw_flag(True)

            x = SCREEN.get_ch()

        SCREEN.screen_exit()
    except:
        LOG.exception_err_write()
コード例 #9
0
ファイル: cli.py プロジェクト: Ivrez/dictionary
#!/usr/bin/env python3
import sys

from cli.cli import CLI

if __name__ == "__main__":
    interface = CLI()
    interface.run()
コード例 #10
0
def run():
    cli = CLI()
    cli.start()
コード例 #11
0
ファイル: pyweb.py プロジェクト: NoahGWood/PyWeb
#!/usr/bin/python3
import sys
from cli.cli_strings import label, usage, cmd_not_found
from cli.cli import CLI

if len(sys.argv) == 1:
    cmd_not_found()
else:
    args = sys.argv[1:]
    cmd = args[0]
    x = CLI()
    x.switch_cmd(cmd, *args[1:])
コード例 #12
0
from game.game import Game
from game.models.settings import Settings
from cli.cli import CLI

game = Game.New_Game(Settings())
client = CLI(game)
コード例 #13
0
def test_cli_class_instantiation():
    cli = CLI()
    assert cli.document == ""
    assert cli.keyword_counts == {}
コード例 #14
0
def test_keyword_counts():
    cli = CLI()
    document = "This is a test document."
    keyword_counts = {"this": 1, "is": 1, "a": 1, "test": 1, "document": 1}
    cli._process_document(document)
    assert cli.keyword_counts == keyword_counts
コード例 #15
0
def test_set_document():
    cli = CLI()
    document = "This is a test document."
    cli._process_document(document)
    assert cli.document == document