示例#1
0
文件: view.py 项目: shouh/tascon
    def _do(self, cmdline_by_list):
        if len(cmdline_by_list)==0:
            return

        cmds = " ".join(cmdline_by_list)

        if cmds in ['q', 'quit']:
            return EditInterface.BREAK
        if cmds in ['h', 'help']:
            self._print_help()
            return

        line = cmds.lower()
        try:
            k, v = line.split(':', 1)
        except ValueError as e:
            return

        def target_number_observer(new_target_number):
            self._target_number = new_target_number

        try:
            self._ctrl.edit_task(self._target_number, k, v, target_number_observer)
        except EditError as e:
            # タスク番号消失に伴うエラーの対処は,
            # * 対話モード時 -> 表出する. これ以上対話的に実行できないため.
            # * Onceモード時 -> 表出しない.
            if self._use_current_print:
                raise e
        except Exception as e:
            viewutil.error_print(e)
        self._print_current()
示例#2
0
文件: view.py 项目: shouh/tascon
    def _do(self, cmdline_by_list):
        command = cmdline_by_list[0].lower()
        if command=='':
            self._print_category()
            return

        prm_list = cmdline_by_list[1:]

        if command in ['q', 'quit']:
            return EditInterface.BREAK
        if command in ['h', 'help']:
            self._print_help(prm_list)
            return
        if command in ['l', 'list']:
            self._print_category()
            return

        from config import CategoryError
        try:
            if self._add_category(command, prm_list):
                return
            if self._remove_category(command, prm_list):
                return
            if self._update_category(command, prm_list):
                return
        except CategoryError as e:
            # エラー時はエラーを見せるだけで
            # Category Mode 自体は終了させたくないので吸収する.
            viewutil.error_print(e)
            return

        viewutil.error_print(ValueError('Invalid command or parameter.'))
示例#3
0
文件: view.py 项目: shouh/tascon
    def execute_commandline(commandline_by_list, controller_inst, use_assertion=False):
        """ 与えられたコマンドラインを実行する.
        @return BREAK 抜けるタイミングが指定された(ので呼び出し元で抜けよ) """

        if len(commandline_by_list)==0:
            return

        # (COMMAND) (PRM1) (PRM2) ...
        # ^^^^^^^^^ ^^^^^^^^^^^^^^^^^
        # cmd       prms
        cmd, prmlist = commandline_by_list[0].lower(), \
                       commandline_by_list[1:]
        prms = " ".join(prmlist)

        kwargs = {'ctrl':controller_inst, 'prms':prms}
        f = COMMAND_TABLE.get_command(cmd)
        if not f:
            errmsg = 'Invalid command "%s".' % cmd
            if use_assertion:
                raise RuntimeError(errmsg)
            print errmsg
            return
        try:
            inst = f(**kwargs)
            inst.command()
        except Exception as e:
            if use_assertion:
                raise e
            viewutil.error_print(e)

        if inst.is_break_timing():
            return COMMAND_TABLE.BREAK