moving the list generation to a seperate method
[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
12 PATH_CREATE = 0
13 PATH_DONTCREATE = 1
14
15 defaultPaths = {
16                 SCOPE_TRANSPONDERDATA: ("/etc/", PATH_DONTCREATE),
17                 SCOPE_SYSETC: ("/etc/", PATH_DONTCREATE),
18                 SCOPE_FONTS: ("/usr/share/fonts/", PATH_DONTCREATE),
19                 SCOPE_CONFIG: ("/etc/enigma2/", PATH_CREATE),
20                                             
21                 SCOPE_LANGUAGE: ("/enigma2/po/", PATH_CREATE),
22
23                 SCOPE_SKIN: ("/usr/share/enigma2/", PATH_DONTCREATE),
24                 SCOPE_SKIN_IMAGE: ("/usr/share/enigma2/", PATH_DONTCREATE),
25                 
26                 SCOPE_USERETC: ("", PATH_DONTCREATE) # user home directory
27         }
28
29 def resolveFilename(scope, base):
30         # in future, we would check for file existence here,
31         # so we can provide default/fallbacks.
32         
33         path = defaultPaths[scope]
34         if path[1] == PATH_CREATE:
35                 if (not os.path.exists(path[0])):
36                         os.mkdir(path[0])
37         
38         # FIXME: we also have to handle DATADIR etc. here.
39         return path[0] + base
40
41         # this is only the BASE - an extension must be added later.
42 def getRecordingFilename(basename):
43         
44                 # filter out non-allowed characters
45         non_allowed_characters = "/.\\"
46         
47         filename = ""
48         for c in basename:
49                 if c in non_allowed_characters:
50                         c = "_"
51                 filename += c
52         
53         i = 0
54         while True:
55                 path = "/hdd/movies/" + filename
56                 if i > 0:
57                         path += "_%03d" % i
58                 try:
59                         open(path + ".ts")
60                         i += 1
61                 except IOError:
62                         return path