From 5c9d049dbaa4555d7ae8a6bf817dd3b1b98c17c2 Mon Sep 17 00:00:00 2001 From: Rebel Zhang Date: Sun, 28 Sep 2025 11:17:31 +0800 Subject: [PATCH] Partially completed the user daemon --- ressenger.py | 3 +++ ressenger_user.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ressenger.py b/ressenger.py index 5cf9537..4502abf 100755 --- a/ressenger.py +++ b/ressenger.py @@ -172,6 +172,9 @@ List of options: if profile.startswith("cache_"): message_box_1('Error', 'Invalid profile name.') exit() + if profile.startswith("lock_"): + message_box_1('Error', 'Invalid profile name.') + exit() user_path=pathlib.Path(f'~/.ressenger/{profile}').expanduser() if not user_path.exists(): diff --git a/ressenger_user.py b/ressenger_user.py index c64747f..8bbb416 100755 --- a/ressenger_user.py +++ b/ressenger_user.py @@ -1,3 +1,34 @@ #!/usr/bin/python3 -import ressenger_common +import sys, pathlib, subprocess, os +import ressenger_common, ressenger_exceptions, ressenger_cryptography +def run_in_background(pyfile, args=None, stdout=None, stderr=None): + args = args or [] + cmd = [sys.executable, pyfile] + args + + p = subprocess.Popen( + cmd, + stdout=stdout or subprocess.DEVNULL, + stderr=stderr or subprocess.DEVNULL, + start_new_session=True, + close_fds=True + ) + return p + +def initialise_user(username, password): + user_path=pathlib.Path(f'~/.ressenger/{username}').expanduser() + if not user_path.exists(): + raise ressenger_exceptions.UserDoesNotExistError(f'The user {username} does not exist.') + with open(user_path, 'rb') as file: + user=pickle.loads(ressenger_cryptography.decrypt_bytes(file.read(), password)) + run_in_background('ressenger_server.py', args=[user['port']]) + cache1_path = pathlib.Path(f"~/.ressenger/cache_{user['port']}").expanduser() + cache2_path = pathlib.Path(f"~/.ressenger/cache_{username}").expanduser() + cache1_lock_path = pathlib.Path(f"~/.ressenger/lock_cache_{user['port']}").expanduser() + cache2_lock_path = pathlib.Path(f"~/.ressenger/lock_cache_{username}").expanduser() + cache1_processed=[] + cache2_processed=[] + # TO DO + +if __name__=='__main__': + initialise_user(sys.argv[1], sys.argv[2])