Пример #1
0
    def from_dict(cls, d):
        ''' Like Identity.from_dict, but will cast the class type based on the format.
        i.e. if the format is hdf, return an HdfPartitionIdentity

        :param d:
        :return:
        '''

        from partition import identity_class_from_format_name

        ic = identity_class_from_format_name(d.get('format', 'db'))

        name = ic._name_class(**d)

        if 'id' in d and 'revision' in d:
            # The vid should be constructed from the id and the revision
            on = (ObjectNumber.parse(d['id']).rev(d['revision']))
        elif 'vid' in d:
            on = ObjectNumber.parse(d['vid'])
        else:
            raise ValueError("Must have id and revision, or vid")

        try:
            return ic(name, on)
        except TypeError as e:
            raise TypeError("Failed to make identity from \n{}\n: {}".format(d, e.message))
Пример #2
0
    def new_subclass(cls, name, object_number):

        from partition import identity_class_from_format_name, name_class_from_format_name

        nc = name_class_from_format_name(name.format)
        ic = identity_class_from_format_name(name.format)

        nname = nc(**name.dict)

        return ic(nname, object_number)
Пример #3
0
    def as_partition(self, partition=0, **kwargs):
        '''Return a new PartitionIdentity based on this Identity
        :param partition: Integer partition number for PartitionObjectNumber
        :param kwargs:
        '''

        from partition import identity_class_from_format_name

        assert type(self._name) == Name, "Wrong type: {}".format(type(self._name))
        assert type(self._on) == DatasetNumber, "Wrong type: {}".format(type(self._on))

        name = self._name.as_partition(**kwargs)
        on = self._on.as_partition(partition)

        ic = identity_class_from_format_name(name.format)

        return ic(name,on)