from os import path as os_path, mkdir, rmdir, system, walk, stat as os_stat, listdir, readlink, makedirs, error as os_error, symlink, access, F_OK, R_OK, W_OK
from stat import S_IMODE
from re import compile
+from enigma import eEnv
try:
from os import chmod
SCOPE_DEFAULTPARTITION = 14
SCOPE_DEFAULTPARTITIONMOUNTDIR = 15
SCOPE_METADIR = 16
+SCOPE_CURRENT_PLUGIN = 17
PATH_CREATE = 0
PATH_DONTCREATE = 1
PATH_FALLBACK = 2
defaultPaths = {
- SCOPE_TRANSPONDERDATA: ("/etc/", PATH_DONTCREATE),
- SCOPE_SYSETC: ("/etc/", PATH_DONTCREATE),
- SCOPE_FONTS: ("/usr/share/fonts/", PATH_DONTCREATE),
- SCOPE_CONFIG: ("/etc/enigma2/", PATH_CREATE),
- SCOPE_PLUGINS: ("/usr/lib/enigma2/python/Plugins/", PATH_CREATE),
+ SCOPE_TRANSPONDERDATA: (eEnv.resolve("${sysconfdir}/"), PATH_DONTCREATE),
+ SCOPE_SYSETC: (eEnv.resolve("${sysconfdir}/"), PATH_DONTCREATE),
+ SCOPE_FONTS: (eEnv.resolve("${datadir}/fonts/"), PATH_DONTCREATE),
+ SCOPE_CONFIG: (eEnv.resolve("${sysconfdir}/enigma2/"), PATH_CREATE),
+ SCOPE_PLUGINS: (eEnv.resolve("${libdir}/enigma2/python/Plugins/"), PATH_CREATE),
- SCOPE_LANGUAGE: ("/usr/share/enigma2/po/", PATH_DONTCREATE),
+ SCOPE_LANGUAGE: (eEnv.resolve("${datadir}/enigma2/po/"), PATH_DONTCREATE),
- SCOPE_SKIN: ("/usr/share/enigma2/", PATH_DONTCREATE),
- SCOPE_SKIN_IMAGE: ("/usr/share/enigma2/", PATH_DONTCREATE),
+ SCOPE_SKIN: (eEnv.resolve("${datadir}/enigma2/"), PATH_DONTCREATE),
+ SCOPE_SKIN_IMAGE: (eEnv.resolve("${datadir}/enigma2/"), PATH_DONTCREATE),
SCOPE_HDD: ("/hdd/movie/", PATH_DONTCREATE),
SCOPE_MEDIA: ("/media/", PATH_DONTCREATE),
- SCOPE_PLAYLIST: ("/etc/enigma2/playlist/", PATH_CREATE),
+ SCOPE_PLAYLIST: (eEnv.resolve("${sysconfdir}/enigma2/playlist/"), PATH_CREATE),
SCOPE_USERETC: ("", PATH_DONTCREATE), # user home directory
- SCOPE_DEFAULTDIR: ("/usr/share/enigma2/defaults/", PATH_CREATE),
- SCOPE_DEFAULTPARTITION: ("/dev/mtdblock/6", PATH_DONTCREATE),
- SCOPE_DEFAULTPARTITIONMOUNTDIR: ("/usr/share/enigma2/dealer", PATH_CREATE),
- SCOPE_METADIR: ("/usr/lib/enigma2/python/Plugins/meta", PATH_CREATE),
+ SCOPE_DEFAULTDIR: (eEnv.resolve("${datadir}/enigma2/defaults/"), PATH_CREATE),
+ SCOPE_DEFAULTPARTITION: ("/dev/mtdblock6", PATH_DONTCREATE),
+ SCOPE_DEFAULTPARTITIONMOUNTDIR: (eEnv.resolve("${datadir}/enigma2/dealer"), PATH_CREATE),
+ SCOPE_METADIR: (eEnv.resolve("${datadir}/meta"), PATH_CREATE),
}
FILE_COPY = 0 # copy files from fallback dir to the basedir
PATH_MOVE = 3 # move the fallback dir to the basedir (can be used for changes in paths)
fallbackPaths = {
SCOPE_CONFIG: [("/home/root/", FILE_MOVE),
- ("/usr/share/enigma2/defaults/", FILE_COPY)],
+ (eEnv.resolve("${datadir}/enigma2/defaults/"), FILE_COPY)],
SCOPE_HDD: [("/hdd/movies", PATH_MOVE)]
}
tmp = defaultPaths[SCOPE_SKIN]
pos = config.skin.primary_skin.value.rfind('/')
if pos != -1:
- path = tmp[0]+config.skin.primary_skin.value[:pos+1]
+ #if basefile is not available use default skin path as fallback
+ tmpfile = tmp[0]+config.skin.primary_skin.value[:pos+1] + base
+ if fileExists(tmpfile):
+ path = tmp[0]+config.skin.primary_skin.value[:pos+1]
+ else:
+ path = tmp[0]
+ else:
+ path = tmp[0]
+
+ elif scope == SCOPE_CURRENT_PLUGIN:
+ tmp = defaultPaths[SCOPE_PLUGINS]
+ from Components.config import config
+ skintmp = defaultPaths[SCOPE_SKIN]
+ pos = config.skin.primary_skin.value.rfind('/')
+ if pos != -1:
+ #if basefile is not available inside current skin path, use the original provided file as fallback
+ skintmpfile = skintmp[0]+config.skin.primary_skin.value[:pos+1] + base
+ if fileExists(skintmpfile):
+ path = skintmp[0]+config.skin.primary_skin.value[:pos+1]
+ else:
+ path = tmp[0]
else:
path = tmp[0]
else:
if dirname is not None:
filename = ''.join((dirname, filename))
+ while len(filename) > 240:
+ filename = filename.decode('UTF-8')
+ filename = filename[:-1]
+ filename = filename.encode('UTF-8')
+
i = 0
while True:
path = resolveFilename(SCOPE_HDD, filename)
utime(dst, (st.st_atime, st.st_mtime))
except:
print "copy stats for", src, "failed!"
+
+def getSize(path, pattern=".*"):
+ path_size = 0
+ if os_path.isdir(path):
+ files = crawlDirectory(path, pattern)
+ for file in files:
+ filepath = os_path.join(file[0], file[1])
+ path_size += os_path.getsize(filepath)
+ elif os_path.isfile(path):
+ path_size = os_path.getsize(path)
+ return path_size