From afdd812f2f439d61746aae43225f1816d0996374 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 1 Jan 2026 03:40:39 -0500 Subject: [PATCH] Updated sound fallback paths to include nonstandard installation paths. --- src/cthulhu/sound_theme_manager.py | 76 ++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/src/cthulhu/sound_theme_manager.py b/src/cthulhu/sound_theme_manager.py index 0759cc1..912f0f5 100644 --- a/src/cthulhu/sound_theme_manager.py +++ b/src/cthulhu/sound_theme_manager.py @@ -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):