Пример #1
0
    def match(self, p_todo):
        """
        Performs a match on a key:value tag in the todo.

        First it tries to convert the value and the user-entered expression to
        a date and makes a comparison if it succeeds, based on the given
        operator (default ==).
        Upon failure, it falls back to converting value and user-entered
        expression to an integer and makes a numerical comparison based on the
        given operator (default ==)
        As a last resort, it falls back to using a Grep filter to see if the
        user given expression is contained in the todo text.
        """
        if not self.key or not p_todo.has_tag(self.key):
            return False

        try:
            operand1 = date_string_to_date(p_todo.tag_value(self.key))
            operand2 = relative_date_to_date(self.value)

            if not operand2:
                operand2 = date_string_to_date(self.value)

        except ValueError:
            operand1 = p_todo.tag_value(self.key)
            operand2 = self.value

            try:
                operand1 = int(operand1)
                operand2 = int(operand2)
            except ValueError:
                grep = GrepFilter(self.expression)
                return grep.match(p_todo)

        return self.compare_operands(operand1, operand2)
Пример #2
0
    def match(self, p_todo):
        if not self.key or not p_todo.has_tag(self.key):
            return False

        try:
            operand1 = date_string_to_date(p_todo.tag_value(self.key))
            operand2 = relative_date_to_date(self.value)

            if not operand2:
                operand2 = date_string_to_date(self.value)

        except ValueError:
            try:
                operand1 = int(p_todo.tag_value(self.key))
                operand2 = int(self.value)
            except ValueError:
                return False

        if self.operator == '<':
            return operand1 < operand2
        elif self.operator == '<=':
            return operand1 <= operand2
        elif self.operator == '=':
            return operand1 == operand2
        elif self.operator == '>=':
            return operand1 >= operand2
        elif self.operator == '>':
            return operand1 > operand2
        elif self.operator == '!':
            return operand1 != operand2

        return False
Пример #3
0
    def match(self, p_todo):
        """
        Performs a match on a key:value tag in the todo.

        First it tries to convert the value and the user-entered expression to
        a date and makes a comparison if it succeeds, based on the given
        operator (default ==).
        Upon failure, it falls back to converting value and user-entered
        expression to an integer and makes a numerical comparison based on the
        given operator (default ==)
        As a last resort, it falls back to using a Grep filter to see if the
        user given expression is contained in the todo text.
        """
        if not self.key or not p_todo.has_tag(self.key):
            return False

        try:
            operand1 = date_string_to_date(p_todo.tag_value(self.key))
            operand2 = relative_date_to_date(self.value)

            if not operand2:
                operand2 = date_string_to_date(self.value)

        except ValueError:
            operand1 = p_todo.tag_value(self.key)
            operand2 = self.value

            try:
                operand1 = int(operand1)
                operand2 = int(operand2)
            except ValueError:
                grep = GrepFilter(self.expression)
                return grep.match(p_todo)

        if self.operator == '<':
            return operand1 < operand2
        elif self.operator == '<=':
            return operand1 <= operand2
        elif self.operator == '=':
            return operand1 == operand2
        elif self.operator == '>=':
            return operand1 >= operand2
        elif self.operator == '>':
            return operand1 > operand2
        elif self.operator == '!':
            return operand1 != operand2

        return False
Пример #4
0
 def process_flag(self, p_opt, p_value):
     if p_opt == "-s" or p_opt == "--strict":
         self.strict_recurrence = True
     elif p_opt == "-d" or p_opt == "--date":
         try:
             self.completion_date = date_string_to_date(p_value)
         except ValueError:
             self.completion_date = date.today()
Пример #5
0
        def _get_offset(p_todo):
            offset = p_todo.tag_value(config().tag_due(),
                                      date.today().isoformat())
            offset_date = date_string_to_date(offset)

            if offset_date < date.today():
                offset_date = date.today()

            return offset_date
Пример #6
0
        def _get_offset(p_todo):
            offset = p_todo.tag_value(
                config().tag_due(), date.today().isoformat())
            offset_date = date_string_to_date(offset)

            if offset_date < date.today():
                offset_date = date.today()

            return offset_date
Пример #7
0
    def process_flag(self, p_opt, p_value):
        super(DoCommand, self).process_flag(p_opt, p_value)

        if p_opt == "-s" or p_opt == "--strict":
            self.strict_recurrence = True
        elif p_opt == "-d" or p_opt == "--date":
            try:
                self.completion_date = date_string_to_date(p_value)
            except ValueError:
                self.completion_date = date.today()
Пример #8
0
    def match(self, p_todo):
        """
        Performs a match on a key:value tag in the todo.

        First it tries to convert the value and the user-entered expression to
        a date and makes a comparison if it succeeds, based on the given
        operator (default ==).
        Upon failure, it falls back to converting value and user-entered
        expression to an integer and makes a numerical comparison based on the
        given operator (default ==)
        As a last resort, it falls back to using a Grep filter to see if the
        user given expression is contained in the todo text.
        """
        def resort_to_grep_filter():
            grep = GrepFilter(self.expression)
            return grep.match(p_todo)

        if not self.key or not p_todo.has_tag(self.key):
            return False

        if len(p_todo.tag_values(self.key)) > 1:
            # we cannot apply an ordening on a tag that appears more than once
            # in this todo item, therefore use a simple value match
            return resort_to_grep_filter()

        try:
            operand1 = date_string_to_date(p_todo.tag_value(self.key))
            operand2 = relative_date_to_date(self.value)

            if not operand2:
                operand2 = date_string_to_date(self.value)

        except ValueError:
            operand1 = p_todo.tag_value(self.key)
            operand2 = self.value

            try:
                operand1 = int(operand1)
                operand2 = int(operand2)
            except ValueError:
                return resort_to_grep_filter()

        return self.compare_operands(operand1, operand2)
Пример #9
0
    def get_date(self, p_tag):
        """ Given a date tag, return a date object. """
        string = self.tag_value(p_tag)
        result = None

        try:
            result = date_string_to_date(string) if string else None
        except ValueError:
            pass

        return result
Пример #10
0
    def get_date(self, p_tag):
        """ Given a date tag, return a date object. """
        string = self.tag_value(p_tag)
        result = None

        try:
            result = date_string_to_date(string) if string else None
        except ValueError:
            pass

        return result
Пример #11
0
    def match(self, p_todo):
        operand1 = self.getter(p_todo)
        operand2 = relative_date_to_date(self.value)

        if not operand2:
            operand2 = date_string_to_date(self.value)

        if operand1 and operand2:
            return self.compare_operands(operand1, operand2)
        else:
            return False
Пример #12
0
    def match(self, p_todo):
        operand1 = self.getter(p_todo)
        operand2 = relative_date_to_date(self.value)

        if not operand2:
            operand2 = date_string_to_date(self.value)

        if operand1 and operand2:
            return self.compare_operands(operand1, operand2)
        else:
            return False
Пример #13
0
                def group_value(p_todo):
                    """
                    Returns a value to assign the given todo to a group. Date tags
                    are grouped according to the relative date (1 day, 1 month,
                    ...)
                    """
                    result = 'No value'

                    if p_todo.has_tag(p_field):
                        if p_field == config().tag_due():
                            result = humanize_date(p_todo.due_date())
                        elif p_field == config().tag_start():
                            result = humanize_date(p_todo.start_date())
                        else:
                            result = p_todo.tag_value(p_field)

                            try:
                                result = humanize_date(date_string_to_date(result))
                            except ValueError:
                                pass

                    return result
Пример #14
0
            def group_value(p_todo):
                """
                Returns a value to assign the given todo to a group. Date tags
                are grouped according to the relative date (1 day, 1 month,
                ...)
                """
                result = 'No value'

                if p_todo.has_tag(p_field):
                    if p_field == config().tag_due():
                        result = humanize_date(p_todo.due_date())
                    elif p_field == config().tag_start():
                        result = humanize_date(p_todo.start_date())
                    else:
                        result = p_todo.tag_value(p_field)

                        try:
                            result = humanize_date(date_string_to_date(result))
                        except ValueError:
                            pass

                return result
Пример #15
0
def parse_line(p_string):
    """
    Parses a single line as can be encountered in a todo.txt file.
    First checks whether the standard elements are present, such as priority,
    creation date, completeness check and the completion date.

    Then the rest of the analyzed for any occurrences of contexts, projects or
    tags.

    Returns an dictionary with the default values as shown below.
    """
    result = {
        'completed': False,
        'completionDate': None,
        'priority': None,
        'creationDate': None,
        'text': "",
        'projects': [],
        'contexts': [],
        'tags': {},
    }

    completed_head = _COMPLETED_HEAD_MATCH.match(p_string)
    normal_head = _NORMAL_HEAD_MATCH.match(p_string)

    rest = p_string

    if completed_head:
        result['completed'] = True

        completion_date = completed_head.group('completionDate')
        try:
            result['completionDate'] = date_string_to_date(completion_date)
        except ValueError:
            pass

        creation_date = completed_head.group('creationDate')

        try:
            result['creationDate'] = date_string_to_date(creation_date)
        except ValueError:
            pass

        rest = completed_head.group('rest')
    elif normal_head:
        result['priority'] = normal_head.group('priority')

        creation_date = normal_head.group('creationDate')

        try:
            result['creationDate'] = date_string_to_date(creation_date)
        except ValueError:
            pass

        rest = normal_head.group('rest')

    for word in rest.split():
        project = _PROJECT_MATCH.match(word)
        if project:
            result['projects'].append(project.group(1))

        context = _CONTEXT_MATCH.match(word)
        if context:
            result['contexts'].append(context.group(1))

        tag = _TAG_MATCH.match(word)
        if tag:
            tag_name = tag.group('tag')
            tag_value = tag.group('value')
            try:
                result['tags'][tag_name].append(tag_value)
            except KeyError:
                result['tags'][tag_name] = [tag_value]
        else:
            result['text'] += word + ' '

    # strip trailing space from resulting text
    result['text'] = result['text'][:-1]

    return result
Пример #16
0
def parse_line(p_string):
    """
    Parses a single line as can be encountered in a todo.txt file.
    First checks whether the standard elements are present, such as priority,
    creation date, completeness check and the completion date.

    Then the rest of the analyzed for any occurrences of contexts, projects or
    tags.

    Returns an dictionary with the default values as shown below.
    """
    result = {
        'completed': False,
        'completionDate': None,
        'priority': None,
        'creationDate': None,
        'text': "",
        'projects': [],
        'contexts': [],
        'tags': {},
    }

    completed_head = _COMPLETED_HEAD_MATCH.match(p_string)
    normal_head = _NORMAL_HEAD_MATCH.match(p_string)

    rest = p_string

    if completed_head:
        result['completed'] = True

        completion_date = completed_head.group('completionDate')
        result['completionDate'] = date_string_to_date(completion_date)

        creation_date = completed_head.group('creationDate')
        result['creationDate'] = date_string_to_date(creation_date)

        rest = completed_head.group('rest')
    elif normal_head:
        result['priority'] = normal_head.group('priority')

        creation_date = normal_head.group('creationDate')
        result['creationDate'] = date_string_to_date(creation_date)

        rest = normal_head.group('rest')

    for word in rest.split():
        project = _PROJECT_MATCH.match(word)
        if project:
            result['projects'].append(project.group(1))

        context = _CONTEXT_MATCH.match(word)
        if context:
            result['contexts'].append(context.group(1))

        tag = _TAG_MATCH.match(word)
        if tag:
            tag_name = tag.group('tag')
            tag_value = tag.group('value')
            try:
                result['tags'][tag_name].append(tag_value)
            except KeyError:
                result['tags'][tag_name] = [tag_value]
        else:
            result['text'] += word + ' '

    # strip trailing space from resulting text
    result['text'] = result['text'][:-1]

    return result