Partially completed the user daemon

main
Rebel Zhang 2025-09-28 11:17:31 +08:00
parent ee12742fc0
commit 5c9d049dba
2 changed files with 35 additions and 1 deletions

View File

@ -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():

View File

@ -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])