Updated sound fallback paths to include nonstandard installation paths.

This commit is contained in:
Storm Dragon
2026-01-01 03:40:39 -05:00
parent e2cbcb0ac4
commit afdd812f2f

View File

@@ -99,14 +99,59 @@ class SoundThemeManager:
self._systemSoundsDir = None
self._userSoundsDir = None
def _deriveDatadirFromModulePath(self):
"""Derive the datadir from where this module is actually installed.
If module is at /usr/local/lib/python3.x/site-packages/cthulhu/,
then datadir should be /usr/local/share.
"""
try:
modulePath = os.path.dirname(os.path.abspath(__file__))
# Walk up looking for lib/python* pattern
currentPath = modulePath
for _ in range(10): # Limit iterations to avoid infinite loop
parent = os.path.dirname(currentPath)
if parent == currentPath:
break
dirName = os.path.basename(currentPath)
# Check if we're in a lib directory
if dirName == 'lib' or dirName.startswith('lib64'):
# Parent of lib is the prefix
prefix = parent
datadir = os.path.join(prefix, 'share')
if os.path.isdir(datadir):
return datadir
currentPath = parent
except Exception:
pass
return None
def getSystemSoundsDir(self):
"""Get system sounds directory from platform settings."""
"""Get system sounds directory from platform settings.
First tries cthulhu_platform.datadir, then derives from module location.
"""
if self._systemSoundsDir is None:
datadir = None
# First try the configured datadir from cthulhu_platform
try:
from . import cthulhu_platform
datadir = getattr(cthulhu_platform, 'datadir', '/usr/share')
datadir = getattr(cthulhu_platform, 'datadir', None)
except ImportError:
pass
# If datadir points to user home, it's likely wrong - try to derive it
if datadir and (datadir.startswith(os.path.expanduser('~')) or
'/home/' in datadir):
derivedDatadir = self._deriveDatadirFromModulePath()
if derivedDatadir:
datadir = derivedDatadir
# Fallback to /usr/share if nothing else works
if not datadir:
datadir = '/usr/share'
self._systemSoundsDir = os.path.join(datadir, 'cthulhu', 'sounds')
return self._systemSoundsDir
@@ -123,10 +168,20 @@ class SoundThemeManager:
Returns list of theme names (folder names) from both system and user dirs.
User themes with same name as system themes will override system themes.
Also checks standard fallback paths.
"""
themes = set()
for baseDir in [self.getSystemSoundsDir(), self.getUserSoundsDir()]:
# Check configured paths plus standard fallback locations
# /usr/share is standard, /usr/local/share is non-standard
searchDirs = [
self.getUserSoundsDir(),
self.getSystemSoundsDir(),
'/usr/share/cthulhu/sounds',
'/usr/local/share/cthulhu/sounds',
]
for baseDir in searchDirs:
if os.path.isdir(baseDir):
try:
for entry in os.listdir(baseDir):
@@ -143,15 +198,30 @@ class SoundThemeManager:
"""Get the path to a theme directory.
User themes take precedence over system themes.
Checks multiple standard locations as fallbacks.
"""
# Check user directory first
userPath = os.path.join(self.getUserSoundsDir(), themeName)
if os.path.isdir(userPath):
return userPath
# Check the configured system directory
systemPath = os.path.join(self.getSystemSoundsDir(), themeName)
if os.path.isdir(systemPath):
return systemPath
# Fallback: check standard system paths in case cthulhu_platform.datadir
# doesn't match where sounds are actually installed
# Check /usr/share first (standard), then /usr/local/share (non-standard)
fallbackPaths = [
'/usr/share/cthulhu/sounds',
'/usr/local/share/cthulhu/sounds',
]
for fallbackDir in fallbackPaths:
fallbackPath = os.path.join(fallbackDir, themeName)
if os.path.isdir(fallbackPath):
return fallbackPath
return None
def getSoundPath(self, themeName, soundName):