Ejemplo n.º 1
0
    def testParseDateLimit(self):
        # Fake today to a fixed date. This is a saturday (weekday=5).
        today = datetime(2009, 1, 3)
        endOfDay = dict(hour=23, minute=59, second=59)
        startOfDay = dict(hour=0, minute=0, second=0)

        testData = [
            ("today", operator.__le__, today.replace(**endOfDay)),
            ("<=today", operator.__le__, today.replace(**endOfDay)),
            ("<today", operator.__lt__, today.replace(**startOfDay)),
            (">today", operator.__gt__, today.replace(**endOfDay)),
            (">=today", operator.__ge__, today.replace(**startOfDay)),
            ("<=06/02/2009", operator.__le__, datetime(2009, 2,
                                                       6).replace(**endOfDay)),
            ("<06/02/2009", operator.__lt__,
             datetime(2009, 2, 6).replace(**startOfDay)),
            ("tomorrow 18:00", operator.__le__,
             today + timedelta(days=1, hours=18)),
            ("sunday", operator.__le__, datetime(2009, 1,
                                                 4).replace(**endOfDay)),
            ("tu 11:45", operator.__le__, datetime(2009, 1, 6, 11, 45)),
        ]

        for text, expectedOp, expectedDate in testData:
            output = ydateutils.parseDateLimit(text, today=today)
            output = ydateutils.parseDateLimit(text, today=today)
            self.assertEquals(expectedOp, output[0])
            self.assertEquals(expectedDate, output[1])
Ejemplo n.º 2
0
    def testParseDateLimit(self):
        # Fake today to a fixed date. This is a saturday (weekday=5).
        today = datetime(2009, 1, 3)
        endOfDay = dict(hour=23, minute=59, second=59)
        startOfDay = dict(hour=0, minute=0, second=0)

        testData = [
            ("today", operator.__le__, today.replace(**endOfDay)),
            ("<=today", operator.__le__, today.replace(**endOfDay)),
            ("<today", operator.__lt__, today.replace(**startOfDay)),
            (">today", operator.__gt__, today.replace(**endOfDay)),
            (">=today", operator.__ge__, today.replace(**startOfDay)),
            ("<=06/02/2009", operator.__le__, datetime(2009, 2, 6).replace(**endOfDay)),
            ("<06/02/2009", operator.__lt__, datetime(2009, 2, 6).replace(**startOfDay)),
            ("tomorrow 18:00", operator.__le__, today + timedelta(days=1, hours=18)),
            ("sunday", operator.__le__, datetime(2009, 1, 4).replace(**endOfDay)),
            ("tu 11:45", operator.__le__, datetime(2009, 1, 6, 11, 45)),
            ]

        for text, expectedOp, expectedDate in testData:
            output = ydateutils.parseDateLimit(text, today=today)
            output = ydateutils.parseDateLimit(text, today=today)
            self.assertEqual(expectedOp, output[0])
            self.assertEqual(expectedDate, output[1])
Ejemplo n.º 3
0
    def do_t_list(self, line, renderer=None):

        def selectRendererClass():
            if args.format != "auto":
                return gRendererClassDict[args.format]

            defaultRendererClass = TextListRenderer
            if not args.output:
                return defaultRendererClass

            ext = os.path.splitext(args.output)[1]
            if not ext:
                return defaultRendererClass

            return gRendererClassDict.get(ext[1:], defaultRendererClass)

        # Reset last tasks id list
        self.lastTaskIds = []

        # BUG: completion based on parameter position is broken when parameter is given"
        args, projectList, filters = self._parseListLine(self.parser_t_list(), line)

        # Skip notes
        filters.append(parseutils.KeywordFilter("!@" + NOTE_KEYWORD).filter())

        # Handle t_list specific options
        order = [desc(Task.urgency), Task.creationDate]
        limit = None
        if args.done:
            filters.append(Task.status == 'done')
            if args.done != "all":
                minDate = ydateutils.parseMinDate(args.done)
                filters.append(Task.doneDate >= minDate)
        elif args.status == "all":
            pass
        elif args.status == "started":
            filters.append(Task.status == "started")
        else:
            filters.append(Task.status != "done")
        if args.urgency:
            order = [desc(Task.urgency), ]
            filters.append(Task.urgency >= args.urgency)
        if args.topDue:
            filters.append(Task.dueDate != None)
            order = [Task.dueDate, ]
            limit = 5
        if args.due:
            for due in args.due:
                dueOperator, dueLimit = ydateutils.parseDateLimit(due)
                filters.append(dueOperator(Task.dueDate, dueLimit))
            order = [Task.dueDate, ]
        if args.decrypt:
            self.cryptoMgr.force_decrypt = True

        # Define output
        if args.output:
            out = open(args.output, "w", encoding='utf-8')
        else:
            out = tui.stdout

        # Instantiate renderer
        if renderer is None:
            rendererClass = selectRendererClass()
            renderer = rendererClass(out, cryptoMgr=self.cryptoMgr)

        # Fill the renderer
        self._renderList(renderer, projectList, filters, order, limit, args.keyword)
Ejemplo n.º 4
0
    def do_t_list(self, line):
        def selectRendererClass():
            if args.format != "auto":
                return gRendererClassDict[args.format]

            defaultRendererClass = TextListRenderer
            if not args.output:
                return defaultRendererClass

            ext = os.path.splitext(args.output)[1]
            if not ext:
                return defaultRendererClass

            return gRendererClassDict.get(ext[1:], defaultRendererClass)

        # Reset last tasks id list
        self.lastTaskIds = []

        # BUG: completion based on parameter position is broken when parameter is given
        args, projectList, filters = self._parseListLine(
            self.parser_t_list(), line)

        # Skip notes
        filters.append(parseutils.KeywordFilter("!@" + NOTE_KEYWORD).filter())

        # Handle t_list specific options
        order = -Task.q.urgency, Task.q.creationDate
        limit = None
        if args.done:
            filters.append(Task.q.status == 'done')
            if args.done != "all":
                minDate = ydateutils.parseMinDate(args.done)
                filters.append(Task.q.doneDate >= minDate)
        elif args.status == "all":
            pass
        elif args.status == "started":
            filters.append(Task.q.status == 'started')
        else:
            filters.append(Task.q.status != 'done')
        if args.urgency:
            order = -Task.q.urgency
            filters.append(Task.q.urgency >= args.urgency)
        if args.topDue:
            filters.append(Task.q.dueDate != None)
            order = Task.q.dueDate
            limit = 5
        if args.due:
            for due in args.due:
                dueOperator, dueLimit = ydateutils.parseDateLimit(due)
                filters.append(dueOperator(Task.q.dueDate, dueLimit))
            order = Task.q.dueDate
        if args.decrypt:
            self.cryptoMgr.force_decrypt = True

        # Define output
        if args.output:
            out = open(args.output, "w")
        else:
            out = tui.stdout

        # Instantiate renderer
        rendererClass = selectRendererClass()
        renderer = rendererClass(out, cryptoMgr=self.cryptoMgr)

        # Fill the renderer
        self._renderList(renderer, projectList, filters, order, limit,
                         args.keyword)