fix deleting bug
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / Movie.py
1 from enigma import *
2 from enigma import eServiceReference, iServiceInformation
3 from Components.Sources.Source import Source
4 from ServiceReference import ServiceReference,eServiceCenter
5 from Components.MovieList import MovieList
6 from Tools.Directories import *
7
8 import os
9 #import sys, traceback
10
11 class Movie( Source):
12     LIST = 0
13     DEL = 1
14     
15     def __init__(self, session,func = LIST):
16         Source.__init__(self)
17         self.func = func
18         self.session = session
19         self.root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
20         self.movielist = MovieList(self.root)
21         self.movielist.load(self.root,None)
22     
23     def handleCommand(self,cmd):
24         if self.func is self.DEL:
25             self.result = self.delMovieFiles(cmd)
26         else:
27             self.result = False,"unknown command"
28         
29     def delMovieFiles(self,param):
30         print "delMovieFiles:",param
31         
32         if param is None:
33             return False,"title missing"
34         
35         #os.system("rm -f %s*" % param)
36         try:
37             os.system('rm -f "%s"' % param)
38             #.ap .cuts .meta
39             if os.path.exists("%s.ap" % param):
40                 os.system('rm -f "%s.ap"' % param)
41             
42             if os.path.exists("%s.cuts" % param):
43                 os.system('rm -f "%s.cuts"' % param)
44             
45             if os.path.exists("%s.meta" % param):
46                 os.system('rm -f "%s.meta"' % param)
47         except OSError:
48             return False,"OSErrorSome error occurred while deleting file"
49 #        except:
50 #             print sys.exc_info()[0]
51 #             print sys.exc_info()[1]
52 #             print traceback.extract_tb(sys.exc_info()[2])
53
54         
55         if os.path.exists(param):
56             return False,"Some error occurred while deleting file"
57         else:
58             return True,"File deleted"
59    
60     def command(self):
61         self.movielist.reload(root=self.root)
62         list=[]
63         for (serviceref, info, begin,unknown) in self.movielist.list:
64             movie = []
65             movie.append(serviceref.toString())
66             movie.append(ServiceReference(serviceref).getServiceName())
67             movie.append(info.getInfoString(serviceref, iServiceInformation.sDescription))
68             
69             sourceERef =info.getInfoString(serviceref, iServiceInformation.sServiceref)
70             sourceRef= ServiceReference(sourceERef)
71             
72             movie.append(sourceRef.getServiceName())
73             movie.append(info.getInfoString(serviceref, iServiceInformation.sTags))
74             event = info.getEvent(serviceref)
75             if event is not None:
76                 text = event.getEventName()
77                 short = event.getShortDescription()
78                 ext = event.getExtendedDescription()
79                 movie.append(ext)
80             else:
81                 movie.append("")
82             filename = "/"+"/".join(serviceref.toString().split("/")[1:])
83             movie.append(filename)
84             list.append(movie)
85         print "tags",self.movielist.tags
86         return list
87
88     def getText(self):
89         print self.result
90         (result,text) = self.result
91         xml = "<?xml version=\"1.0\"?>\n"
92         xml  += "<e2simplexmlresult>\n"
93         if result:
94             xml += "<e2state>True</e2state>\n"
95         else:
96             xml += "<e2state>False</e2state>\n"            
97         xml += "<e2statetext>%s</e2statetext>\n" % text
98         xml += "</e2simplexmlresult>\n"
99         return xml
100     
101     text = property(getText)        
102     
103     list = property(command)
104     lut = {"ServiceReference": 0
105            ,"Title": 1
106            ,"Description": 2
107            ,"ServiceName": 3
108            ,"Tags": 4
109            ,"DescriptionExtended": 5
110            ,"Filename": 6
111            }
112