the new hdd movie directory is /hdd/movie (for 7020 compatibility reasons)
[enigma2.git] / lib / python / Tools / Directories.py
1 import os
2
3 SCOPE_TRANSPONDERDATA = 0
4 SCOPE_SYSETC = 1
5 SCOPE_FONTS = 2
6 SCOPE_SKIN = 3
7 SCOPE_SKIN_IMAGE = 4
8 SCOPE_USERETC = 5
9 SCOPE_CONFIG = 6
10 SCOPE_LANGUAGE = 7
11 SCOPE_HDD = 8
12
13 PATH_CREATE = 0
14 PATH_DONTCREATE = 1
15
16 defaultPaths = {
17                 SCOPE_TRANSPONDERDATA: ("/etc/", PATH_DONTCREATE),
18                 SCOPE_SYSETC: ("/etc/", PATH_DONTCREATE),
19                 SCOPE_FONTS: ("/usr/share/fonts/", PATH_DONTCREATE),
20                 SCOPE_CONFIG: ("/etc/enigma2/", PATH_CREATE),
21                                             
22                 SCOPE_LANGUAGE: ("/usr/share/enigma2/po/", PATH_CREATE),
23
24                 SCOPE_SKIN: ("/usr/share/enigma2/", PATH_DONTCREATE),
25                 SCOPE_SKIN_IMAGE: ("/usr/share/enigma2/", PATH_DONTCREATE),
26                 SCOPE_HDD: ("/hdd/movie/", PATH_DONTCREATE),
27                 
28                 SCOPE_USERETC: ("", PATH_DONTCREATE) # user home directory
29         }
30
31 def resolveFilename(scope, base = ""):
32         # in future, we would check for file existence here,
33         # so we can provide default/fallbacks.
34         
35         path = defaultPaths[scope]
36         if path[1] == PATH_CREATE:
37                 if (not pathExists(scope)):
38                         os.mkdir(path[0])
39         
40         # FIXME: we also have to handle DATADIR etc. here.
41         return path[0] + base
42
43         # this is only the BASE - an extension must be added later.
44         
45 def pathExists(scope):
46         return os.path.exists(defaultPaths[scope][0])
47
48 def getRecordingFilename(basename):
49         
50                 # filter out non-allowed characters
51         non_allowed_characters = "/.\\"
52         
53         filename = ""
54         for c in basename:
55                 if c in non_allowed_characters:
56                         c = "_"
57                 filename += c
58         
59         i = 0
60         while True:
61                 path = resolveFilename(SCOPE_HDD, filename)
62                 if i > 0:
63                         path += "_%03d" % i
64                 try:
65                         open(path + ".ts")
66                         i += 1
67                 except IOError:
68                         return path
69                 
70 # this fixes paths or files when changed in a new enigma2 version
71 def fixOldDirectoryEntries():
72         if (os.path.exists("/hdd/movies")):
73                 if (not os.path.exists(resolveFilename(SCOPE_HDD))):
74                         os.system("mv /hdd/movies " + resolveFilename(SCOPE_HDD))