-add support for loading pluginlist
authorDr.Best <dr_best@users.schwerkraft.elitedvb.net>
Sat, 3 Oct 2009 15:48:26 +0000 (15:48 +0000)
committerDr.Best <dr_best@users.schwerkraft.elitedvb.net>
Sat, 3 Oct 2009 15:48:26 +0000 (15:48 +0000)
-add support for adding and removing movie-location bookmarks

webinterface/src/WebComponents/Sources/LocationsAndTags.py
webinterface/src/WebComponents/Sources/ReadPluginList.py [new file with mode: 0644]
webinterface/src/WebScreens.py
webinterface/src/web/addlocation.xml [new file with mode: 0644]
webinterface/src/web/pluginlistread.xml [new file with mode: 0644]
webinterface/src/web/removelocation.xml [new file with mode: 0644]

index 6f13c31..3d486ec 100644 (file)
@@ -1,10 +1,13 @@
 from Components.Sources.Source import Source
 from Components.config import config
+import os
 
 class LocationsAndTags(Source):
        CURRLOCATION = 0
        LOCATIONS = 1
        TAGS = 2
+       ADDLOCATION = 3
+       REMOVELOCATION = 4
 
        def __init__(self, session, func):
                self.func = func
@@ -19,6 +22,10 @@ class LocationsAndTags(Source):
                        self.result = self.getLocations()
                elif self.func is self.TAGS:
                        self.result = self.getTags()
+               elif self.func is self.ADDLOCATION:
+                       self.result = self.addLocation(cmd)
+               elif self.func is self.REMOVELOCATION:
+                       self.result = self.removeLocation(cmd)
                else:
                        self.result = False
 
@@ -39,9 +46,52 @@ class LocationsAndTags(Source):
                        tags = ()
                return tags
 
+       def addLocation(self, param):
+               print "[WebComponents.LocationsAndTags] addLocation: ", param
+               if param['dirname'] is None:
+                       return ( False, "Missing Parameter: dirname" )
+               dirname = param['dirname']
+               if len(dirname) == 0:
+                       return ( False, "Missing value for parameter dirname" )
+               if not dirname.endswith("/"):
+                       dirname += "/"
+               if not os.path.exists(dirname):
+                       createFolder = False
+                       if param['createFolder'] is not None:
+                               if param['createFolder'] == "1":
+                                       try:
+                                               createFolder = True
+                                               os.makedirs(dirname)
+                                       except OSError:
+                                               return ( False, "Path %s can not be created" %(dirname) )
+                       if not createFolder:
+                               return ( False, "Path %s does not exist" %(dirname) )
+               bookmarks = config.movielist.videodirs.value[:] or []
+               if dirname in bookmarks:
+                       return ( False, "Location '%s' is already existing" %(dirname) )
+               bookmarks.append(dirname)
+               config.movielist.videodirs.value = bookmarks
+               config.movielist.videodirs.save()
+               return ( True, "Location '%s' added successfully" % (dirname) )
+
+       def removeLocation(self, param):
+               print "[WebComponents.LocationsAndTags] removeLocation: ", param
+               if len(param) == 0:
+                       return ( False, "Missing value for parameter dirname" )
+               dirname = param
+               if not dirname.endswith("/"):
+                       dirname += "/"
+               bookmarks = config.movielist.videodirs.value[:] or []
+               if dirname in bookmarks:
+                       bookmarks.remove(dirname)
+                       config.movielist.videodirs.value = bookmarks
+                       config.movielist.videodirs.save()
+                       return ( True, "Location '%s' removed successfully" % (dirname) )
+               else:
+                       return ( False, "Location '%s' does not exist" %(dirname) )
+
        def getText(self):
                self.handleCommand(None)
-
                if self.result:
                        return str(self.result)
                else:
diff --git a/webinterface/src/WebComponents/Sources/ReadPluginList.py b/webinterface/src/WebComponents/Sources/ReadPluginList.py
new file mode 100644 (file)
index 0000000..09024ce
--- /dev/null
@@ -0,0 +1,16 @@
+from Components.Sources.Source import Source
+from Components.PluginComponent import plugins
+from Tools.Directories import resolveFilename, SCOPE_PLUGINS
+
+class ReadPluginList(Source):
+       def __init__(self, session):
+               Source.__init__(self)
+               self.session = session
+
+       def command(self):
+               print "[WebComponents.ReadPluginList] readPluginList"
+
+               plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
+               return ( True, "List of Plugins has been read" )
+
+       result = property(command)
index 6e7c284..d14d824 100644 (file)
@@ -129,6 +129,12 @@ class ServiceWebScreen(WebScreen):
                ugly, but necessary :(
                """
 
+class ReadPluginListWebScreen(WebScreen):
+       def __init__(self, session, request):
+               WebScreen.__init__(self, session, request)
+               from WebComponents.Sources.ReadPluginList import ReadPluginList
+               self["ReadPluginList"] = ReadPluginList(session)
+
 class LocationsAndTagsWebScreen(WebScreen):
        def __init__(self, session, request):
                WebScreen.__init__(self, session, request)
@@ -136,6 +142,8 @@ class LocationsAndTagsWebScreen(WebScreen):
 
                self["CurrentLocation"] = LocationsAndTags(session, LocationsAndTags.CURRLOCATION)
                self["Locations"] = LocationsAndTags(session, LocationsAndTags.LOCATIONS)
+               self["AddLocation"] = LocationsAndTags(session, LocationsAndTags.ADDLOCATION)
+               self["RemoveLocation"] = LocationsAndTags(session, LocationsAndTags.REMOVELOCATION)
                self["Tags"] = LocationsAndTags(session, LocationsAndTags.TAGS)
 
 class EpgWebScreen(WebScreen):
@@ -341,4 +349,4 @@ class DeviceInfoWebScreen(WebScreen):
                self["ImageVersion"] = StaticText(about.getVersionString())
                self["WebIfVersion"] = StaticText(config.plugins.Webinterface.version.value)
                self["FpVersion"] = StaticText(str(getFPVersion()))
-               self["DeviceName"] = StaticText(hw.get_device_name())
\ No newline at end of file
+               self["DeviceName"] = StaticText(hw.get_device_name())
diff --git a/webinterface/src/web/addlocation.xml b/webinterface/src/web/addlocation.xml
new file mode 100644 (file)
index 0000000..4a2c056
--- /dev/null
@@ -0,0 +1,9 @@
+<e2:screen name="LocationsAndTagsWebScreen">&lt;?xml version="1.0" encoding="UTF-8"?>
+<e2:element source="AddLocation" id="dirname,createFolder">
+       <e2:convert type="web:Null" />
+</e2:element>
+<e2simplexmlresult>
+       <e2state><e2:element source="AddLocation"><e2:convert type="SimpleResult">Result</e2:convert><e2:convert type="web:TextToHTML" /></e2:element></e2state>
+       <e2statetext><e2:element source="AddLocation"><e2:convert type="SimpleResult">ResultText</e2:convert><e2:convert type="web:TextToHTML" /></e2:element></e2statetext>    
+</e2simplexmlresult>           
+</e2:screen>
diff --git a/webinterface/src/web/pluginlistread.xml b/webinterface/src/web/pluginlistread.xml
new file mode 100644 (file)
index 0000000..a4d04b7
--- /dev/null
@@ -0,0 +1,9 @@
+<e2:screen name="ReadPluginListWebScreen">&lt;?xml version="1.0" encoding="UTF-8"?>
+<e2:element source="ReadPluginList">
+       <e2:convert type="web:Null" />
+</e2:element>
+<e2simplexmlresult>
+       <e2state><e2:element source="ReadPluginList"><e2:convert type="SimpleResult">Result</e2:convert><e2:convert type="web:TextToHTML" /></e2:element></e2state>
+       <e2statetext><e2:element source="ReadPluginList"><e2:convert type="SimpleResult">ResultText</e2:convert><e2:convert type="web:TextToHTML" /></e2:element></e2statetext> 
+</e2simplexmlresult>           
+</e2:screen>
diff --git a/webinterface/src/web/removelocation.xml b/webinterface/src/web/removelocation.xml
new file mode 100644 (file)
index 0000000..1de35c0
--- /dev/null
@@ -0,0 +1,9 @@
+<e2:screen name="LocationsAndTagsWebScreen">&lt;?xml version="1.0" encoding="UTF-8"?>
+<e2:element source="RemoveLocation" id="dirname">
+       <e2:convert type="web:Null" />
+</e2:element>
+<e2simplexmlresult>
+       <e2state><e2:element source="RemoveLocation"><e2:convert type="SimpleResult">Result</e2:convert><e2:convert type="web:TextToHTML" /></e2:element></e2state>
+       <e2statetext><e2:element source="RemoveLocation"><e2:convert type="SimpleResult">ResultText</e2:convert><e2:convert type="web:TextToHTML" /></e2:element></e2statetext> 
+</e2simplexmlresult>           
+</e2:screen>