Beispiel #1
0
    def __init__(self, id=None, created=None, modified=None, **kwargs):
        """Creates a new Resource with the given optional arguments.

        :param int id: The ID of the resource (assigned automatically upon creation).
        :param created: The created timestamp (assigned automatically).
        :param modified: The modification timestamp (updated automatically).
        :type created: str, ~datetime.datetime
        :type modified: str, ~datetime.datetime
        """
        super(TimestampedResource, self).__init__(id=id)

        try:
            if created:
                self._set('created', Timestamp.to_datetime(created))
            if modified:
                self._set('modified', Timestamp.to_datetime(modified))
        except (TypeError, ValueError) as e:
            raise exceptions.ValidationError(e)
Beispiel #2
0
    def start(self, start):
        """Set the timestamp for the first scheduled instance.

        :param start: The start timestamp.
        :type start: str, ~datetime.datetime
        :raise ~fetchcore.exceptions.ValidationError: Thrown if the timestamp is not a string or cannot be parsed.
        """
        try:
            self._set('start', Timestamp.to_datetime(start))
        except (TypeError, ValueError) as e:
            raise ValidationError(e)
Beispiel #3
0
    def end(self, end):
        """Sets the timestamp that indicates when the action stopped execution

        :param str, ~datetime.datetime end: A timestamp
        """
        if end is None:
            self._set("end", end)
        else:
            try:
                self._set("end", Timestamp.to_datetime(end))
            except (TypeError, ValueError) as e:
                raise ValidationError(e)
Beispiel #4
0
    def start(self, start):
        """Sets the timestamp that indicates when the action started execution

        :param str, ~datetime.datetime start: A timestamp
        """
        if start is None:
            self._set("start", start)
        else:
            try:
                self._set("start", Timestamp.to_datetime(start))
            except (TypeError, ValueError) as e:
                raise ValidationError(e)
Beispiel #5
0
    def last_boot(self, last_boot):
        """Sets the timestamp that indicates when the robot's computer last booted

        :param last_boot: (string|datetime.datetime) A timestamp
        """
        if last_boot is None:
            self._set("last_boot", last_boot)
        else:
            try:
                self._set("last_boot", Timestamp.to_datetime(last_boot))
            except (TypeError, ValueError) as e:
                raise exceptions.ValidationError(e)
Beispiel #6
0
    def last_connection_time(self, last_connection_time):
        """Sets the timestamp that indicates when the robot last connected

        :param last_connection_time: (string|datetime.datetime) A timestamp
        """
        if last_connection_time is None:
            self._set("last_connection_time", last_connection_time)
        else:
            try:
                self._set("last_connection_time", Timestamp.to_datetime(last_connection_time))
            except (TypeError, ValueError) as e:
                raise exceptions.ValidationError(e)
Beispiel #7
0
    def last_deep_charge(self, last_deep_charge):
        """Sets the timestamp that indicates when the robot was last charged

        :param last_deep_charge: (string|datetime.datetime) A timestamp
        """
        if last_deep_charge is None:
            self._set("last_deep_charge", last_deep_charge)
        else:
            try:
                self._set("last_deep_charge",
                          Timestamp.to_datetime(last_deep_charge))
            except (TypeError, ValueError) as e:
                raise ValidationError(e)
Beispiel #8
0
    def end(self, end):
        """Set the timestamp for the last scheduled instance

        :param end: The end timestamp.
        :type end: str, ~datetime.datetime
        :raise: ~fetchcore.exceptions.ValidationError Thrown if the timestamp is not a string or cannot be parsed.
        """
        if end is None:
            self._set('end', end)
        else:
            try:
                self._set('end', Timestamp.to_datetime(end))
            except (TypeError, ValueError) as e:
                raise ValidationError(e)
    def to_json_dict(self):
        """Gets the copy of the JSON document

        :return: the JSON document
        """
        self.check_input_fields()
        base = super(BaseAction, self).to_json_dict()
        for key, value in base.get('inputs', {}).iteritems():
            try:
                if isinstance(value, datetime.datetime):
                    base['inputs'][key] = Timestamp.to_string(value)
                elif isinstance(value, datetime.timedelta):
                    base['inputs'][key] = Duration.to_string(value)
            except TypeError as e:
                raise ValidationError(e)
        return base
Beispiel #10
0
    def set_values(self, key, value):
        """Saves the data that is received from the server.

        :param key: The key to save the data for.
        :param value: The value to save.
        """
        if key == 'created' or key == 'modified':
            try:
                self._set(key, Timestamp.to_datetime(value))
            except (TypeError, ValueError) as e:
                raise exceptions.ValidationError(e)
        elif key == 'id':
            self._set(key, value)
        elif key in self.read_only_fields:
            self._set(key, value)
        else:
            self.__setattr__(key, value)
Beispiel #11
0
    def to_json_dict(self):
        """Returns a copy of this Resource as a JSON dictionary.

        :return: A copy of this Resource as a JSON dictionary.
        """
        # Convert standard types to strings
        final = {}
        for key, value in self.__json.iteritems():
            try:
                if isinstance(value, datetime.datetime):
                    final[key] = Timestamp.to_string(value)
                elif isinstance(value, datetime.timedelta):
                    final[key] = Duration.to_string(value)
                else:
                    final[key] = value
            except TypeError as e:
                raise ValidationError(e)
        return final