Exemple #1
0
    def update(self, other):
        """ Merge two Textgroup Objects.

        - Original (left Object) keeps his parent.
        - Added document merges with work if it already exists

        :param other: Textgroup object
        :type other: CtsTextgroupMetadata
        :return: Textgroup Object
        :rtype: CtsTextgroupMetadata
        """
        if not isinstance(other, CtsTextgroupMetadata):
            raise TypeError("Cannot add %s to CtsTextgroupMetadata" %
                            type(other))
        elif str(self.urn) != str(other.urn):
            raise InvalidURN(
                "Cannot add CtsTextgroupMetadata %s to CtsTextgroupMetadata %s "
                % (self.urn, other.urn))

        for urn, work in other.works.items():
            if urn in self.works:
                self.works[urn].update(deepcopy(work))
            else:
                self.works[urn] = deepcopy(work)
            self.works[urn].parent = self
            self.works[urn].resource = None

        return self
Exemple #2
0
    def update(self, other):
        """ Merge two Work Objects.

        - Original (left Object) keeps his parent.
        - Added document overwrite text if it already exists

        :param other: Work object
        :type other: Work
        :return: Work Object
        :rtype Work:
        """
        if not isinstance(other, Work):
            raise TypeError("Cannot add %s to Work" % type(other))
        elif self.urn != other.urn:
            raise InvalidURN("Cannot add Work %s to Work %s " %
                             (self.urn, other.urn))

        self.metadata += other.metadata
        parents = [self] + self.parents
        for urn, text in other.texts.items():
            if urn in self.texts:
                self.texts[urn] = deepcopy(text)
            else:
                self.texts[urn] = deepcopy(text)
            self.texts[urn].parents = parents
            self.texts[urn].resource = None

        return self
Exemple #3
0
 def __getText__(self, urn):
     if not isinstance(urn, URN):
         urn = URN(urn)
     if len(urn) != 5:
         # this is different from MyCapytain in that we don't need to look
         # the first passage. let's always assume we get the right thing.
         raise InvalidURN()
     metadata = self.inventory[str(urn)]
     text = self.load_text(metadata.path)
     return text, metadata
Exemple #4
0
    def update(self, other):
        """ Merge two XmlCtsWorkMetadata Objects.

        - Original (left Object) keeps his parent.
        - Added document overwrite text if it already exists

        :param other: XmlCtsWorkMetadata object
        :type other: CtsWorkMetadata
        :return: XmlCtsWorkMetadata Object
        :rtype XmlCtsWorkMetadata:
        """
        if not isinstance(other, CtsWorkMetadata):
            raise TypeError("Cannot add %s to CtsWorkMetadata" % type(other))
        elif self.urn != other.urn:
            raise InvalidURN(
                "Cannot add CtsWorkMetadata %s to CtsWorkMetadata %s " %
                (self.urn, other.urn))

        for urn, text in other.children.items():
            self.texts[urn] = text
            self.texts[urn].parent = self
            self.texts[urn].resource = None

        return self