Beispiel #1
0
 def test_modstring_to_kwargs_ignore_modifiers(self):
     assert util.tw_modstring_to_kwargs("project.is:Random due:now") == {
         "due": "now"
     }
     assert util.tw_modstring_to_kwargs(
         "project:Random due.before:now area:admin") == {
             "project": "Random",
             "area": "admin"
         }
Beispiel #2
0
 def test_modstring_to_kwargs_ignore_virtual_tags(self):
     assert util.tw_modstring_to_kwargs("project:Random +PENDING") == {
         "project": "Random"
     }
     assert util.tw_modstring_to_kwargs(
         "project:Random -DELETED area:admin") == {
             "project": "Random",
             "area": "admin"
         }
Beispiel #3
0
 def test_modstring_to_kwargs_overriding(self):
     assert util.tw_modstring_to_kwargs("project:Random project:Home") == {
         "project": "Home"
     }
     assert util.tw_modstring_to_kwargs(
         "project:Random area:admin area:school") == {
             "project": "Random",
             "area": "school"
         }
Beispiel #4
0
 def test_modstring_to_kwargs_with_spaces(self):
     assert util.tw_modstring_to_kwargs("project:Random area:admin") == {
         "project": "Random",
         "area": "admin"
     }
     assert util.tw_modstring_to_kwargs("project:Random +test") == {
         "project": "Random",
         "tags": ["test"]
     }
Beispiel #5
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
Beispiel #6
0
    def __init__(self,
                 line_number,
                 cache,
                 tw,
                 name,
                 filterstring,
                 defaultstring,
                 sort=None):
        """
        Constructs a ViewPort out of given line.
        """

        self.cache = cache
        self.tw = tw

        self.name = name
        self.line_number = line_number
        self.taskfilter, self.meta = self.process_filterstring(
            filterstring, use_presets=True)

        if defaultstring:
            self.defaults = util.tw_modstring_to_kwargs(defaultstring)
        else:
            pure_filter, _ = self.process_filterstring(filterstring,
                                                       use_presets=False)
            self.defaults = util.tw_args_to_kwargs(pure_filter)

        self.tasks = set()
        self.sort = (sort or util.get_var('taskwiki_sort_order')
                     or constants.DEFAULT_SORT_ORDER)
Beispiel #7
0
 def test_modstring_to_kwargs(self):
     assert util.tw_modstring_to_kwargs("") == {}
     assert util.tw_modstring_to_kwargs("project:Random")  == {"project":"Random"}
     assert util.tw_modstring_to_kwargs("project:Random area:admin")  == {"project":"Random", "area":"admin"}
     assert util.tw_modstring_to_kwargs("project:Random +test")  == {"project":"Random", "tags":["test"]}
     assert util.tw_modstring_to_kwargs("project:Random +test +home")  == {"project":"Random", "tags":["test", "home"]}
     assert util.tw_modstring_to_kwargs("project:'Random +test'")  == {"project":"Random +test"}
Beispiel #8
0
 def test_modstring_to_kwargs(self):
     assert util.tw_modstring_to_kwargs("") == {}
     assert util.tw_modstring_to_kwargs("project:Random") == {
         "project": "Random"
     }
     assert util.tw_modstring_to_kwargs("project:Random area:admin") == {
         "project": "Random",
         "area": "admin"
     }
     assert util.tw_modstring_to_kwargs("project:Random +test") == {
         "project": "Random",
         "tags": ["test"]
     }
     assert util.tw_modstring_to_kwargs("project:Random +test +home") == {
         "project": "Random",
         "tags": ["test", "home"]
     }
     assert util.tw_modstring_to_kwargs("project:'Random +test'") == {
         "project": "Random +test"
     }
Beispiel #9
0
    def from_line(cls, cache, number):
        """
        Creates a Vimwiki object from given line in the buffer.
          - If line does not contain a Vimwiki task, returns None.
        """
        # Protected access is ok here
        # pylint: disable=W0212

        match = cache.line[(cls, number)]

        if not match:
            return None

        tw = cache.warriors[match.group('source') or 'default']
        self = cls(cache, match.group('uuid'), tw)

        # Save vim-only related data
        self.vim_data.update({
            'indent': match.group('space'),
            'completed_mark': match.group('completed'),
            'line_number': number,
        })

        # Save task related data into Task object directly
        # Use data from the buffer to update the task only if we
        # explicitly stated that buffer has authority or if the task
        # being loaded is not saved in TW
        if cache.buffer_has_authority or not self.task.saved:
            if six.PY2:
                self.task['description'] = match.group('text').decode('utf-8')
            else:
                self.task['description'] = match.group('text')

            self.task['priority'] = convert_priority_to_tw_format(
                len(match.group('priority')
                    or []))  # This is either 0,1,2 or 3

            # Also make sure changes in the progress field are reflected
            if self['completed_mark'] is 'X':
                self.task['status'] = 'completed'
                self.task['start'] = None
                self.task['end'] = self.task['end'] or datetime.now()
            elif self['completed_mark'] is 'S':
                self.task['status'] = 'pending'
                self.task['start'] = self.task['start'] or datetime.now()
                self.task['end'] = None
            elif self['completed_mark'] == 'D':
                self.task['status'] = 'deleted'
                self.task['start'] = None
                self.task['end'] = self.task['end'] or datetime.now()
            elif self['completed_mark'] == ' ':
                self.task['status'] = "pending"
                self.task['start'] = None
                self.task['end'] = None
                self.task['wait'] = None

            # To get local time aware timestamp, we need to convert to
            # from local datetime to UTC time, since that is what
            # tasklib (correctly) uses
            due = match.group('due')
            if due:
                # With strptime, we get a native datetime object
                parsed_due = None

                try:
                    parsed_due = datetime.strptime(due, regexp.DATETIME_FORMAT)
                except ValueError:
                    try:
                        parsed_due = datetime.strptime(due, regexp.DATE_FORMAT)
                    except ValueError:
                        vim.command('echom "Taskwiki: Invalid timestamp '
                                    'on line %s, ignored."' %
                                    self['line_number'])

                # We need to interpret it as timezone aware object in user's
                # timezone, This properly handles DST and timezone offset.
                if parsed_due:
                    self.task['due'] = parsed_due

            # After all line-data parsing, save the data in the buffer
            self._buffer_data = {key: self[key] for key in self.buffer_keys}

        # We need to track depedency set in a extra attribute, since
        # this may be a new task, and hence it need not to be saved yet.
        # We circumvent this problem by iteration order in the TaskCache
        self.add_dependencies = set()

        self.parent = self.find_parent_task()

        # Make parent task dependant on this task
        if self.parent:
            self.parent.add_dependencies |= set([self])

        # For new tasks, apply defaults from above viewport
        if not self.uuid:
            self.apply_defaults()

            # If -- is in description, assume it's separator for metadata
            # * [ ] this is new task -- project:home
            # should turn into
            # * [ ] this is new task
            # with project:home applied

            if '--' in self['description']:
                first_part, second_part = self['description'].split('--', 1)

                new_description = first_part.strip()
                modstring = second_part.strip()

                # Convert the modstring
                modifications = util.tw_modstring_to_kwargs(modstring)
                for key in modifications.keys():
                    self[key] = modifications[key]

                # Apply the new description
                self['description'] = new_description

        return self
Beispiel #10
0
 def test_modstring_to_kwargs_with_removal(self):
     assert util.tw_modstring_to_kwargs("project: +work") == {"tags":["work"], "project":None}
Beispiel #11
0
 def test_modstring_to_kwargs_with_spaces(self):
     assert util.tw_modstring_to_kwargs("project:Random area:admin") == {"project":"Random", "area":"admin"}
     assert util.tw_modstring_to_kwargs("project:Random +test") == {"project":"Random", "tags":["test"]}
Beispiel #12
0
 def test_modstring_to_kwargs_with_simple_tag(self):
     assert util.tw_modstring_to_kwargs("+test ") == {"tags": ["test"]}
Beispiel #13
0
 def test_modstring_to_kwargs_overriding(self):
     assert util.tw_modstring_to_kwargs("project:Random project:Home") == {"project":"Home"}
     assert util.tw_modstring_to_kwargs("project:Random area:admin area:school") == {"project":"Random", "area":"school"}
Beispiel #14
0
 def test_modstring_to_kwargs_ignore_modifiers(self):
     assert util.tw_modstring_to_kwargs("project.is:Random due:now") == {"due":"now"}
     assert util.tw_modstring_to_kwargs("project:Random due.before:now area:admin") == {"project":"Random", "area":"admin"}
Beispiel #15
0
 def test_modstring_to_kwargs_ignore_virtual_tags(self):
     assert util.tw_modstring_to_kwargs("project:Random +PENDING") == {"project":"Random"}
     assert util.tw_modstring_to_kwargs("project:Random -DELETED area:admin") == {"project":"Random", "area":"admin"}
Beispiel #16
0
 def test_modstring_to_kwargs_with_simple_tag(self):
     assert util.tw_modstring_to_kwargs("+test ") == {"tags":["test"]}
Beispiel #17
0
 def test_modstring_to_kwargs_with_removal(self):
     assert util.tw_modstring_to_kwargs("project: +work") == {
         "tags": ["work"],
         "project": None
     }