Beispiel #1
0
    def Regen(self, tag_service_ids):

        for tag_service_id in tag_service_ids:

            cache_tag_parents_lookup_table_name = GenerateTagParentsLookupCacheTableName(
                ClientTags.TAG_DISPLAY_IDEAL, tag_service_id)

            self._Execute(
                'DELETE FROM {};'.format(cache_tag_parents_lookup_table_name))

            applicable_service_ids = self.GetApplicableServiceIds(
                tag_service_id)

            tps = ClientTagsHandling.TagParentsStructure()

            for applicable_service_id in applicable_service_ids:

                unideal_statuses_to_pair_ids = self.GetTagParentsIds(
                    service_id=applicable_service_id)

                # we have to collapse the parent ids according to siblings

                ideal_statuses_to_pair_ids = self.IdealiseStatusesToPairIds(
                    tag_service_id, unideal_statuses_to_pair_ids)

                #

                petitioned_fast_lookup = set(
                    ideal_statuses_to_pair_ids[HC.CONTENT_STATUS_PETITIONED])

                for (child_tag_id,
                     parent_tag_id) in ideal_statuses_to_pair_ids[
                         HC.CONTENT_STATUS_CURRENT]:

                    if (child_tag_id, parent_tag_id) in petitioned_fast_lookup:

                        continue

                    tps.AddPair(child_tag_id, parent_tag_id)

                for (child_tag_id,
                     parent_tag_id) in ideal_statuses_to_pair_ids[
                         HC.CONTENT_STATUS_PENDING]:

                    tps.AddPair(child_tag_id, parent_tag_id)

            self._ExecuteMany(
                'INSERT OR IGNORE INTO {} ( child_tag_id, ancestor_tag_id ) VALUES ( ?, ? );'
                .format(cache_tag_parents_lookup_table_name),
                tps.IterateDescendantAncestorPairs())

            if tag_service_id in self._service_ids_to_display_application_status:

                del self._service_ids_to_display_application_status[
                    tag_service_id]
    def Regen(self, tag_service_ids):

        for tag_service_id in tag_service_ids:

            cache_tag_siblings_lookup_table_name = GenerateTagSiblingsLookupCacheTableName(
                ClientTags.TAG_DISPLAY_IDEAL, tag_service_id)

            self._Execute(
                'DELETE FROM {};'.format(cache_tag_siblings_lookup_table_name))

            applicable_service_ids = self.GetApplicableServiceIds(
                tag_service_id)

            tss = ClientTagsHandling.TagSiblingsStructure()

            for applicable_service_id in applicable_service_ids:

                statuses_to_pair_ids = self.GetTagSiblingsIds(
                    service_id=applicable_service_id)

                petitioned_fast_lookup = set(
                    statuses_to_pair_ids[HC.CONTENT_STATUS_PETITIONED])

                for (bad_tag_id, good_tag_id
                     ) in statuses_to_pair_ids[HC.CONTENT_STATUS_CURRENT]:

                    if (bad_tag_id, good_tag_id) in petitioned_fast_lookup:

                        continue

                    tss.AddPair(bad_tag_id, good_tag_id)

                for (bad_tag_id, good_tag_id
                     ) in statuses_to_pair_ids[HC.CONTENT_STATUS_PENDING]:

                    tss.AddPair(bad_tag_id, good_tag_id)

            self._ExecuteMany(
                'INSERT OR IGNORE INTO {} ( bad_tag_id, ideal_tag_id ) VALUES ( ?, ? );'
                .format(cache_tag_siblings_lookup_table_name),
                tss.GetBadTagsToIdealTags().items())

            if tag_service_id in self._service_ids_to_display_application_status:

                del self._service_ids_to_display_application_status[
                    tag_service_id]
Beispiel #3
0
    def __init__(self, win, only_run):

        self.app = win
        self.win = win
        self.only_run = only_run

        self.db_dir = tempfile.mkdtemp()

        global DB_DIR

        DB_DIR = self.db_dir

        self._server_files_dir = os.path.join(self.db_dir, 'server_files')
        self._updates_dir = os.path.join(self.db_dir, 'test_updates')

        client_files_default = os.path.join(self.db_dir, 'client_files')

        HydrusPaths.MakeSureDirectoryExists(self._server_files_dir)
        HydrusPaths.MakeSureDirectoryExists(self._updates_dir)
        HydrusPaths.MakeSureDirectoryExists(client_files_default)

        HG.controller = self
        HG.client_controller = self
        HG.server_controller = self
        HG.test_controller = self

        self.db = self
        self.gui = self

        self.frame_splash_status = ClientGUISplash.FrameSplashStatus()

        self._call_to_threads = []

        self._pubsub = HydrusPubSub.HydrusPubSub(self, lambda o: True)

        self.new_options = ClientOptions.ClientOptions()

        HC.options = ClientDefaults.GetClientDefaultOptions()

        self.options = HC.options

        def show_text(text):
            pass

        HydrusData.ShowText = show_text

        self._reads = {}

        self._reads['local_booru_share_keys'] = []
        self._reads['messaging_sessions'] = []
        self._reads['options'] = ClientDefaults.GetClientDefaultOptions()
        self._reads['file_system_predicates'] = []
        self._reads['media_results'] = []

        self._param_reads = {}

        self.example_tag_repo_service_key = HydrusData.GenerateKey()

        services = []

        services.append(
            ClientServices.GenerateService(CC.LOCAL_BOORU_SERVICE_KEY,
                                           HC.LOCAL_BOORU, 'local booru'))
        services.append(
            ClientServices.GenerateService(CC.CLIENT_API_SERVICE_KEY,
                                           HC.CLIENT_API_SERVICE,
                                           'client api'))
        services.append(
            ClientServices.GenerateService(CC.COMBINED_LOCAL_FILE_SERVICE_KEY,
                                           HC.COMBINED_LOCAL_FILE,
                                           'all local files'))
        services.append(
            ClientServices.GenerateService(CC.LOCAL_FILE_SERVICE_KEY,
                                           HC.LOCAL_FILE_DOMAIN, 'my files'))
        services.append(
            ClientServices.GenerateService(CC.TRASH_SERVICE_KEY,
                                           HC.LOCAL_FILE_TRASH_DOMAIN,
                                           'trash'))
        services.append(
            ClientServices.GenerateService(CC.DEFAULT_LOCAL_TAG_SERVICE_KEY,
                                           HC.LOCAL_TAG, 'my tags'))
        services.append(
            ClientServices.GenerateService(self.example_tag_repo_service_key,
                                           HC.TAG_REPOSITORY,
                                           'example tag repo'))
        services.append(
            ClientServices.GenerateService(CC.COMBINED_TAG_SERVICE_KEY,
                                           HC.COMBINED_TAG, 'all known tags'))
        services.append(
            ClientServices.GenerateService(
                LOCAL_RATING_LIKE_SERVICE_KEY, HC.LOCAL_RATING_LIKE,
                'example local rating like service'))
        services.append(
            ClientServices.GenerateService(
                LOCAL_RATING_NUMERICAL_SERVICE_KEY, HC.LOCAL_RATING_NUMERICAL,
                'example local rating numerical service'))

        self._reads['services'] = services

        client_files_locations = {}

        for prefix in HydrusData.IterateHexPrefixes():

            for c in ('f', 't'):

                client_files_locations[c + prefix] = client_files_default

        self._reads['client_files_locations'] = client_files_locations

        self._reads['sessions'] = []
        self._reads['tag_parents'] = {}
        self._reads['tag_siblings_all_ideals'] = {}
        self._reads['in_inbox'] = False

        self._writes = collections.defaultdict(list)

        self._managers = {}

        self.column_list_manager = ClientGUIListManager.ColumnListManager()

        self.services_manager = ClientServices.ServicesManager(self)
        self.client_files_manager = ClientFiles.ClientFilesManager(self)

        self.parsing_cache = ClientCaches.ParsingCache()

        bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
        session_manager = ClientNetworkingSessions.NetworkSessionManager()
        domain_manager = ClientNetworkingDomain.NetworkDomainManager()

        ClientDefaults.SetDefaultDomainManagerData(domain_manager)

        login_manager = ClientNetworkingLogin.NetworkLoginManager()

        self.network_engine = ClientNetworking.NetworkEngine(
            self, bandwidth_manager, session_manager, domain_manager,
            login_manager)

        self.CallToThreadLongRunning(self.network_engine.MainLoop)

        self.tag_display_manager = ClientTagsHandling.TagDisplayManager()

        self._managers['undo'] = ClientManagers.UndoManager(self)
        self.server_session_manager = HydrusSessions.HydrusSessionManagerServer(
        )

        self.bitmap_manager = ClientManagers.BitmapManager(self)

        self.local_booru_manager = ClientCaches.LocalBooruCache(self)
        self.client_api_manager = ClientAPI.APIManager()

        self._cookies = {}

        self._job_scheduler = HydrusThreading.JobScheduler(self)

        self._job_scheduler.start()
Beispiel #4
0
    def RegenChains(self, tag_service_ids, tag_ids):

        if len(tag_ids) == 0:

            return

        for tag_service_id in tag_service_ids:

            cache_tag_parents_lookup_table_name = GenerateTagParentsLookupCacheTableName(
                ClientTags.TAG_DISPLAY_IDEAL, tag_service_id)

            # it is possible that the parents cache currently contains non-ideal tag_ids
            # so, to be safe, we'll also get all sibling chain members

            tag_ids_to_clear_and_regen = set(tag_ids)

            ideal_tag_ids = self.modules_tag_siblings.GetIdeals(
                ClientTags.TAG_DISPLAY_IDEAL, tag_service_id, tag_ids)

            tag_ids_to_clear_and_regen.update(
                self.modules_tag_siblings.GetChainsMembersFromIdeals(
                    ClientTags.TAG_DISPLAY_IDEAL, tag_service_id,
                    ideal_tag_ids))

            # and now all possible current parent chains based on this

            tag_ids_to_clear_and_regen.update(
                self.GetChainsMembers(ClientTags.TAG_DISPLAY_IDEAL,
                                      tag_service_id,
                                      tag_ids_to_clear_and_regen))

            # this should now contain all possible tag_ids that could be in tag parents right now related to what we were given

            self._ExecuteMany(
                'DELETE FROM {} WHERE child_tag_id = ? OR ancestor_tag_id = ?;'
                .format(cache_tag_parents_lookup_table_name),
                ((tag_id, tag_id) for tag_id in tag_ids_to_clear_and_regen))

            # we wipe them

            applicable_tag_service_ids = self.GetApplicableServiceIds(
                tag_service_id)

            tps = ClientTagsHandling.TagParentsStructure()

            for applicable_tag_service_id in applicable_tag_service_ids:

                service_key = self.modules_services.GetService(
                    applicable_tag_service_id).GetServiceKey()

                unideal_statuses_to_pair_ids = self.GetTagParentsIdsChains(
                    applicable_tag_service_id, tag_ids_to_clear_and_regen)

                ideal_statuses_to_pair_ids = self.IdealiseStatusesToPairIds(
                    tag_service_id, unideal_statuses_to_pair_ids)

                #

                petitioned_fast_lookup = set(
                    ideal_statuses_to_pair_ids[HC.CONTENT_STATUS_PETITIONED])

                for (child_tag_id,
                     parent_tag_id) in ideal_statuses_to_pair_ids[
                         HC.CONTENT_STATUS_CURRENT]:

                    if (child_tag_id, parent_tag_id) in petitioned_fast_lookup:

                        continue

                    tps.AddPair(child_tag_id, parent_tag_id)

                for (child_tag_id,
                     parent_tag_id) in ideal_statuses_to_pair_ids[
                         HC.CONTENT_STATUS_PENDING]:

                    tps.AddPair(child_tag_id, parent_tag_id)

            self._ExecuteMany(
                'INSERT OR IGNORE INTO {} ( child_tag_id, ancestor_tag_id ) VALUES ( ?, ? );'
                .format(cache_tag_parents_lookup_table_name),
                tps.IterateDescendantAncestorPairs())

            if tag_service_id in self._service_ids_to_display_application_status:

                del self._service_ids_to_display_application_status[
                    tag_service_id]
    def RegenChains(self, tag_service_ids, tag_ids):

        # as this guy can change ideals, the related parent chains need to be regenned afterwards too

        if len(tag_ids) == 0:

            return

        for tag_service_id in tag_service_ids:

            cache_tag_siblings_lookup_table_name = GenerateTagSiblingsLookupCacheTableName(
                ClientTags.TAG_DISPLAY_IDEAL, tag_service_id)

            tag_ids_to_clear_and_regen = set(tag_ids)

            ideal_tag_ids = self.GetIdeals(ClientTags.TAG_DISPLAY_IDEAL,
                                           tag_service_id, tag_ids)

            tag_ids_to_clear_and_regen.update(
                self.GetChainsMembersFromIdeals(ClientTags.TAG_DISPLAY_IDEAL,
                                                tag_service_id, ideal_tag_ids))

            self._ExecuteMany(
                'DELETE FROM {} WHERE bad_tag_id = ? OR ideal_tag_id = ?;'.
                format(cache_tag_siblings_lookup_table_name),
                ((tag_id, tag_id) for tag_id in tag_ids_to_clear_and_regen))

            applicable_tag_service_ids = self.GetApplicableServiceIds(
                tag_service_id)

            tss = ClientTagsHandling.TagSiblingsStructure()

            for applicable_tag_service_id in applicable_tag_service_ids:

                service_key = self.modules_services.GetService(
                    applicable_tag_service_id).GetServiceKey()

                statuses_to_pair_ids = self.GetTagSiblingsIdsChains(
                    applicable_tag_service_id, tag_ids_to_clear_and_regen)

                petitioned_fast_lookup = set(
                    statuses_to_pair_ids[HC.CONTENT_STATUS_PETITIONED])

                for (bad_tag_id, good_tag_id
                     ) in statuses_to_pair_ids[HC.CONTENT_STATUS_CURRENT]:

                    if (bad_tag_id, good_tag_id) in petitioned_fast_lookup:

                        continue

                    tss.AddPair(bad_tag_id, good_tag_id)

                for (bad_tag_id, good_tag_id
                     ) in statuses_to_pair_ids[HC.CONTENT_STATUS_PENDING]:

                    tss.AddPair(bad_tag_id, good_tag_id)

            self._ExecuteMany(
                'INSERT OR IGNORE INTO {} ( bad_tag_id, ideal_tag_id ) VALUES ( ?, ? );'
                .format(cache_tag_siblings_lookup_table_name),
                tss.GetBadTagsToIdealTags().items())

            if tag_service_id in self._service_ids_to_display_application_status:

                del self._service_ids_to_display_application_status[
                    tag_service_id]