Ejemplo n.º 1
0
def action(do_action, arg, list_type='notes', book='general'):
    if sys.platform.startswith("linux"):
        # Linux specific abstract namespace domain socket
        grab_attention("foolscap_actor")

    func = FUNCTION_MAP[do_action]

    new_action = {}
    if do_action in DISPLAY_ACTIONS:
        display_ctrl = Controller(list_type)

        # Quitting from list calls exit() method.
        # arg is filter in this case
        if arg:
            if do_action == 'search':
                new_action = display_ctrl.search_output(arg)
            else:
                new_action = display_ctrl.query_output(arg)
        else:
            new_action = display_ctrl.basic_output(book)

    if new_action.get('action', False):
        new_func = new_action['action']
        note = new_action['item']
        if new_func == 'list':
            action(new_func, None, book=new_action['book'])
        else:
            action(new_func, note)
    # arg is note in this case
    elif arg:
        func(arg)
    else:
        func()