Updated sound fallback paths to include nonstandard installation paths.
This commit is contained in:
@@ -99,14 +99,59 @@ class SoundThemeManager:
|
|||||||
self._systemSoundsDir = None
|
self._systemSoundsDir = None
|
||||||
self._userSoundsDir = 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):
|
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:
|
if self._systemSoundsDir is None:
|
||||||
|
datadir = None
|
||||||
|
|
||||||
|
# First try the configured datadir from cthulhu_platform
|
||||||
try:
|
try:
|
||||||
from . import cthulhu_platform
|
from . import cthulhu_platform
|
||||||
datadir = getattr(cthulhu_platform, 'datadir', '/usr/share')
|
datadir = getattr(cthulhu_platform, 'datadir', None)
|
||||||
except ImportError:
|
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'
|
datadir = '/usr/share'
|
||||||
|
|
||||||
self._systemSoundsDir = os.path.join(datadir, 'cthulhu', 'sounds')
|
self._systemSoundsDir = os.path.join(datadir, 'cthulhu', 'sounds')
|
||||||
return self._systemSoundsDir
|
return self._systemSoundsDir
|
||||||
|
|
||||||
@@ -123,10 +168,20 @@ class SoundThemeManager:
|
|||||||
|
|
||||||
Returns list of theme names (folder names) from both system and user dirs.
|
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.
|
User themes with same name as system themes will override system themes.
|
||||||
|
Also checks standard fallback paths.
|
||||||
"""
|
"""
|
||||||
themes = set()
|
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):
|
if os.path.isdir(baseDir):
|
||||||
try:
|
try:
|
||||||
for entry in os.listdir(baseDir):
|
for entry in os.listdir(baseDir):
|
||||||
@@ -143,15 +198,30 @@ class SoundThemeManager:
|
|||||||
"""Get the path to a theme directory.
|
"""Get the path to a theme directory.
|
||||||
|
|
||||||
User themes take precedence over system themes.
|
User themes take precedence over system themes.
|
||||||
|
Checks multiple standard locations as fallbacks.
|
||||||
"""
|
"""
|
||||||
|
# Check user directory first
|
||||||
userPath = os.path.join(self.getUserSoundsDir(), themeName)
|
userPath = os.path.join(self.getUserSoundsDir(), themeName)
|
||||||
if os.path.isdir(userPath):
|
if os.path.isdir(userPath):
|
||||||
return userPath
|
return userPath
|
||||||
|
|
||||||
|
# Check the configured system directory
|
||||||
systemPath = os.path.join(self.getSystemSoundsDir(), themeName)
|
systemPath = os.path.join(self.getSystemSoundsDir(), themeName)
|
||||||
if os.path.isdir(systemPath):
|
if os.path.isdir(systemPath):
|
||||||
return 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
|
return None
|
||||||
|
|
||||||
def getSoundPath(self, themeName, soundName):
|
def getSoundPath(self, themeName, soundName):
|
||||||
|
|||||||
Reference in New Issue
Block a user