Exemplo n.º 1
0
    def GetTagId(self, tag) -> int:

        clean_tag = HydrusTags.CleanTag(tag)

        try:

            HydrusTags.CheckTagNotEmpty(clean_tag)

        except HydrusExceptions.TagSizeException:

            raise HydrusExceptions.TagSizeException(
                '"{}" tag seems not valid--when cleaned, it ends up with zero size!'
                .format(tag))

        result = self._Execute(
            'SELECT tag_id FROM local_tags_cache WHERE tag = ?;',
            (tag, )).fetchone()

        if result is None:

            return self.modules_tags.GetTagId(tag)

        else:

            (tag_id, ) = result

        return tag_id
Exemplo n.º 2
0
def CheckTagNotEmpty(tag):

    (namespace, subtag) = SplitTag(tag)

    if subtag == '':

        raise HydrusExceptions.TagSizeException('Received a zero-length tag!')
Exemplo n.º 3
0
 def GetTagId( self, tag ) -> int:
     
     clean_tag = HydrusTags.CleanTag( tag )
     
     try:
         
         HydrusTags.CheckTagNotEmpty( clean_tag )
         
     except HydrusExceptions.TagSizeException:
         
         # update this to instead go 'hey, does the dirty tag exist?' if it does, run the fix invalid tags routine
         
         raise HydrusExceptions.TagSizeException( '"{}" tag seems not valid--when cleaned, it ends up with zero size!'.format( tag ) )
         
     
     ( namespace, subtag ) = HydrusTags.SplitTag( clean_tag )
     
     namespace_id = self.GetNamespaceId( namespace )
     subtag_id = self.GetSubtagId( subtag )
     
     result = self._c.execute( 'SELECT tag_id FROM tags WHERE namespace_id = ? AND subtag_id = ?;', ( namespace_id, subtag_id ) ).fetchone()
     
     if result is None:
         
         self._c.execute( 'INSERT INTO tags ( namespace_id, subtag_id ) VALUES ( ?, ? );', ( namespace_id, subtag_id ) )
         
         tag_id = self._c.lastrowid
         
     else:
         
         ( tag_id, ) = result
         
     
     return tag_id