import subprocess def check_gnome_favorite_apps(apps_str: str, rule): # parse the string like "['thunderbird.desktop', 'vim.desktop', 'google-chrome.desktop']" # to a list of strings apps = eval(apps_str) expected_apps = rule["expected"] if len(apps) != len(expected_apps): return 0 if set(apps) == set(expected_apps): return 1 else: return 0 # TODO: log in to the system before running this def is_logout_successful(): try: subprocess.run(["whoami"]) return 0 # Task not successful except subprocess.CalledProcessError: return 1 # Task successful def is_battery_percentage_displayed(): # GNOME schema and key for the setting schema = "org.gnome.desktop.interface" key = "show-battery-percentage" try: # use gsettings to get the current setting result = subprocess.run(['gsettings', 'get', schema, key], capture_output=True, text=True) # examine the output is 'true' if result.stdout.strip() == 'true': return 1. else: return 0. except Exception as e: print(f"An error occurred: {e}") return 0. def check_auto_lock_settings(): # The schema and keys for the GNOME desktop lock settings schema = "org.gnome.desktop.screensaver" lock_enabled_key = "lock-enabled" lock_delay_key = "lock-delay" try: # Check if the screen lock is enabled lock_enabled = subprocess.run(['gsettings', 'get', schema, lock_enabled_key], capture_output=True, text=True) is_lock_enabled = lock_enabled.stdout.strip() == 'true' # Check the delay before the screen is locked lock_delay = subprocess.run(['gsettings', 'get', schema, lock_delay_key], capture_output=True, text=True) # Extract the numerical value from the output delay_seconds = lock_delay # Print the results if is_lock_enabled: return 1. else: return 0. except Exception as e: return 0.