Exemplo n.º 1
0
 def test_modstring_to_args_with_esacpe(self):
     assert util.tw_modstring_to_args(r'project:Random\ test +test') == [
         "project:Random test", "+test"
     ]
     assert util.tw_modstring_to_args(r"project:Random\ test +test") == [
         "project:Random test", "+test"
     ]
Exemplo n.º 2
0
 def test_modstring_to_args_with_spaces(self):
     assert util.tw_modstring_to_args("project:Random  +test") == [
         "project:Random", "+test"
     ]
     assert util.tw_modstring_to_args("project:Random    due:now") == [
         "project:Random", "due:now"
     ]
Exemplo n.º 3
0
 def test_modstring_to_args_with_nested_quotes(self):
     assert util.tw_modstring_to_args('project:"Random\'test" +test') == [
         "project:Random'test", "+test"
     ]
     assert util.tw_modstring_to_args("project:'Random\"test' +test") == [
         "project:Random\"test", "+test"
     ]
Exemplo n.º 4
0
 def test_modstring_to_args_overriding(self):
     assert util.tw_modstring_to_args("project:Random project:Home") == [
         "project:Random", "project:Home"
     ]
     assert util.tw_modstring_to_args(
         "project:Random due:now due:today") == [
             "project:Random", "due:now", "due:today"
         ]
Exemplo n.º 5
0
 def test_modstring_to_args(self):
     assert util.tw_modstring_to_args("") == []
     assert util.tw_modstring_to_args("project:Random") == [
         "project:Random"
     ]
     assert util.tw_modstring_to_args("project:Random area:admin") == [
         "project:Random", "area:admin"
     ]
     assert util.tw_modstring_to_args("project:Random +test") == [
         "project:Random", "+test"
     ]
     assert util.tw_modstring_to_args("project:'Random +test'") == [
         "project:Random +test"
     ]
Exemplo n.º 6
0
    def modify(self, modstring):
        # If no modstring was passed as argument, ask the user interactively
        if not modstring:
            with util.current_line_highlighted():
                modstring = util.get_input("Enter modifications: ")

        # We might have two same tasks in the range, make sure we do not pass the
        # same uuid twice
        unique_tasks = set(vimwikitask.task['uuid'] for vimwikitask in self.tasks)
        uuids = list(unique_tasks)

        # Generate the arguments from the modstring
        args = util.tw_modstring_to_args(modstring)

        # Modify all tasks at once
        output = util.tw_execute_safely(self.tw, uuids + ['mod'] + args)

        # Update the touched tasks in buffer, if needed
        cache().load_tasks()
        cache().update_vwtasks_from_tasks()
        cache().update_vwtasks_in_buffer()

        # Output the feedback from TW
        if output:
            print(output[-1])

        cache().buffer.push()
        self.save_action('modify', modstring)
Exemplo n.º 7
0
    def __init__(self, cache, parent, level, filterstring, defaultstring):

        self.level = level
        self.parent = parent

        if parent:
            taskfilter = list(parent.taskfilter)
        else:
            taskfilter = []

        if filterstring:
            taskfilter += '('
            taskfilter += util.tw_modstring_to_args(filterstring)
            taskfilter += ')'

        self.taskfilter = taskfilter

        if parent:
            defaults = dict(parent.defaults)
        else:
            defaults = dict()

        if defaultstring:
            defaults.update(util.tw_modstring_to_kwargs(defaultstring))
        else:
            defaults.update(util.tw_args_to_kwargs(taskfilter))

        self.defaults = defaults
Exemplo n.º 8
0
    def _process_args(self, args):
        tw_args = util.tw_modstring_to_args(args)

        # If only 'global' argument has been passed, then no
        # filter should be applied
        if tw_args == ['global']:
            return []
        # If unempty filter has been passed, then use that
        elif tw_args != []:
            return tw_args
        # If no argument has been passed, locate the closest viewport,
        # if any exists, and use its filter.
        else:
            port = viewport.ViewPort.find_closest(cache())
            return port.taskfilter if port is not None else []
Exemplo n.º 9
0
 def __init__(self, args):
     self.args = []
     self.tw_extra_args = util.tw_modstring_to_args(args)
     self.split_name = self.split_name or self.command
     self.tw = cache().get_relevant_tw()
Exemplo n.º 10
0
 def test_modstring_to_args_with_esacped_escape(self):
     assert util.tw_modstring_to_args(r'project:Random\\ +test') == [
         'project:Random\\', "+test"
     ]
Exemplo n.º 11
0
 def test_modstring_to_args_with_spaces(self):
     assert util.tw_modstring_to_args("project:Random  +test") == ["project:Random", "+test"]
     assert util.tw_modstring_to_args("project:Random    due:now") == ["project:Random", "due:now"]
Exemplo n.º 12
0
 def test_modstring_to_args_overriding(self):
     assert util.tw_modstring_to_args("project:Random project:Home") == ["project:Random", "project:Home"]
     assert util.tw_modstring_to_args("project:Random due:now due:today") == ["project:Random", "due:now", "due:today"]
Exemplo n.º 13
0
 def test_modstring_to_args_with_esacped_escape(self):
     assert util.tw_modstring_to_args(r'project:Random\\ +test') == ['project:Random\\', "+test"]
Exemplo n.º 14
0
 def test_modstring_to_args_with_esacpe(self):
     assert util.tw_modstring_to_args(r'project:Random\ test +test') == ["project:Random test", "+test"]
     assert util.tw_modstring_to_args(r"project:Random\ test +test") == ["project:Random test", "+test"]
Exemplo n.º 15
0
 def test_modstring_to_args_with_nested_quotes(self):
     assert util.tw_modstring_to_args('project:"Random\'test" +test') == ["project:Random'test", "+test"]
     assert util.tw_modstring_to_args("project:'Random\"test' +test") == ["project:Random\"test", "+test"]
Exemplo n.º 16
0
    def process_filterstring(self, filterstring, use_presets=True):
        """
        This method processes taskfilter in the form or filter string,
        parses it into list of filter args, processing any syntax sugar
        as part of the process.

        Following syntax sugar in filter expressions is currently supported:

        * Expand @name with the definition of 'context.name' TW config
          variable

        * Interpret !+DELETED as forcing the +DELETED token.
        * Interpret !-DELETED as forcing the -DELETED token.
        * Interpret !?DELETED as removing both +DELETED and -DELETED.
        """

        # Get the initial version of the taskfilter args
        taskfilter_args = list(constants.DEFAULT_VIEWPORT_VIRTUAL_TAGS)
        if use_presets:
            taskfilter_args += list(
                preset.PresetHeader.from_line(self.line_number,
                                              self.cache).taskfilter)
        taskfilter_args += "("
        taskfilter_args += util.tw_modstring_to_args(filterstring)
        taskfilter_args += ")"

        # Process syntactic sugar: Context expansion
        detected_contexts = []
        for token in filter(lambda x: x.startswith('@'), taskfilter_args):
            context_variable_name = 'context.{0}'.format(token[1:])
            context_definition = self.tw.config.get(context_variable_name)

            if context_definition:
                context_args = util.tw_modstring_to_args(context_definition)
                detected_contexts.append((token, context_args))
            else:
                raise errors.TaskWikiException("Context definition for '{0}' "
                                               "could not be found.".format(
                                                   token[1:]))

        for context_token, context_args in detected_contexts:
            # Find the position of the context token
            token_index = taskfilter_args.index(context_token)

            # Replace the token at token_index by context_args list
            taskfilter_args = (taskfilter_args[:token_index] + context_args +
                               taskfilter_args[(token_index + 1):])

        # Process syntactic sugar: Forcing virtual tags
        tokens_to_remove = set()
        tokens_to_add = set()

        is_forced_virtual_tag = lambda x: x.isupper() and (x.startswith(
            '!+') or x.startswith('!-') or x.startswith('!?'))

        for token in filter(is_forced_virtual_tag, taskfilter_args):
            # In any case, remove the forced tag and the forcing
            # flag from the taskfilter
            tokens_to_remove.add(token)
            tokens_to_remove.add('+' + token[2:])
            tokens_to_remove.add('-' + token[2:])

            # Add forced tag versions
            if token.startswith('!+'):
                tokens_to_add.add('+' + token[2:])
            elif token.startswith('!-'):
                tokens_to_add.add('-' + token[2:])
            elif token.startswith('!?'):
                pass

        for token in tokens_to_remove:
            if token in taskfilter_args:
                taskfilter_args.remove(token)

        taskfilter_args = list(tokens_to_add) + taskfilter_args

        # Deal with the situation when both +TAG and -TAG appear in the
        # taskfilter_args. If one of them is from the defaults, the explicit
        # version wins.

        def detect_virtual_tag(tag):
            return tag.isupper() and tag[0] in ('+', '-')

        def get_complement_tag(tag):
            return ('+' if tag.startswith('-') else '-') + tag[1:]

        virtual_tags = list(filter(detect_virtual_tag, taskfilter_args))
        tokens_to_remove = set()
        # For each virtual tag, check if its complement is in the
        # taskfilter_args too. If so, remove the tag that came from defaults.
        for token in virtual_tags:
            complement = get_complement_tag(token)
            if complement in virtual_tags:
                # Both tag and its complement are in the taskfilter_args.
                # Remove the one from defaults.
                if token in constants.DEFAULT_VIEWPORT_VIRTUAL_TAGS:
                    tokens_to_remove.add(token)
                if complement in constants.DEFAULT_VIEWPORT_VIRTUAL_TAGS:
                    tokens_to_remove.add(complement)

        for token in tokens_to_remove:
            if token in taskfilter_args:
                taskfilter_args.remove(token)

        # Process meta tags, remove them from filter
        meta = dict()

        for token in taskfilter_args:
            if token == '-VISIBLE':
                meta['visible'] = False

        taskfilter_args = [
            x for x in taskfilter_args if x not in self.meta_tokens
        ]

        # If, after all processing, any empty parens appear in the
        # seqeunce of taskfilter_args, remove them
        def deempty_parenthesize(tokens):
            empty_paren_index = None

            # Detect any empty parenthesis pair
            for index, token in enumerate(tokens):
                if token == '(' and tokens[index + 1] == ')':
                    empty_paren_index = index

            # Delete empty pair, if found
            if empty_paren_index is not None:
                del tokens[empty_paren_index]
                del tokens[empty_paren_index]

                # Attempt to delete next one, if it exists
                deempty_parenthesize(tokens)

        deempty_parenthesize(taskfilter_args)

        # All syntactic processing done, return the resulting filter args
        return taskfilter_args, meta
Exemplo n.º 17
0
 def test_modstring_to_args(self):
     assert util.tw_modstring_to_args("") == []
     assert util.tw_modstring_to_args("project:Random") == ["project:Random"]
     assert util.tw_modstring_to_args("project:Random area:admin") == ["project:Random", "area:admin"]
     assert util.tw_modstring_to_args("project:Random +test") == ["project:Random", "+test"]
     assert util.tw_modstring_to_args("project:'Random +test'") == ["project:Random +test"]