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) if defaultstring: self.defaults = util.tw_modstring_to_kwargs(defaultstring) else: self.defaults = util.tw_args_to_kwargs(self.taskfilter) self.tasks = set() self.sort = (sort or vim.vars.get('taskwiki_sort_order') or constants.DEFAULT_SORT_ORDER)
def from_line(cls, number, cache): match = re.search(regexp.GENERIC_VIEWPORT, vim.current.buffer[number]) if not match: return None taskfilter = util.tw_modstring_to_args(match.group('filter') or '') defaults, meta = util.tw_modstring_to_kwargs( match.group('filter') + ' ' + (match.group('defaults') or '')) name = match.group('name').strip() tw = cache.warriors[match.group('source') or 'default'] self = cls(number, cache, tw, name, taskfilter, defaults, meta) return self
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) if defaultstring: self.defaults = util.tw_modstring_to_kwargs(defaultstring) else: self.defaults = util.tw_args_to_kwargs(self.taskfilter) self.tasks = set() self.sort = ( sort or vim.vars.get('taskwiki_sort_order') or constants.DEFAULT_SORT_ORDER )
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 = re.search(regexp.GENERIC_TASK, vim.current.buffer[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: self.task['description'] = match.group('text').decode('utf-8') 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' elif self['completed_mark'] is 'S': self.task['status'] = 'pending' self.task['start'] = self.task['start'] or 'now' # 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 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. 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
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 = re.search(regexp.GENERIC_TASK, vim.current.buffer[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 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' elif self['completed_mark'] is 'S': self.task['status'] = 'pending' self.task['start'] = self.task['start'] or 'now' # 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 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, timezone offset and everything 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 and apply it, ignore meta part modifications = util.tw_modstring_to_kwargs(modstring)[0] for key in modifications.keys(): self[key] = modifications[key] # Apply the new description self['description'] = new_description return self