"--cleanup-index" reformation

This commit is contained in:
Profitroll 2022-08-09 11:58:40 +02:00
parent e0ecf98443
commit 71d1efa82b
2 changed files with 10 additions and 2 deletions

View File

@ -34,6 +34,7 @@ To make this bot run at first you need to have a Python interpreter and git. Goo
Of course bot also has them. You can perform some actions with them. Of course bot also has them. You can perform some actions with them.
* `--move-sent` - allows you to move all sent files from queue to sent directories * `--move-sent` - allows you to move all sent files from queue to sent directories
* `--cleanup` - purge files in both `queue` and `sent` folders if they're sent. Requires `--confirm` argument * `--cleanup` - purge files in both `queue` and `sent` folders if they're sent. Requires `--confirm` argument
* `--cleanup-index` - purge all sent entries from index. Requires `--confirm` argument
* `--norun` - allows you to execute above arguments without tiggering the bot start itself * `--norun` - allows you to execute above arguments without tiggering the bot start itself
Examples: Examples:

11
main.py
View File

@ -36,8 +36,6 @@ if "--cleanup" in sys.argv:
os.remove(configGet("sent", "locations")+os.sep+entry) os.remove(configGet("sent", "locations")+os.sep+entry)
except FileNotFoundError: except FileNotFoundError:
pass pass
if "--cleanup-index" in sys.argv:
del index[entry]
except Exception as exp: except Exception as exp:
logWrite(f"Could not remove '{entry}' due to {exp}") logWrite(f"Could not remove '{entry}' due to {exp}")
jsonSave(index, jsonLoad(configGet("index", "locations"))) jsonSave(index, jsonLoad(configGet("index", "locations")))
@ -45,6 +43,15 @@ if "--cleanup" in sys.argv:
else: else:
logWrite(f"Requested cleanup of sent files but not authorized. Please pass '--confirm' to perform that") logWrite(f"Requested cleanup of sent files but not authorized. Please pass '--confirm' to perform that")
if "--cleanup-index" in sys.argv:
if "--confirm" in sys.argv:
index = jsonLoad(configGet("index", "locations"))
index["sent"] = []
jsonSave(index, jsonLoad(configGet("index", "locations")))
logWrite(f"Performed cleanup of sent files index")
else:
logWrite(f"Requested cleanup of sent files index but not authorized. Please pass '--confirm' to perform that")
if "--norun" in sys.argv: if "--norun" in sys.argv:
logWrite("Argument --norun passed, not running the main script") logWrite("Argument --norun passed, not running the main script")
sys.exit() sys.exit()