コード例 #1
0
    def GetServiceKeysToContentUpdates(
            self,
            status: int,
            media_result: ClientMediaResult.MediaResult,
            filterable_tags: typing.Iterable[str],
            external_filterable_tags=None,
            external_additional_service_keys_to_tags=None):

        if external_filterable_tags is None:

            external_filterable_tags = set()

        if external_additional_service_keys_to_tags is None:

            external_additional_service_keys_to_tags = ClientTags.ServiceKeysToTags(
            )

        filterable_tags = HydrusTags.CleanTags(filterable_tags)

        service_keys_to_tags = ClientTags.ServiceKeysToTags()

        for service_key in HG.client_controller.services_manager.GetServiceKeys(
                HC.REAL_TAG_SERVICES):

            service_additional_tags = set()

            if service_key in external_additional_service_keys_to_tags:

                service_additional_tags.update(
                    external_additional_service_keys_to_tags[service_key])

            if service_key in self._service_keys_to_service_tag_import_options:

                service_tag_import_options = self._service_keys_to_service_tag_import_options[
                    service_key]

                service_filterable_tags = set(filterable_tags)

                service_filterable_tags.update(external_filterable_tags)

                service_tags = service_tag_import_options.GetTags(
                    service_key, status, media_result, service_filterable_tags,
                    service_additional_tags)

            else:

                service_tags = service_additional_tags

            if len(service_tags) > 0:

                service_keys_to_tags[service_key] = service_tags

        hash = media_result.GetHash()

        service_keys_to_content_updates = ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates(
            {hash}, service_keys_to_tags)

        return service_keys_to_content_updates
コード例 #2
0
def FilterDeletedTags( service_key: bytes, media_result: ClientMediaResult.MediaResult, tags: typing.Iterable[ str ] ):
    
    tags_manager = media_result.GetTagsManager()
    
    deleted_tags = tags_manager.GetDeleted( service_key, ClientTags.TAG_DISPLAY_STORAGE )
    
    tags = set( tags ).difference( deleted_tags )
    
    return tags
コード例 #3
0
    def GetTags(
            self,
            service_key: bytes,
            status: int,
            media_result: ClientMediaResult.MediaResult,
            filterable_tags: typing.Collection[str],
            additional_tags: typing.Optional[typing.Collection[str]] = None):

        if additional_tags is None:

            additional_tags = set()

        tags = set()

        in_inbox = media_result.GetInbox()

        if ClientImportOptions.NewInboxArchiveMatch(
                self._to_new_files, self._to_already_in_inbox,
                self._to_already_in_archive, status, in_inbox):

            if self._get_tags:

                filtered_tags = self._get_tags_filter.Filter(filterable_tags)

                if not self._get_tags_overwrite_deleted:

                    filtered_tags = ClientImportOptions.FilterDeletedTags(
                        service_key, media_result, filtered_tags)

                tags.update(filtered_tags)

            additional_tags = set(additional_tags)
            additional_tags.update(self._additional_tags)

            additional_tags = HydrusTags.CleanTags(additional_tags)

            if not self._additional_tags_overwrite_deleted:

                additional_tags = ClientImportOptions.FilterDeletedTags(
                    service_key, media_result, additional_tags)

            tags.update(additional_tags)

            if self._only_add_existing_tags:

                applicable_tags = self._only_add_existing_tags_filter.Filter(
                    tags)

                tags.difference_update(applicable_tags)

                existing_applicable_tags = HG.client_controller.Read(
                    'filter_existing_tags', service_key, applicable_tags)

                tags.update(existing_applicable_tags)

        return tags
コード例 #4
0
 def GetServiceKeysToContentUpdates( self, media_result: ClientMediaResult.MediaResult, names_and_notes: typing.Collection[ typing.Tuple[ str, str ] ] ):
     
     content_updates = []
     
     if self._get_notes:
         
         hash = media_result.GetHash()
         
         notes_manager = media_result.GetNotesManager()
         
         existing_names_to_notes = dict( notes_manager.GetNamesToNotes() )
         
         for ( name, note ) in names_and_notes:
             
             if name in self._names_to_name_overrides:
                 
                 name = self._names_to_name_overrides[ name ]
                 
             elif self._all_name_override is not None:
                 
                 name = self._all_name_override
                 
             
             if name in existing_names_to_notes:
                 
                 name_exists = True
                 
                 existing_note = existing_names_to_notes[ name ]
                 
                 name_and_note_exists = existing_note == note
                 
                 new_note_is_an_extension = existing_note in note
                 
             else:
                 
                 name_exists = False
                 name_and_note_exists = False
                 new_note_is_an_extension = False
                 
             
             do_it = True
             
             if name_and_note_exists:
                 
                 do_it = False
                 
             elif name_exists:
                 
                 if new_note_is_an_extension and self._extend_existing_note_if_possible:
                     
                     pass # yes let's do it with current name and note
                     
                 else:
                     
                     if self._conflict_resolution == NOTE_IMPORT_CONFLICT_IGNORE:
                         
                         do_it = False
                         
                     elif self._conflict_resolution == NOTE_IMPORT_CONFLICT_RENAME:
                         
                         existing_names = set( existing_names_to_notes.keys() )
                         
                         name = HydrusData.GetNonDupeName( name, existing_names )
                         
                     elif self._conflict_resolution == NOTE_IMPORT_CONFLICT_APPEND:
                         
                         existing_note = existing_names_to_notes[ name ]
                         
                         sep = os.linesep * 2
                         
                         note = sep.join( ( existing_note, note ) )
                         
                     
                 
             
             if do_it:
                 
                 existing_names_to_notes[ name ] = note
                 
                 content_updates.append( HydrusData.ContentUpdate( HC.CONTENT_TYPE_NOTES, HC.CONTENT_UPDATE_SET, ( hash, name, note ) ) )
                 
             
         
     
     service_keys_to_content_updates = {}
     
     if len( content_updates ) > 0:
         
         service_keys_to_content_updates[ CC.LOCAL_NOTES_SERVICE_KEY ] = content_updates
         
     
     return service_keys_to_content_updates