It says that for duplicate information (i.e., equal file names), only
the one that comes first ought to be used. So we have to make sure to
load profiles in the correct order -- the ones that have the highest
priority last, because we just dict.update them all together. And in
script execution, we have to keep a list of file names already used in
scripts that have already been executed.
else:
env = os.environ.copy()
else:
env = os.environ.copy()
- for folder in chain((profile_path, os.path.dirname(profile_path)),
+ # If there are multiple candidates, the XDG spec tells to only use the first one.
+ ran_scripts = set()
+
+ user_profile_path = os.path.expanduser("~/.autorandr")
+ if not os.path.isdir(user_profile_path):
+ user_profile_path = os.path.join(os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "autorandr")
+
+ for folder in chain((profile_path, os.path.dirname(profile_path), user_profile_path),
(os.path.join(x, "autorandr") for x in os.environ.get("XDG_CONFIG_DIRS", "").split(":"))):
(os.path.join(x, "autorandr") for x in os.environ.get("XDG_CONFIG_DIRS", "").split(":"))):
- script = os.path.join(folder, script_name)
- if os.access(script, os.X_OK | os.F_OK):
- all_ok &= subprocess.call(script, env=env) != 0
+
+ if script_name not in ran_scripts:
+ script = os.path.join(folder, script_name)
+ if os.access(script, os.X_OK | os.F_OK):
+ all_ok &= subprocess.call(script, env=env) != 0
+ ran_scripts.add(script_name)
script_folder = os.path.join(folder, "%s.d" % script_name)
if os.access(script_folder, os.R_OK | os.X_OK) and os.path.isdir(script_folder):
for file_name in os.listdir(script_folder):
script_folder = os.path.join(folder, "%s.d" % script_name)
if os.access(script_folder, os.R_OK | os.X_OK) and os.path.isdir(script_folder):
for file_name in os.listdir(script_folder):
- script = os.path.join(script_folder, file_name)
- if os.access(script, os.X_OK | os.F_OK):
- all_ok &= subprocess.call(script, env=env) != 0
+ check_name = "d/%s" % (file_name,)
+ if check_name not in ran_scripts:
+ script = os.path.join(script_folder, file_name)
+ if os.access(script, os.X_OK | os.F_OK):
+ all_ok &= subprocess.call(script, env=env) != 0
+ ran_scripts.add(check_name)
profiles = {}
try:
# Load profiles from each XDG config directory
profiles = {}
try:
# Load profiles from each XDG config directory
- for directory in os.environ.get("XDG_CONFIG_DIRS", "").split(":"):
+ # The XDG spec says that earlier entries should take precedence, so reverse the order
+ for directory in reversed(os.environ.get("XDG_CONFIG_DIRS", "").split(":")):
system_profile_path = os.path.join(directory, "autorandr")
if os.path.isdir(system_profile_path):
profiles.update(load_profiles(system_profile_path))
system_profile_path = os.path.join(directory, "autorandr")
if os.path.isdir(system_profile_path):
profiles.update(load_profiles(system_profile_path))