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