add downloadbutton in movielist, fix HTTP-Header Contenttype
[enigma2-plugins.git] / webinterface / src / WebChilds / IPKG.py
1 from enigma import eConsoleAppContainer
2
3 from twisted.web2 import resource, stream, responsecode, http
4
5 import os
6
7 class IPKGResource(resource.Resource):
8     def render(self, req):
9        self.args = req.args
10        if self.getArg("command") == "update":
11            return self.doUpdate()
12        elif self.getArg("command") == "upgrade":
13            return self.doUpgrade()
14        elif self.getArg("command") == "list_installed":
15            return self.doListInstalled()
16        elif self.getArg("command") == "list":
17            return self.doListAvaiable()
18        elif self.getArg("command") == "search":
19            return self.doSearch()
20        elif self.getArg("command") == "info":
21            return self.doInfo()
22        elif self.getArg("command") == "status":
23            return self.doInfo()
24        elif self.getArg("command") == "install":
25            return self.doInstall()
26        elif self.getArg("command") == "remove":
27            return self.doRemove()
28        elif self.getArg("command"):
29            return self.doErrorPage("no or unknown command")
30        else:
31            return self.doIndexPage()
32
33     def doIndexPage(self):
34         html  = "<html><body>"
35         html += "<h1>Interface to IPKG</h1>"
36         html += "update, ?command=update<br>"
37         html += "upgrade, ?command=upgrade<br>"
38         html += "list_installed, ?command=list_installed<br>"
39         html += "list, ?command=list<br>"
40         html += "search, ?command=search&file=&lt;filename&gt;<br>"
41         html += "info, ?command=search&package=&lt;packagename&gt;<br>"
42         html += "status, ?command=search&package=&lt;packagename&gt;<br>"
43         html += "install, ?command=install&package=&lt;packagename&gt;<br>"
44         html += "remove, ?command=remove&package=&lt;packagename&gt;<br>"
45         html += "</body></html>"
46         return http.Response(responsecode.OK,stream=html)
47
48     def doUpdate(self):
49         return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg update"))
50         
51     def doUpgrade(self):
52         return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg upgrade"))
53         
54     def doListInstalled(self):
55         return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg list_installed"))
56         
57     def doListAvaiable(self):
58         return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg list"))
59
60     def doSearch(self):
61         if self.getArg("file"):
62             return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg search "+self.getArg("file")))
63         else:
64             return self.doErrorPage("no file to search givven")
65
66     def doInfo(self):
67         if self.getArg("package"):
68             return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg info "+self.getArg("package")))
69         else:
70             return self.doErrorPage("no package to print info givven")
71
72     def doStatus(self):
73         if self.getArg("package"):
74             return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg status "+self.getArg("package")))
75         else:
76             return self.doErrorPage("no package to print status givven")
77
78     def doInstall(self):
79         if self.getArg("package"):
80             return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg install "+self.getArg("package")))
81         else:
82             return self.doErrorPage("no package to install givven")
83
84     def doRemove(self):
85         if self.getArg("package"):
86             return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg remove "+self.getArg("package")))
87         else:
88             return self.doErrorPage("no package to remove givven")
89
90     def doListAvaiable(self):
91         return http.Response(responsecode.OK,stream=IPKGConsoleStream("ipkg list"))
92         
93     def doErrorPage(self,errormsg):
94         return http.Response(responsecode.OK,stream=errormsg)
95     
96     def getArg(self,key):
97         if self.args.has_key(key):
98             return self.args[key][0]
99         else:
100             return False
101
102 class IPKGConsoleStream(stream.ProducerStream):
103     def __init__(self,cmd):
104         stream.ProducerStream.__init__(self)
105         self.container = eConsoleAppContainer()
106         self.container.appClosed.get().append(self.cmdFinished)
107         self.container.dataAvail.get().append(self.dataAvail)
108         self.container.execute(cmd)
109
110     def cmdFinished(self,data):
111         self.finish()    
112             
113     def dataAvail(self,data):
114         self.write(data)