from twisted.internet import reactor except: HG.twisted_is_broke = True except Exception as e: import traceback import os try: from include import HydrusData HydrusData.DebugPrint( 'Critical boot error occurred! Details written to crash.log!') HydrusData.PrintException(e) except: pass error_trace = traceback.format_exc() print(error_trace) if 'db_dir' in locals() and os.path.exists(db_dir): emergency_dir = db_dir else:
# action = ServerController.ProcessStartingAction( db_dir, action ) with HydrusLogger.HydrusLogger( db_dir, 'server' ) as logger: try: if action in ( 'stop', 'restart' ): ServerController.ShutdownSiblingInstance( db_dir ) if action in ( 'start', 'restart' ): HydrusData.Print( u'Initialising controller\u2026' ) threading.Thread( target = reactor.run, kwargs = { 'installSignalHandlers' : 0 } ).start() controller = ServerController.Controller( db_dir, no_daemons, no_wal ) controller.Run() except HydrusExceptions.PermissionException as e: error = HydrusData.ToUnicode( e ) HydrusData.Print( error ) except:
win = QW.QWidget(None) win.setWindowTitle('Running tests...') controller = TestController.Controller(win, only_run) def do_it(): controller.Run(win) QP.CallAfter(do_it) app.exec_() except: HydrusData.DebugPrint(traceback.format_exc()) finally: HG.view_shutdown = True controller.pubimmediate('wake_daemons') HG.model_shutdown = True controller.pubimmediate('wake_daemons') controller.TidyUp() except:
def __init__( self ): self.db_dir = tempfile.mkdtemp() TestConstants.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.gui = self self._call_to_threads = [] self._pubsub = HydrusPubSub.HydrusPubSub( self ) self.new_options = ClientOptions.ClientOptions( self.db_dir ) HC.options = ClientDefaults.GetClientDefaultOptions() self.options = HC.options def show_text( text ): pass HydrusData.ShowText = show_text 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() self._reads[ 'file_system_predicates' ] = [] self._reads[ 'media_results' ] = [] self.example_tag_repo_service_key = HydrusData.GenerateKey() services = [] services.append( ClientServices.GenerateService( CC.LOCAL_BOORU_SERVICE_KEY, HC.LOCAL_BOORU, CC.LOCAL_BOORU_SERVICE_KEY ) ) services.append( ClientServices.GenerateService( CC.COMBINED_LOCAL_FILE_SERVICE_KEY, HC.COMBINED_LOCAL_FILE, CC.COMBINED_LOCAL_FILE_SERVICE_KEY ) ) services.append( ClientServices.GenerateService( CC.LOCAL_FILE_SERVICE_KEY, HC.LOCAL_FILE_DOMAIN, CC.LOCAL_FILE_SERVICE_KEY ) ) services.append( ClientServices.GenerateService( CC.TRASH_SERVICE_KEY, HC.LOCAL_FILE_TRASH_DOMAIN, CC.LOCAL_FILE_SERVICE_KEY ) ) services.append( ClientServices.GenerateService( CC.LOCAL_TAG_SERVICE_KEY, HC.LOCAL_TAG, CC.LOCAL_TAG_SERVICE_KEY ) ) 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, CC.COMBINED_TAG_SERVICE_KEY ) ) services.append( ClientServices.GenerateService( TestConstants.LOCAL_RATING_LIKE_SERVICE_KEY, HC.LOCAL_RATING_LIKE, 'example local rating like service' ) ) services.append( ClientServices.GenerateService( TestConstants.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', 'r' ): 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' ] = {} self._reads[ 'in_inbox' ] = False self._writes = collections.defaultdict( list ) self._managers = {} self.services_manager = ClientCaches.ServicesManager( self ) self.client_files_manager = ClientCaches.ClientFilesManager( self ) self.parsing_cache = ClientCaches.ParsingCache() bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager() session_manager = ClientNetworkingSessions.NetworkSessionManager() domain_manager = ClientNetworkingDomain.NetworkDomainManager() 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._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.server_session_manager = HydrusSessions.HydrusSessionManagerServer() self.local_booru_manager = ClientCaches.LocalBooruCache( self ) self._cookies = {} self._job_scheduler = HydrusThreading.JobScheduler( self ) self._job_scheduler.start()
sys.exit(1) controller = None with HydrusLogger.HydrusLogger(db_dir, 'server') as logger: try: if action in ('stop', 'restart'): ServerController.ShutdownSiblingInstance(db_dir) if action in ('start', 'restart'): HydrusData.Print('Initialising controller\u2026') threading.Thread(target=reactor.run, name='twisted', kwargs={ 'installSignalHandlers': 0 }).start() controller = ServerController.Controller(db_dir) controller.Run() except (HydrusExceptions.InsufficientCredentialsException, HydrusExceptions.ShutdownException) as e: error = str(e)
def AcquirePageKey( self ): return HydrusData.GenerateKey()
def __init__(self): self._db_dir = tempfile.mkdtemp() TestConstants.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) 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(self._db_dir) def show_text(text): pass HydrusData.ShowText = show_text self._http = ClientNetworking.HTTPConnectionManager() self._call_to_threads = [] 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( ClientServices.GenerateService(CC.LOCAL_BOORU_SERVICE_KEY, HC.LOCAL_BOORU, CC.LOCAL_BOORU_SERVICE_KEY)) services.append( ClientServices.GenerateService(CC.COMBINED_LOCAL_FILE_SERVICE_KEY, HC.COMBINED_LOCAL_FILE, CC.COMBINED_LOCAL_FILE_SERVICE_KEY)) services.append( ClientServices.GenerateService(CC.LOCAL_FILE_SERVICE_KEY, HC.LOCAL_FILE_DOMAIN, CC.LOCAL_FILE_SERVICE_KEY)) services.append( ClientServices.GenerateService(CC.TRASH_SERVICE_KEY, HC.LOCAL_FILE_TRASH_DOMAIN, CC.LOCAL_FILE_SERVICE_KEY)) services.append( ClientServices.GenerateService(CC.LOCAL_TAG_SERVICE_KEY, HC.LOCAL_TAG, CC.LOCAL_TAG_SERVICE_KEY)) self._reads['services'] = services client_files_locations = {} for prefix in HydrusData.IterateHexPrefixes(): for c in ('f', 't', 'r'): 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'] = {} 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 = {}
dest_path = os.path.join(db_dir, 'crash.log') with open(dest_path, 'w', encoding='utf-8') as f: f.write(error_trace) print('Critical boot error occurred! Details written to crash.log!') sys.exit(1) with HydrusLogger.HydrusLogger(db_dir, 'client') as logger: try: HydrusData.Print('hydrus client started') if not HG.twisted_is_broke: threading.Thread(target=reactor.run, name='twisted', kwargs={ 'installSignalHandlers': 0 }).start() controller = ClientController.Controller(db_dir) controller.Run() except:
import os import sys import time from include import ServerController import threading from twisted.internet import reactor from include import HydrusGlobals from include import HydrusLogger import traceback action = ServerController.GetStartingAction() if action == 'help': HydrusData.Print( 'This is the hydrus server. It accepts these commands:' ) HydrusData.Print( '' ) HydrusData.Print( 'server start - runs the server' ) HydrusData.Print( 'server stop - stops an existing instance of this server' ) HydrusData.Print( 'server restart - stops an existing instance of this server, then runs itself' ) HydrusData.Print( '' ) HydrusData.Print( 'You can also run \'server\' without arguments. Depending on what is going on, it will try to start or it will ask you if you want to stop or restart.' ) HydrusData.Print( 'You can also stop the running server just by hitting Ctrl+C.') else: with HydrusLogger.HydrusLogger( 'server.log' ) as logger: try: if action in ( 'stop', 'restart' ):
def __init__(self): HC.DB_DIR = tempfile.mkdtemp() 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_UPDATES_DIR = os.path.join(HC.DB_DIR, 'server_updates') client_files_default = os.path.join(HC.DB_DIR, 'client_files') os.makedirs(client_files_default) HydrusGlobals.is_first_start = True 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._http = ClientNetworking.HTTPConnectionManager() self._call_to_threads = [] 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 = {} for prefix in HydrusData.IterateHexPrefixes(): for c in ('f', 't', 'r'): 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'] = {} 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 = {}