Initialize Ubuntu OS examples
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import subprocess
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def is_spotify_installed() -> bool:
|
||||
# Use the 'which' command to check if the 'spotify' executable exists
|
||||
@@ -8,35 +9,39 @@ def is_spotify_installed() -> bool:
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def is_dim_screen_inactive_off():
|
||||
# Get the current value of "Dim screen when inactive" setting
|
||||
result = subprocess.run(["gsettings", "get", "org.gnome.desktop.session", "idle-delay"], capture_output=True, text=True)
|
||||
result = subprocess.run(["gsettings", "get", "org.gnome.desktop.session", "idle-delay"], capture_output=True,
|
||||
text=True)
|
||||
|
||||
# Check if the setting is set to "uint32 0"
|
||||
if result.stdout.strip() == "uint32 0":
|
||||
return 1 # Task successful
|
||||
else:
|
||||
return 0 # Task not successful
|
||||
|
||||
|
||||
|
||||
def evaluate_create_test_directory():
|
||||
try:
|
||||
# Specify the path to the directory
|
||||
path = '/test'
|
||||
|
||||
|
||||
# Check if the directory already exists
|
||||
if os.path.exists(path):
|
||||
return 0 # Directory already exists, task not successful
|
||||
|
||||
|
||||
# Check if the user has sufficient permissions to create the directory
|
||||
if not os.access("/", os.W_OK | os.X_OK):
|
||||
return 0 # Insufficient permissions to create the directory, task not successful
|
||||
|
||||
|
||||
return 1 # Task can be considered successful
|
||||
except Exception as e:
|
||||
print(f"Error: {str(e)}")
|
||||
return 0 # Any other errors, task not successful
|
||||
|
||||
|
||||
# TODO: create a file named test.txt and a directory dir1 at home dir before running this
|
||||
def is_file_in_directory():
|
||||
# Specify the paths of the file and directory
|
||||
@@ -48,7 +53,8 @@ def is_file_in_directory():
|
||||
return 1 # Task successful
|
||||
else:
|
||||
return 0 # Task not successful
|
||||
|
||||
|
||||
|
||||
# TODO: log in to the system before running this
|
||||
def is_logout_successful():
|
||||
try:
|
||||
@@ -57,6 +63,7 @@ def is_logout_successful():
|
||||
except subprocess.CalledProcessError:
|
||||
return 1 # Task successful
|
||||
|
||||
|
||||
def is_do_not_disturb_mode_enabled():
|
||||
try:
|
||||
subprocess.run(["gsettings", "set", "org.gnome.desktop.notifications", "show-banners", "false"], check=True)
|
||||
@@ -64,6 +71,7 @@ def is_do_not_disturb_mode_enabled():
|
||||
except subprocess.CalledProcessError:
|
||||
return 0 # Task not successful
|
||||
|
||||
|
||||
def get_default_browser(answer: str):
|
||||
try:
|
||||
result = subprocess.run(["xdg-settings", "get", "default-web-browser"], capture_output=True, text=True)
|
||||
@@ -72,11 +80,15 @@ def get_default_browser(answer: str):
|
||||
except subprocess.CalledProcessError:
|
||||
return 0
|
||||
|
||||
|
||||
# TODO: should confirm initial state, i.e. initial list of favorite apps & the first app
|
||||
first_app = "thunderbird.desktop" # to be changed
|
||||
first_app = "thunderbird.desktop" # to be changed
|
||||
|
||||
|
||||
def is_first_favorite_app_removed():
|
||||
try:
|
||||
result = subprocess.run(["gsettings", "get", "org.gnome.shell", "favorite-apps"], capture_output=True, text=True)
|
||||
result = subprocess.run(["gsettings", "get", "org.gnome.shell", "favorite-apps"], capture_output=True,
|
||||
text=True)
|
||||
output = result.stdout.strip()
|
||||
|
||||
# Remove brackets and spaces from the output
|
||||
@@ -90,4 +102,51 @@ def is_first_favorite_app_removed():
|
||||
else:
|
||||
return 0 # First favorite app not removed
|
||||
except subprocess.CalledProcessError:
|
||||
return 0 # Task not successful
|
||||
return 0 # Task not 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.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user