Commit 373857fb authored by Benjamin REED's avatar Benjamin REED

added saving to diff file

parent 6d7da466
......@@ -28,7 +28,7 @@ USAGES = {
"echo": "echo <string content> ( 'string_content' = any text to be echoed )",
"dbg": "dbg ( Prints a debug output of the manager's state )",
"list": "list [ <label> <password> ](Prints the passwords currently stored 'label' = the password you want to decrypt)",
"save": "save - Saves the state to the file originally inputted.", # TODO: make it possible to save to a new file
"save": "save <filename> - Saves the state to the file originally inputted or the file provided.",
"drop": "drop <label> - deletes the selected label from the list of passwords. This can be undone with the 'undo' command, however if 'drop' is used on an already deleted password, the password is removed forever from the database.",
"undo": "undo - undoes the latest deletion/modification",
"history": "history - prints all the deleted passwords",
......@@ -306,7 +306,9 @@ class State:
'<p.label>,<p.encrypted_password>' <-- same format as caesar, just in a different section
<end>
"""
def save(self):
def save(self, filepath = None):
if filepath is None:
filepath = self.filepath
content = self.head + "\n"
content += f"{self.rsa_key}" + "\n"
for l, p in self.passwords.items():
......@@ -324,7 +326,7 @@ class State:
content += f"rm({l}),{p.encrypt()}\n"
else:
content += f"{l},{p.encrypt()}\n"
file = open(self.filepath, 'w')
file = open(filepath, 'w')
file.write(content)
file.close()
......@@ -461,9 +463,12 @@ def main():
elif command == "dbg":
print(vars(state))
elif command == "save" or command == "s":
file = None
if len(args) > 1:
file = args[1]
try:
state.save()
print(f"State saved to {filepath}!")
state.save(file)
print(f"State saved to {file if file is not None else state.filepath}!")
except:
print("There was an error saving, maybe back up your stuff now. Sorry")
elif command == "drop" or command == "delete" or command == "del" or command == "rm":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment