hydrus/include/ClientDaemons.py

169 lines
5.1 KiB
Python
Raw Normal View History

2019-01-09 22:59:03 +00:00
from . import ClientImporting
from . import ClientImportOptions
from . import ClientImportFileSeeds
from . import ClientPaths
from . import ClientThreading
from . import HydrusConstants as HC
from . import HydrusData
from . import HydrusExceptions
from . import HydrusGlobals as HG
from . import HydrusNATPunch
from . import HydrusPaths
from . import HydrusSerialisable
from . import HydrusThreading
from . import ClientConstants as CC
2015-03-04 22:44:32 +00:00
import random
2018-04-11 22:30:40 +00:00
import threading
2015-03-04 22:44:32 +00:00
import time
2019-02-13 22:26:43 +00:00
def DAEMONCheckExportFolders():
controller = HG.client_controller
2015-03-04 22:44:32 +00:00
2017-12-06 22:06:56 +00:00
if not controller.options[ 'pause_export_folders_sync' ]:
2015-03-04 22:44:32 +00:00
2018-03-14 21:01:02 +00:00
HG.export_folders_running = True
2015-03-04 22:44:32 +00:00
2018-03-14 21:01:02 +00:00
try:
export_folder_names = controller.Read( 'serialisable_names', HydrusSerialisable.SERIALISABLE_TYPE_EXPORT_FOLDER )
2015-03-04 22:44:32 +00:00
2018-03-14 21:01:02 +00:00
for name in export_folder_names:
export_folder = controller.Read( 'serialisable_named', HydrusSerialisable.SERIALISABLE_TYPE_EXPORT_FOLDER, name )
2015-10-21 21:53:10 +00:00
2018-03-14 21:01:02 +00:00
if controller.options[ 'pause_export_folders_sync' ] or HydrusThreading.IsThreadShuttingDown():
break
2015-10-21 21:53:10 +00:00
2018-03-14 21:01:02 +00:00
export_folder.DoWork()
finally:
2015-10-21 21:53:10 +00:00
2018-03-14 21:01:02 +00:00
HG.export_folders_running = False
2015-03-04 22:44:32 +00:00
2019-02-13 22:26:43 +00:00
def DAEMONCheckImportFolders():
controller = HG.client_controller
2015-03-04 22:44:32 +00:00
2017-12-06 22:06:56 +00:00
if not controller.options[ 'pause_import_folders_sync' ]:
2015-03-04 22:44:32 +00:00
2018-02-07 23:40:33 +00:00
HG.import_folders_running = True
try:
2015-03-04 22:44:32 +00:00
2018-03-14 21:01:02 +00:00
import_folder_names = controller.Read( 'serialisable_names', HydrusSerialisable.SERIALISABLE_TYPE_IMPORT_FOLDER )
2018-02-07 23:40:33 +00:00
for name in import_folder_names:
2015-10-21 21:53:10 +00:00
2018-02-07 23:40:33 +00:00
import_folder = controller.Read( 'serialisable_named', HydrusSerialisable.SERIALISABLE_TYPE_IMPORT_FOLDER, name )
2015-10-21 21:53:10 +00:00
2018-02-14 21:47:18 +00:00
if controller.options[ 'pause_import_folders_sync' ] or HydrusThreading.IsThreadShuttingDown():
2018-02-07 23:40:33 +00:00
break
import_folder.DoWork()
finally:
2015-10-21 21:53:10 +00:00
2018-02-07 23:40:33 +00:00
HG.import_folders_running = False
2015-03-04 22:44:32 +00:00
2015-11-04 22:30:28 +00:00
def DAEMONMaintainTrash( controller ):
2015-07-15 20:28:26 +00:00
2015-08-12 20:35:24 +00:00
if HC.options[ 'trash_max_size' ] is not None:
max_size = HC.options[ 'trash_max_size' ] * 1048576
2015-07-15 20:28:26 +00:00
2015-11-04 22:30:28 +00:00
service_info = controller.Read( 'service_info', CC.TRASH_SERVICE_KEY )
2015-07-15 20:28:26 +00:00
while service_info[ HC.SERVICE_INFO_TOTAL_SIZE ] > max_size:
2015-09-16 18:11:00 +00:00
if HydrusThreading.IsThreadShuttingDown():
2015-07-15 20:28:26 +00:00
return
2016-06-01 20:04:15 +00:00
hashes = controller.Read( 'trash_hashes', limit = 10 )
2015-07-15 20:28:26 +00:00
if len( hashes ) == 0:
return
2015-10-14 21:02:25 +00:00
content_update = HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_DELETE, hashes )
2015-07-15 20:28:26 +00:00
service_keys_to_content_updates = { CC.TRASH_SERVICE_KEY : [ content_update ] }
2015-11-04 22:30:28 +00:00
controller.WriteSynchronous( 'content_updates', service_keys_to_content_updates )
2015-07-15 20:28:26 +00:00
2015-11-04 22:30:28 +00:00
service_info = controller.Read( 'service_info', CC.TRASH_SERVICE_KEY )
2015-07-15 20:28:26 +00:00
2017-08-02 21:32:54 +00:00
time.sleep( 2 )
2015-07-15 20:28:26 +00:00
2015-08-12 20:35:24 +00:00
if HC.options[ 'trash_max_age' ] is not None:
max_age = HC.options[ 'trash_max_age' ] * 3600
2015-07-15 20:28:26 +00:00
2016-06-01 20:04:15 +00:00
hashes = controller.Read( 'trash_hashes', limit = 10, minimum_age = max_age )
2015-07-15 20:28:26 +00:00
while len( hashes ) > 0:
2015-09-16 18:11:00 +00:00
if HydrusThreading.IsThreadShuttingDown():
2015-07-15 20:28:26 +00:00
return
2015-10-14 21:02:25 +00:00
content_update = HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_DELETE, hashes )
2015-07-15 20:28:26 +00:00
service_keys_to_content_updates = { CC.TRASH_SERVICE_KEY : [ content_update ] }
2015-11-04 22:30:28 +00:00
controller.WriteSynchronous( 'content_updates', service_keys_to_content_updates )
2015-07-15 20:28:26 +00:00
2016-06-01 20:04:15 +00:00
hashes = controller.Read( 'trash_hashes', limit = 10, minimum_age = max_age )
2015-07-15 20:28:26 +00:00
2017-08-02 21:32:54 +00:00
time.sleep( 2 )
2015-07-15 20:28:26 +00:00
2015-11-04 22:30:28 +00:00
def DAEMONSynchroniseRepositories( controller ):
2015-03-04 22:44:32 +00:00
2017-12-06 22:06:56 +00:00
if not controller.options[ 'pause_repo_sync' ]:
2015-03-04 22:44:32 +00:00
2017-06-28 20:23:21 +00:00
services = controller.services_manager.GetServices( HC.REPOSITORIES )
2015-07-15 20:28:26 +00:00
2015-03-04 22:44:32 +00:00
for service in services:
2017-11-29 21:48:23 +00:00
if HydrusThreading.IsThreadShuttingDown():
return
2017-12-06 22:06:56 +00:00
if controller.options[ 'pause_repo_sync' ]:
2015-10-07 21:56:22 +00:00
2017-11-08 22:07:12 +00:00
return
2015-10-07 21:56:22 +00:00
2019-09-25 21:34:18 +00:00
service.SyncRemote()
service.SyncProcessUpdates( maintenance_mode = HC.MAINTENANCE_IDLE )
2015-03-04 22:44:32 +00:00
2017-11-29 21:48:23 +00:00
if HydrusThreading.IsThreadShuttingDown():
return
2019-12-11 23:18:37 +00:00
time.sleep( 1 )
2017-11-29 21:48:23 +00:00
2015-03-04 22:44:32 +00:00