Ejemplo n.º 1
0
    def test_alias_quotation(self):
        config("test/data/aliases.conf")

        args = ["quot"]
        with self.assertRaises(ConfigError) as ce:
            get_subcommand(args)

        self.assertEqual(str(ce.exception), 'No closing quotation')
Ejemplo n.º 2
0
    def test_alias_quotation(self):
        config("test/data/aliases.conf")

        args = ["quot"]
        with self.assertRaises(ConfigError) as ce:
            get_subcommand(args)

        self.assertEqual(str(ce.exception), 'No closing quotation')
Ejemplo n.º 3
0
    def run(self):
        """ Main entry function. """
        history = History()

        while True:
            # (re)load the todo.txt file (only if it has been modified)
            self._load_file()

            try:
                user_input = get_input(u'topydo> ',
                                       history=history,
                                       completer=self.completer).split()
            except (EOFError, KeyboardInterrupt):
                sys.exit(0)

            mtime_after = _todotxt_mtime()

            if self.mtime != mtime_after:
                # refuse to perform operations such as 'del' and 'do' if the
                # todo.txt file has been changed in the background.
                error(
                    "WARNING: todo.txt file was modified by another application.\nTo prevent unintended changes, this operation was not executed."
                )
                continue

            (subcommand, args) = get_subcommand(user_input)

            try:
                if self._execute(subcommand, args) != False:
                    self._post_execute()
            except TypeError:
                usage()
Ejemplo n.º 4
0
    def test_alias_default_cmd02(self):
        config("test/data/aliases.conf", {('topydo', 'default_command'): 'foo'})

        args = []
        real_cmd, final_args = get_subcommand(args)
        self.assertTrue(issubclass(real_cmd, DeleteCommand))
        self.assertEqual(final_args, ["-f", "test"])
Ejemplo n.º 5
0
    def run(self):
        """ Main entry function. """
        history = InMemoryHistory()
        self._load_file()

        while True:
            # (re)load the todo.txt file (only if it has been modified)

            try:
                user_input = prompt(u'topydo> ', history=history,
                                    completer=self.completer,
                                    complete_while_typing=False)
                user_input = shlex.split(user_input)
            except EOFError:
                sys.exit(0)
            except KeyboardInterrupt:
                continue
            except ValueError as verr:
                error('Error: ' + str(verr))
                continue

            try:
                (subcommand, args) = get_subcommand(user_input)
            except ConfigError as ce:
                error('Error: ' + str(ce) + '. Check your aliases configuration')
                continue

            try:
                if self._execute(subcommand, args) != False:
                    self._post_execute()
            except TypeError:
                print(GENERIC_HELP)
Ejemplo n.º 6
0
    def test_alias04(self):
        config("test/data/aliases.conf")

        args = ["star", "foo"]
        real_cmd, final_args = get_subcommand(args)
        self.assertTrue(issubclass(real_cmd, TagCommand))
        self.assertEqual(final_args, ["foo", "star", "1"])
Ejemplo n.º 7
0
    def test_alias02(self):
        config("test/data/aliases.conf")

        args = ["format"]
        real_cmd, final_args = get_subcommand(args)
        self.assertTrue(issubclass(real_cmd, ListCommand))
        self.assertEqual(final_args, ["-F", "|I| x c d {(}p{)} s k", "-n", "25"])
Ejemplo n.º 8
0
    def test_alias03(self):
        config("test/data/aliases.conf")

        args = ["smile"]
        real_cmd, final_args = get_subcommand(args)
        self.assertTrue(issubclass(real_cmd, ListCommand))
        self.assertEqual(final_args, [u"\u263b"])
Ejemplo n.º 9
0
    def run(self):
        """ Main entry function. """
        history = InMemoryHistory()
        self._load_file()
        session = PromptSession(history=history)

        while True:
            # (re)load the todo.txt file (only if it has been modified)

            try:
                user_input = session.prompt(u'topydo> ',
                                            completer=self.completer,
                                            complete_while_typing=False)
                user_input = shlex.split(user_input)
            except EOFError:
                sys.exit(0)
            except KeyboardInterrupt:
                continue
            except ValueError as verr:
                error('Error: ' + str(verr))
                continue

            try:
                (subcommand, args) = get_subcommand(user_input)
            except ConfigError as ce:
                error('Error: ' + str(ce) +
                      '. Check your aliases configuration')
                continue

            try:
                if self._execute(subcommand, args) != False:
                    self._post_execute()
            except TypeError:
                print(GENERIC_HELP)
Ejemplo n.º 10
0
    def test_alias01(self):
        config("test/data/aliases.conf")

        args = ["foo"]
        real_cmd, final_args = get_subcommand(args)
        self.assertTrue(issubclass(real_cmd, DeleteCommand))
        self.assertEqual(final_args, ["-f", "test"])
Ejemplo n.º 11
0
    def test_alias01(self):
        config("test/data/aliases.conf")

        args = ["foo"]
        real_cmd, final_args = get_subcommand(args)
        self.assertTrue(issubclass(real_cmd, DeleteCommand))
        self.assertEqual(final_args, ["-f", "test"])
Ejemplo n.º 12
0
    def test_alias03(self):
        config("test/data/aliases.conf")

        args = ["smile"]
        real_cmd, final_args = get_subcommand(args)
        self.assertTrue(issubclass(real_cmd, ListCommand))
        self.assertEqual(final_args, [u"\u263b"])
Ejemplo n.º 13
0
    def test_alias04(self):
        config("test/data/aliases.conf")

        args = ["star", "foo"]
        real_cmd, final_args = get_subcommand(args)
        self.assertTrue(issubclass(real_cmd, TagCommand))
        self.assertEqual(final_args, ["foo", "star", "1"])
Ejemplo n.º 14
0
    def test_alias_default_cmd03(self):
        config("test/data/aliases.conf", {('topydo', 'default_command'): 'nonexisting_default'})

        args = ['nonexisting']
        real_cmd, final_args = get_subcommand(args)
        self.assertFalse(real_cmd)
        self.assertEqual(final_args, ['nonexisting'])
Ejemplo n.º 15
0
    def run(self):
        """ Main entry function. """
        history = History()

        while True:
            # (re)load the todo.txt file (only if it has been modified)
            self._load_file()

            try:
                user_input = get_input(u'topydo> ', history=history,
                                       completer=self.completer).split()
            except (EOFError, KeyboardInterrupt):
                sys.exit(0)

            mtime_after = _todotxt_mtime()

            if self.mtime != mtime_after:
                # refuse to perform operations such as 'del' and 'do' if the
                # todo.txt file has been changed in the background.
                error("WARNING: todo.txt file was modified by another application.\nTo prevent unintended changes, this operation was not executed.")
                continue

            (subcommand, args) = get_subcommand(user_input)

            try:
                if self._execute(subcommand, args) != False:
                    self._post_execute()
            except TypeError:
                usage()
Ejemplo n.º 16
0
    def _execute_handler(self, p_command, p_todo_id=None, p_output=None):
        """
        Executes a command, given as a string.
        """
        p_output = p_output or self._output
        self._console_visible = False

        self._last_cmd = (p_command, p_output == self._output)

        try:
            p_command = shlex.split(p_command)
        except ValueError as verr:
            self._print_to_console('Error: ' + str(verr))
            return

        try:
            subcommand, args = get_subcommand(p_command)
        except ConfigError as cerr:
            self._print_to_console(
                'Error: {}. Check your aliases configuration.'.format(cerr))
            return

        if subcommand is None:
            self._print_to_console(GENERIC_HELP)
            return

        env_args = (self.todolist, p_output, self._output, self._input)
        ids = None

        if '{}' in args:
            if self._has_marked_todos():
                ids = self.marked_todos
            else:
                ids = {p_todo_id} if p_todo_id else set()

            invalid_ids = self._check_id_validity(ids)

            if invalid_ids:
                self._print_to_console('Error: ' + invalid_ids)
                return

        transaction = Transaction(subcommand, env_args, ids)
        transaction.prepare(args)
        label = transaction.label
        self._backup(subcommand, p_label=label)

        try:
            if transaction.execute():
                post_archive_action = transaction.execute_post_archive_actions
                self._post_archive_action = post_archive_action
                self._post_execute()
            else:
                self._rollback()
        except TypeError:
            # TODO: show error message
            pass
Ejemplo n.º 17
0
    def _execute_handler(self, p_command, p_todo_id=None, p_output=None):
        """
        Executes a command, given as a string.
        """
        p_output = p_output or self._output
        self._console_visible = False

        self._last_cmd = (p_command, p_output == self._output)

        try:
            p_command = shlex.split(p_command)
        except ValueError as verr:
            self._print_to_console('Error: ' + str(verr))
            return

        try:
            subcommand, args = get_subcommand(p_command)
        except ConfigError as cerr:
            self._print_to_console(
                'Error: {}. Check your aliases configuration.'.format(cerr))
            return

        if subcommand is None:
            self._print_to_console(GENERIC_HELP)
            return

        env_args = (self.todolist, p_output, self._output, self._input)
        ids = None

        if '{}' in args:
            if self._has_marked_todos():
                ids = self.marked_todos
            else:
                ids = {p_todo_id} if p_todo_id else set()

            invalid_ids = self._check_id_validity(ids)

            if invalid_ids:
                self._print_to_console('Error: ' + invalid_ids)
                return

        transaction = Transaction(subcommand, env_args, ids)
        transaction.prepare(args)
        label = transaction.label
        self._backup(subcommand, p_label=label)

        try:
            if transaction.execute():
                post_archive_action = transaction.execute_post_archive_actions
                self._post_archive_action = post_archive_action
                self._post_execute()
            else:
                self._rollback()
        except TypeError:
            # TODO: show error message
            pass
Ejemplo n.º 18
0
    def run(self):
        """ Main entry function. """
        args = self._process_flags()

        self.todofile = TodoFile.TodoFile(config().todotxt())
        self.todolist = TodoList.TodoList(self.todofile.read())

        (subcommand, args) = get_subcommand(args)

        if subcommand == None:
            self._usage()

        if self._execute(subcommand, args) == False:
            sys.exit(1)
        else:
            self._post_execute()
Ejemplo n.º 19
0
    def _execute_handler(self, p_command, p_todo_id=None, p_output=None):
        """
        Executes a command, given as a string.
        """
        p_output = p_output or self._output

        self._last_cmd = (p_command, p_output == self._output)

        if '{}' in p_command:
            if self._has_marked_todos():
                p_todo_id = ' '.join(self.marked_todos)
            p_command = p_command.format(p_todo_id)

        try:
            p_command = shlex.split(p_command)
        except ValueError as verr:
            self._print_to_console('Error: ' + str(verr))
            return

        try:
            (subcommand, args) = get_subcommand(p_command)
        except ConfigError as cerr:
            self._print_to_console(
                'Error: {}. Check your aliases configuration.'.format(cerr))
            return

        self._backup(subcommand, args)

        try:
            command = subcommand(
                args,
                self.todolist,
                p_output,
                self._output,
                self._input,
            )

            if command.execute() != False:
                self._post_execute()

        except TypeError:
            # TODO: show error message
            pass
Ejemplo n.º 20
0
    def run(self):
        """ Main entry function. """
        args = self._process_flags()

        self.todofile = TodoFile.TodoFile(config().todotxt())
        self.todolist = TodoList.TodoList(self.todofile.read())

        try:
            (subcommand, args) = get_subcommand(args)
        except ConfigError as ce:
            error('Error: ' + str(ce) + '. Check your aliases configuration')
            sys.exit(1)

        if subcommand is None:
            self._usage()

        if self._execute(subcommand, args) == False:
            sys.exit(1)
        else:
            self._post_execute()
Ejemplo n.º 21
0
Archivo: CLI.py Proyecto: bram85/topydo
    def run(self):
        """ Main entry function. """
        args = self._process_flags()

        self.todofile = TodoFile.TodoFile(config().todotxt())
        self.todolist = TodoList.TodoList(self.todofile.read())

        try:
            (subcommand, args) = get_subcommand(args)
        except ConfigError as ce:
            error('Error: ' + str(ce) + '. Check your aliases configuration')
            sys.exit(1)

        if subcommand is None:
            CLIApplicationBase._usage()

        if self._execute(subcommand, args) == False:
            sys.exit(1)
        else:
            self._post_execute()
Ejemplo n.º 22
0
    def run(self):
        """ Main entry function. """
        history = InMemoryHistory()

        while True:
            # (re)load the todo.txt file (only if it has been modified)
            self._load_file()

            try:
                user_input = prompt(u'topydo> ', history=history,
                                    completer=self.completer,
                                    complete_while_typing=False)
                user_input = shlex.split(user_input)
            except EOFError:
                sys.exit(0)
            except KeyboardInterrupt:
                continue
            except ValueError as verr:
                error('Error: ' + str(verr))
                continue

            mtime_after = _todotxt_mtime()

            try:
                (subcommand, args) = get_subcommand(user_input)
            except ConfigError as ce:
                error('Error: ' + str(ce) + '. Check your aliases configuration')
                continue

            # refuse to perform operations such as 'del' and 'do' if the
            # todo.txt file has been changed in the background.
            if subcommand and not self.is_read_only(subcommand) and self.mtime != mtime_after:
                error("WARNING: todo.txt file was modified by another application.\nTo prevent unintended changes, this operation was not executed.")
                continue

            try:
                if self._execute(subcommand, args) != False:
                    self._post_execute()
            except TypeError:
                usage()
Ejemplo n.º 23
0
 def test_default_cmd02(self):
     args = []
     real_cmd, final_args = get_subcommand(args)
     self.assertTrue(issubclass(real_cmd, ListCommand))
     self.assertEqual(final_args, [])
Ejemplo n.º 24
0
 def test_help(self):
     real_cmd, final_args = get_subcommand(['help', 'nonexisting'])
     self.assertFalse(real_cmd)
     self.assertEqual(final_args, ['help', 'nonexisting'])
Ejemplo n.º 25
0
 def test_normal_cmd(self):
     args = ["add"]
     real_cmd, final_args = get_subcommand(args)
     self.assertTrue(issubclass(real_cmd, AddCommand))
Ejemplo n.º 26
0
 def test_cmd_help(self):
     args = ["help", "add"]
     real_cmd, final_args = get_subcommand(args)
     self.assertTrue(issubclass(real_cmd, AddCommand))
     self.assertEqual(final_args, ["help"])
Ejemplo n.º 27
0
 def test_normal_cmd(self):
     args = ["add"]
     real_cmd, _ = get_subcommand(args)
     self.assertTrue(issubclass(real_cmd, AddCommand))
Ejemplo n.º 28
0
 def test_help(self):
     real_cmd, final_args = get_subcommand(['help', 'nonexisting'])
     self.assertFalse(real_cmd)
     self.assertEqual(final_args, ['help', 'nonexisting'])
Ejemplo n.º 29
0
    def test_wrong_alias(self):
        config("test/data/aliases.conf")

        args = ["baz"]
        real_cmd, _ = get_subcommand(args)
        self.assertEqual(real_cmd, None)
Ejemplo n.º 30
0
 def test_cmd_help(self):
     args = ["help", "add"]
     real_cmd, final_args = get_subcommand(args)
     self.assertTrue(issubclass(real_cmd, AddCommand))
     self.assertEqual(final_args, ["help"])
Ejemplo n.º 31
0
    def test_wrong_alias(self):
        config("test/data/aliases.conf")

        args = ["baz"]
        real_cmd, final_args = get_subcommand(args)
        self.assertEqual(real_cmd, None)
Ejemplo n.º 32
0
 def test_default_cmd02(self):
     args = []
     real_cmd, final_args = get_subcommand(args)
     self.assertTrue(issubclass(real_cmd, ListCommand))
     self.assertEqual(final_args, [])