示例#1
0
    def check_fact(self, fact, default_day=None):
        """Check Fact validity for inclusion in the storage.

        default_day (date): Default hamster day,
                            used to simplify some hint messages
                            (remove unnecessary dates).
                            None is safe (always show dates).
        """
        if not fact.start_time:
            # Do not even try to pass fact through D-Bus as
            # conversions would fail in this case.
            raise FactError("Missing start time")
        dbus_fact = to_dbus_fact(fact)
        dbus_day = to_dbus_date(default_day)
        success, message = self.conn.CheckFact(dbus_fact, dbus_day)
        if not success:
            raise FactError(message)
        return success, message
示例#2
0
    def check_fact(cls, fact, default_day=None):
        """Check Fact validity for inclusion in the storage.

        Raise FactError(message) on failure.
        """
        if fact.start_time is None:
            raise FactError("Missing start time")

        if fact.end_time and (fact.delta < dt.timedelta(0)):
            fixed_fact = Fact(start_time=fact.start_time,
                              end_time=fact.end_time + dt.timedelta(days=1))
            suggested_range_str = fixed_fact.range.format(default_day=default_day)
            # work around cyclic imports
            from hamster.lib.configuration import conf
            raise FactError(dedent(
                """\
                Duration would be negative.
                Working late ?
                This happens when the activity crosses the
                hamster day start time ({:%H:%M} from tracking settings).

                Suggestion: move the end to the next day; the range would become:
                {}
                (in civil local time)
                """.format(conf.day_start, suggested_range_str)
                ))

        if not fact.activity:
            raise FactError("Missing activity")

        if ',' in fact.category:
            raise FactError(dedent(
                """\
                Forbidden comma in category: '{}'
                Note: The description separator changed
                      from single comma to double comma ',,' (cf. PR #482).
                """.format(fact.category)
                ))