def _GetCallToThread(self): for call_to_thread in self._call_to_threads: if not call_to_thread.CurrentlyWorking(): return call_to_thread if len(self._call_to_threads) > 100: raise Exception('Too many call to threads!') call_to_thread = HydrusThreading.THREADCallToThread(self) self._call_to_threads.append(call_to_thread) call_to_thread.start() return call_to_thread
def __init__(self): HC.DB_DIR = tempfile.mkdtemp() HC.CLIENT_ARCHIVES_DIR = os.path.join(HC.DB_DIR, 'client_archives') HC.CLIENT_FILES_DIR = os.path.join(HC.DB_DIR, 'client_files') HC.CLIENT_THUMBNAILS_DIR = os.path.join(HC.DB_DIR, 'client_thumbnails') HC.CLIENT_UPDATES_DIR = os.path.join(HC.DB_DIR, 'client_updates') HC.SERVER_FILES_DIR = os.path.join(HC.DB_DIR, 'server_files') HC.SERVER_THUMBNAILS_DIR = os.path.join(HC.DB_DIR, 'server_thumbnails') HC.SERVER_UPDATES_DIR = os.path.join(HC.DB_DIR, 'server_updates') os.makedirs(HC.CLIENT_FILES_DIR) HydrusGlobals.controller = self HydrusGlobals.client_controller = self HydrusGlobals.server_controller = self HydrusGlobals.test_controller = self self._pubsub = HydrusPubSub.HydrusPubSub(self) self._new_options = ClientData.ClientOptions() def show_text(text): pass HydrusData.ShowText = show_text self._call_to_threads = [ HydrusThreading.THREADCallToThread(self) for i in range(10) ] for thread in self._call_to_threads: thread.start() self._http = ClientNetworking.HTTPConnectionManager() self._reads = {} self._reads['hydrus_sessions'] = [] self._reads['local_booru_share_keys'] = [] self._reads['messaging_sessions'] = [] self._reads['tag_censorship'] = [] self._reads['options'] = ClientDefaults.GetClientDefaultOptions() services = [] services.append( ClientData.GenerateService(CC.LOCAL_BOORU_SERVICE_KEY, HC.LOCAL_BOORU, CC.LOCAL_BOORU_SERVICE_KEY, { 'max_monthly_data': None, 'used_monthly_data': 0 })) services.append( ClientData.GenerateService(CC.LOCAL_FILE_SERVICE_KEY, HC.LOCAL_FILE, CC.LOCAL_FILE_SERVICE_KEY, {})) services.append( ClientData.GenerateService(CC.LOCAL_TAG_SERVICE_KEY, HC.LOCAL_TAG, CC.LOCAL_TAG_SERVICE_KEY, {})) self._reads['services'] = services client_files_locations = { prefix: HC.CLIENT_FILES_DIR for prefix in HydrusData.IterateHexPrefixes() } self._reads['client_files_locations'] = client_files_locations self._reads['sessions'] = [] self._reads['tag_parents'] = {} self._reads['tag_siblings'] = {} self._reads['web_sessions'] = {} HC.options = ClientDefaults.GetClientDefaultOptions() self._writes = collections.defaultdict(list) self._managers = {} self._services_manager = ClientCaches.ServicesManager(self) self._client_files_manager = ClientCaches.ClientFilesManager(self) self._client_session_manager = ClientCaches.HydrusSessionManager(self) self._managers['tag_censorship'] = ClientCaches.TagCensorshipManager( self) self._managers['tag_siblings'] = ClientCaches.TagSiblingsManager(self) self._managers['tag_parents'] = ClientCaches.TagParentsManager(self) self._managers['undo'] = ClientCaches.UndoManager(self) self._managers['web_sessions'] = TestConstants.FakeWebSessionManager() self._server_session_manager = HydrusSessions.HydrusSessionManagerServer( ) self._managers['local_booru'] = ClientCaches.LocalBooruCache(self) self._cookies = {}