forked from Github/Axter-Stash
Added logic to trim DB files
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# FileMonitor: Ver 0.7.5 (By David Maisonave)
|
||||
# FileMonitor: Ver 0.7.7 (By David Maisonave)
|
||||
FileMonitor is a [Stash](https://github.com/stashapp/stash) plugin with the following two main features:
|
||||
- Updates Stash when any file changes occurs in the Stash library.
|
||||
- Runs scheduled task based on the scheduler configuration in filemonitor_config.py.
|
||||
|
||||
@@ -106,6 +106,16 @@ def isJobWaitingToRun():
|
||||
if plugin.CALLED_AS_STASH_PLUGIN:
|
||||
plugin.Trace(f"isJobWaitingToRun() = {isJobWaitingToRun()})")
|
||||
|
||||
def trimDbFiles(dbPath, maxFiles):
|
||||
if not os.path.exists(dbPath) or len(dbPath) < 5: # For safety and security, short path not supported.
|
||||
return
|
||||
dbFiles = sorted(os.listdir(dbPath))
|
||||
n = len(dbFiles)
|
||||
for i in range(0, n-maxFiles):
|
||||
dbFilePath = f"{dbPath}{os.sep}{dbFiles[i]}"
|
||||
plugin.Log(f"Removing file {dbFilePath}")
|
||||
os.remove(dbFilePath)
|
||||
|
||||
# Reoccurring scheduler code
|
||||
# ToDo: Change the following functions into a class called reoccurringScheduler
|
||||
def runTask(task):
|
||||
@@ -123,7 +133,11 @@ def runTask(task):
|
||||
elif task['task'] == "Generate":
|
||||
plugin.STASH_INTERFACE.metadata_generate()
|
||||
elif task['task'] == "Backup":
|
||||
plugin.STASH_INTERFACE.call_GQL("mutation { backupDatabase(input: {download: false})}")
|
||||
plugin.LogOnce("Note: Backup task does not get listed in the Task Queue, but user can verify that it started by looking in the Stash log file as an INFO level log line.")
|
||||
plugin.STASH_INTERFACE.backup_database()
|
||||
if plugin.pluginConfig['BackupsMax'] > 0 and plugin.pluginConfig['BackupDatabasePath'] != "" and os.path.exists(plugin.pluginConfig['BackupDatabasePath']):
|
||||
plugin.Log("Checking quantity of DB backups.")
|
||||
trimDbFiles(plugin.pluginConfig['BackupDatabasePath'], plugin.pluginConfig['BackupsMax'])
|
||||
elif task['task'] == "Scan":
|
||||
plugin.STASH_INTERFACE.metadata_scan(paths=stashPaths)
|
||||
elif task['task'] == "Auto Tag":
|
||||
@@ -281,9 +295,14 @@ def start_library_monitor():
|
||||
break
|
||||
if plugin.pluginSettings['turnOnScheduler']:
|
||||
checkSchedulePending()
|
||||
plugin.LogOnce("Wait start")
|
||||
plugin.LogOnce("Waiting for a file change-trigger.")
|
||||
signal.wait(timeout=SIGNAL_TIMEOUT)
|
||||
plugin.Trace("Wait end")
|
||||
if plugin.pluginSettings['turnOnScheduler'] and not shouldUpdate:
|
||||
plugin.Trace("Checking the scheduler.")
|
||||
elif shouldUpdate:
|
||||
plugin.Trace("File change trigger occurred.")
|
||||
else:
|
||||
plugin.Trace("Wait timeourt occurred.")
|
||||
shouldUpdate = False
|
||||
TmpTargetPaths = []
|
||||
for TargetPath in TargetPaths:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: FileMonitor
|
||||
description: Monitors the Stash library folders, and updates Stash if any changes occurs in the Stash library paths.
|
||||
version: 0.7.5
|
||||
version: 0.7.7
|
||||
url: https://github.com/David-Maisonave/Axter-Stash/tree/main/plugins/FileMonitor
|
||||
settings:
|
||||
recursiveDisabled:
|
||||
|
||||
@@ -8,8 +8,8 @@ config = {
|
||||
"onAnyEvent": False,
|
||||
# Enable to monitor changes in file system for modification flag. This option is NOT needed for Windows, because on Windows changes are triggered via CREATE, DELETE, and MOVE flags. Other OS may differ.
|
||||
"scanModified": False,
|
||||
# Timeout in seconds. This is how often it will check if another job (Task) is in the queue.
|
||||
"timeOut": 60, # Not needed when running in command line mode.
|
||||
# Timeout in seconds. This is how often it will check the scheduler and (in-plugin mode) if another job (Task) is in the queue
|
||||
"timeOut": 60,
|
||||
# Enable to exit FileMonitor by creating special file in plugin folder\working
|
||||
"createSpecFileToExit": True,
|
||||
# Enable to delete special file imediately after it's created in stop process
|
||||
@@ -40,7 +40,7 @@ config = {
|
||||
# 3 = 3rd specified weekday of the month.
|
||||
# 4 = 4th specified weekday of the month.
|
||||
# Example monthly method.
|
||||
{"task" : "Backup", "weekday" : "saturday", "time" : "02:30", "monthly" : 2}, # Backup -> [Backup] 2nd saturday of the month at 2:30AM
|
||||
{"task" : "Backup", "weekday" : "sunday", "time" : "01:00", "monthly" : 2}, # Backup -> [Backup] 2nd sunday of the month at 1AM (01:00)
|
||||
|
||||
# The following is a place holder for a plugin.
|
||||
{"task" : "PluginButtonName_Here", "pluginId" : "PluginId_Here", "hours" : 0}, # The zero frequency value makes this task disabled.
|
||||
@@ -48,7 +48,8 @@ config = {
|
||||
],
|
||||
|
||||
# Maximum backups to keep. When scheduler is enabled, and the Backup runs, delete older backups after reaching maximum backups.
|
||||
"BackupsMax" : 6, # Not yet implemented!!!
|
||||
"BackupsMax" : 12, # Only works if BackupDatabasePath is properly populated.
|
||||
"BackupDatabasePath" : "C:\\Users\\admin3\\.stash\\DbBackup", # ToDo: Implement code to automate fetching this value
|
||||
|
||||
# When enabled, if CREATE flag is triggered, DupFileManager task is called if the plugin is installed.
|
||||
"onCreateCallDupFileManager": False, # Not yet implemented!!!!
|
||||
|
||||
Reference in New Issue
Block a user