1 # -*- coding: utf-8 -*-
2 from os import path as os_path, mkdir, system
4 SCOPE_TRANSPONDERDATA = 0
21 SCOPE_TRANSPONDERDATA: ("/etc/", PATH_DONTCREATE),
22 SCOPE_SYSETC: ("/etc/", PATH_DONTCREATE),
23 SCOPE_FONTS: ("/usr/share/fonts/", PATH_DONTCREATE),
24 SCOPE_CONFIG: ("/etc/enigma2/", PATH_CREATE),
25 SCOPE_PLUGINS: ("/usr/lib/enigma2/python/Plugins/", PATH_CREATE),
27 SCOPE_LANGUAGE: ("/usr/share/enigma2/po/", PATH_DONTCREATE),
29 SCOPE_SKIN: ("/usr/share/enigma2/", PATH_DONTCREATE),
30 SCOPE_SKIN_IMAGE: ("/usr/share/enigma2/", PATH_DONTCREATE),
31 SCOPE_HDD: ("/hdd/movie/", PATH_DONTCREATE),
32 SCOPE_MEDIA: ("/media/", PATH_DONTCREATE),
33 SCOPE_PLAYLIST: ("/etc/enigma2/playlist/", PATH_CREATE),
35 SCOPE_USERETC: ("", PATH_DONTCREATE) # user home directory
38 FILE_COPY = 0 # copy files from fallback dir to the basedir
39 FILE_MOVE = 1 # move files
40 PATH_COPY = 2 # copy the complete fallback dir to the basedir
41 PATH_MOVE = 3 # move the fallback dir to the basedir (can be used for changes in paths)
43 SCOPE_CONFIG: [("/home/root/", FILE_MOVE),
44 ("/usr/share/enigma2/defaults/", FILE_COPY)],
45 SCOPE_HDD: [("/hdd/movies", PATH_MOVE)]
48 def resolveFilename(scope, base = "", path_prefix = None):
50 # you can only use the ~/ if we have a prefix directory
51 assert path_prefix is not None
52 base = os_path.join(path_prefix, base[2:])
54 # don't resolve absolute paths
58 path = defaultPaths[scope]
60 if path[1] == PATH_CREATE:
61 if (not pathExists(defaultPaths[scope][0])):
64 #if len(base) > 0 and base[0] == '/':
67 if not fileExists(path[0] + base):
69 if fallbackPaths.has_key(scope):
70 for x in fallbackPaths[scope]:
72 if fileExists(x[0] + base):
73 system("cp " + x[0] + base + " " + path[0] + base)
75 elif x[1] == FILE_MOVE:
76 if fileExists(x[0] + base):
77 system("mv " + x[0] + base + " " + path[0] + base)
79 elif x[1] == PATH_COPY:
81 if not pathExists(defaultPaths[scope][0]):
83 system("cp -a " + x[0] + "* " + path[0])
85 elif x[1] == PATH_MOVE:
87 system("mv " + x[0] + " " + path[0])
91 # FIXME: we also have to handle DATADIR etc. here.
94 # this is only the BASE - an extension must be added later.
97 return os_path.exists(path)
108 def fileExists(f, mode='r'):
117 def getRecordingFilename(basename, dirname = None):
118 # filter out non-allowed characters
119 non_allowed_characters = "/.\\:*?<>|\""
122 basename = basename.replace('\xc2\x86', '').replace('\xc2\x87', '')
125 if c in non_allowed_characters:
129 if dirname is not None:
130 filename = ''.join([dirname, filename])
134 path = resolveFilename(SCOPE_HDD, filename)
143 # this is clearly a hack:
144 def InitFallbackFiles():
145 resolveFilename(SCOPE_CONFIG, "userbouquet.favourites.tv")
146 resolveFilename(SCOPE_CONFIG, "bouquets.tv")
147 resolveFilename(SCOPE_CONFIG, "userbouquet.favourites.radio")
148 resolveFilename(SCOPE_CONFIG, "bouquets.radio")