Commit b06ef671 authored by Anael Beutot's avatar Anael Beutot Committed by Antoine Millet
Browse files

Added a method for checking tag name conflicts

parent e360a294
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -282,6 +282,26 @@ class TagDB(object):
                self._parent.add_sub_object(sub_id, db.itervalues(),
                                            self._object_types[sub_id])

    def check_tags_conflict(self, *tag_names):
        """Checks a list of tag names that might conflict before inserting in
        TagDB hierarchy

        .. warning::
            This is in no way a guarantee that following inserts will succeed.
        """
        conflicts = []
        parent_check = []
        for name in tag_names:
            if name in self.db['__main__']:
                conflicts.append(name)
            else:
                parent_check.append(name)

        if self._parent is not None and parent_check:
            conflicts.extend(self._parent.check_tags_conflict(*parent_check))

        return conflicts

    # tag handling part, used by plugins
    def add_tags(self, tags, ignore_errors=False):
        """