diff --git a/test_oauth_config.py b/test_oauth_config.py index 5e00753..b77e8c6 100644 --- a/test_oauth_config.py +++ b/test_oauth_config.py @@ -13,14 +13,25 @@ def get_systemd_env_var(var_name): """Get environment variable from systemd service""" try: result = subprocess.run( - ['systemctl', 'show', 'pdf-renamer', '-p', f'Environment'], + ['systemctl', 'show', 'pdf-renamer', '-p', 'Environment'], capture_output=True, text=True, check=True ) - env_lines = result.stdout.strip().split('\n') - for line in env_lines: - if f'{var_name}=' in line: - # Extract the value after the equals sign - return line.split('=', 1)[1].strip('"') + env_line = result.stdout.strip() + if not env_line or '=' not in env_line: + return None + + # The Environment line contains: Environment=VAR1=value1 VAR2=value2 ... + # Extract everything after the first '=' + env_string = env_line.split('=', 1)[1] + + # Split by spaces to get individual VAR=value pairs + env_pairs = env_string.split() + + # Find the specific variable + for pair in env_pairs: + if pair.startswith(f'{var_name}='): + return pair.split('=', 1)[1] + return None except subprocess.CalledProcessError: return None