make use of fallback files in Tools.Directories when file or path is not in place
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Sun, 1 Jan 2006 17:30:43 +0000 (17:30 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Sun, 1 Jan 2006 17:30:43 +0000 (17:30 +0000)
bouquets.tv [deleted file]
configure.ac
data/Makefile.am
data/defaults/Makefile.am [new file with mode: 0644]
data/defaults/bouquets.tv [new file with mode: 0644]
data/defaults/userbouquet.favourites.tv [new file with mode: 0644]
lib/python/Tools/Directories.py
mytest.py
userbouquet.favourites.tv [deleted file]

diff --git a/bouquets.tv b/bouquets.tv
deleted file mode 100644 (file)
index e69de29..0000000
index 1077c1f..7c4c2cd 100644 (file)
@@ -45,6 +45,7 @@ Makefile
 data/Makefile
 data/fonts/Makefile
 data/countries/Makefile
+data/defaults/Makefile
 lib/Makefile
 lib/actions/Makefile
 lib/base/Makefile
index 8b077b3..5dd9da7 100644 (file)
@@ -1,6 +1,6 @@
 AUTOMAKE_OPTIONS = gnu
 
-SUBDIRS = countries fonts
+SUBDIRS = countries fonts defaults
 
 installdir = $(DATADIR)/enigma2
 
diff --git a/data/defaults/Makefile.am b/data/defaults/Makefile.am
new file mode 100644 (file)
index 0000000..1dbbb96
--- /dev/null
@@ -0,0 +1,6 @@
+AUTOMAKE_OPTIONS = gnu
+
+installdir = $(DATADIR)/enigma2/defaults
+
+install_DATA = \
+       userbouquet.favourites.tv bouquets.tv
diff --git a/data/defaults/bouquets.tv b/data/defaults/bouquets.tv
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/data/defaults/userbouquet.favourites.tv b/data/defaults/userbouquet.favourites.tv
new file mode 100644 (file)
index 0000000..7abdaee
--- /dev/null
@@ -0,0 +1,88 @@
+#NAME Favourites (TV)\r
+#SERVICE 1:0:1:6DCA:44D:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6D66:437:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6DCC:44D:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:2EE3:441:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:2E:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:2EF4:441:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:382:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:383:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:33:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:2F08:441:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:2F1C:441:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6DCD:44D:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:701:5:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:6D67:437:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E29:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E2A:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E2B:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6DCB:44D:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E2C:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E2D:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E41:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6DCF:44D:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6DD0:44D:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6DD2:44D:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:2F80:454:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:2F:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:2F3A:441:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6D6F:437:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:4289:446:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:7004:436:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:7005:436:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:31D8:45C:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:384:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:6D69:437:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6D68:437:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6D6E:437:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6D6B:437:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6D70:437:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:313A:459:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:293:5:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:3138:459:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:3146:459:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6F45:445:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:307:7:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:202:7:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:300:7:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:2FF:7:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:292:7:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:3139:459:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:2F30:441:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:28:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:2F44:454:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:296:5:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:301:7:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:36:7:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:41:5:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:314B:459:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:F228:421:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:F1CC:421:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:295:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:381:21:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:2F3F:441:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:3E:5:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:3C:5:85:C00000:0:0:0:\r
+#SERVICE 1:0:1:3D:5:85:C00000:0:0:0:\r
+#SERVICE 1:0:11:526D:440:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6F46:445:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6DD1:44D:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E47:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E46:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E45:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E44:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E91:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E95:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E96:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E94:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E93:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E92:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E98:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E97:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E43:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6EA5:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E40:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E42:431:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6EA7:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6EA6:4B1:1:C00000:0:0:0:\r
+#SERVICE 1:0:1:6E2E:431:1:C00000:0:0:0:\r
index 64c44cb..8fb5c09 100644 (file)
@@ -12,7 +12,7 @@ SCOPE_HDD = 8
 
 PATH_CREATE = 0
 PATH_DONTCREATE = 1
-
+PATH_FALLBACK = 2
 defaultPaths = {
                SCOPE_TRANSPONDERDATA: ("/etc/", PATH_DONTCREATE),
                SCOPE_SYSETC: ("/etc/", PATH_DONTCREATE),
@@ -27,23 +27,63 @@ defaultPaths = {
                
                SCOPE_USERETC: ("", PATH_DONTCREATE) # user home directory
        }
+       
+FILE_COPY = 0 # copy files from fallback dir to the basedir
+FILE_MOVE = 1 # move files
+PATH_COPY = 2 # copy the complete 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)],
+               SCOPE_HDD: [("/hdd/movies", PATH_MOVE)]
+       }
 
 def resolveFilename(scope, base = ""):
-       # in future, we would check for file existence here,
-       # so we can provide default/fallbacks.
-       
+       print "getting scope", scope, "with base", base
        path = defaultPaths[scope]
-       if path[1] == PATH_CREATE:
-               if (not pathExists(scope)):
-                       os.mkdir(path[0])
+       print "path:", path
+       
+       if not fileExists(path[0] + base):
+               #try:
+               if fallbackPaths.has_key(scope):
+                       print 1
+                       for x in fallbackPaths[scope]:
+                               print x
+                               if x[1] == FILE_COPY:
+                                       if fileExists(x[0] + base):
+                                               os.system("cp " + x[0] + base + " " + path[0] + base)
+                               elif x[1] == FILE_MOVE:
+                                       if fileExists(x[0] + base):
+                                               os.system("mv " + x[0] + base + " " + path[0] + base)
+                               elif x[1] == PATH_COPY:
+                                       if pathExists(x[0]):
+                                               if not pathExists(defaultPaths[scope][0]):
+                                                       os.mkdir(path[0])
+                                               os.system("cp -a " + x[0] + "* " + path[0])
+                               elif x[1] == PATH_MOVE:
+                                       if pathExists(x[0]):
+                                               os.system("mv " + x[0] + " " + path[0])
+
+               if path[1] == PATH_CREATE:
+                       if (not pathExists(defaultPaths[scope][0])):
+                               os.mkdir(path[0])
        
        # FIXME: we also have to handle DATADIR etc. here.
        return path[0] + base
 
        # this is only the BASE - an extension must be added later.
        
-def pathExists(scope):
-       return os.path.exists(defaultPaths[scope][0])
+def pathExists(path):
+       return os.path.exists(path)
+
+def fileExists(f):
+       try:
+               file = open(f)
+       except IOError:
+               exists = 0
+       else:
+               exists = 1
+       return exists
 
 def getRecordingFilename(basename):
        
@@ -66,9 +106,8 @@ def getRecordingFilename(basename):
                        i += 1
                except IOError:
                        return path
-               
-# this fixes paths or files when changed in a new enigma2 version
-def fixOldDirectoryEntries():
-       if (os.path.exists("/hdd/movies")):
-               if (not os.path.exists(resolveFilename(SCOPE_HDD))):
-                       os.system("mv /hdd/movies " + resolveFilename(SCOPE_HDD))
+
+# this is clearly a hack:
+def InitFallbackFiles():
+       resolveFilename(SCOPE_CONFIG, "userbouquet.favourites.tv")
+       resolveFilename(SCOPE_CONFIG, "bouquets.tv")
index f67c199..cb1bc90 100644 (file)
--- a/mytest.py
+++ b/mytest.py
@@ -20,8 +20,8 @@ from Screens.Wizard import wizardManager
 from Screens.StartWizard import *
 from Screens.TutorialWizard import *
 from Tools.BoundFunction import boundFunction
-from Tools.Directories import fixOldDirectoryEntries
-fixOldDirectoryEntries()
+from Tools.Directories import InitFallbackFiles
+InitFallbackFiles()
 
 had = dict()
 
diff --git a/userbouquet.favourites.tv b/userbouquet.favourites.tv
deleted file mode 100644 (file)
index e69de29..0000000