source: ipk/source/epg_crossepg/var/crossepg/scripts/lib/webif.py@ 17841

Last change on this file since 17841 was 7451, checked in by BPanther, 15 years ago

[ipk] - copy source->source.sh4

File size: 3.7 KB
Line 
1#!/usr/bin/python
2
3# webif.py by Ambrosa http://www.ambrosa.net
4# this module is used for manage Web Interface
5# not tested with CrossEPG
6
7__author__ = "ambrosa http://www.ambrosa.net"
8__version__ = "0.53 beta E2_LOADEPG"
9__copyright__ = "Copyright (C) 2008-2009 Alessandro Ambrosini"
10__license__ = "CreativeCommons by-nc-sa http://creativecommons.org/licenses/by-nc-sa/3.0/"
11
12import time
13import string
14import urllib2
15from urllib import quote_plus
16from xml.dom import minidom
17
18
19class webif_class:
20 USE_WEBIF=1
21 USE_WEBIF_AUTH=0
22 WEBIF_AUTH_USER='root'
23 WEBIF_AUTH_PASSW='qboxhd'
24 WEBIF_AUTH_REALM='dm7025'
25 WEBIF_IP='127.0.0.1'
26
27 def __init__(self,use,auth,auth_name,auth_passw,auth_realm,ip):
28 self.USE_WEBIF=use
29 self.USE_WEBIF_AUTH=auth
30 self.WEBIF_AUTH_USER=auth_name
31 self.WEBIF_AUTH_PASSW=auth_passw
32 self.WEBIF_AUTH_REALM=auth_realm
33 self.WEBIF_IP=ip
34
35
36 def get_use_webif(self):
37 return(self.USE_WEBIF)
38
39
40 # WebInterface routines
41 # see http://dream.reichholf.net/wiki/Enigma2:WebInterface
42 def WI(self,command):
43
44 if self.USE_WEBIF_AUTH == 1 :
45 auth_handler = urllib2.HTTPBasicAuthHandler()
46 auth_handler.add_password(self.WEBIF_AUTH_REALM, 'http://' + self.WEBIF_IP, self.WEBIF_AUTH_USER, self.WEBIF_AUTH_PASSW)
47 opener = urllib2.build_opener(auth_handler)
48 urllib2.install_opener(opener)
49
50 try:
51 sock=urllib2.urlopen('http://' + self.WEBIF_IP + '/web/' + command)
52 data=sock.read()
53 except urllib2.URLError:
54 pass
55 except urllib2.HTTPError:
56 pass
57 except urllib2.httplib.BadStatusLine:
58 pass
59 else:
60 sock.close()
61 return(data)
62
63 def standby(self):
64 current_sid=self.currentchannelsid()
65 if current_sid != None:
66 self.WI('powerstate?newstate=0')
67 time.sleep(5)
68
69 def restartenigma(self):
70 self.WI('powerstate?newstate=3')
71
72 def switchon(self):
73 current_sid=self.currentchannelsid()
74 if current_sid == None:
75 # DM appears switched off. Switch it on !
76
77 # switch on emulating remote keypress
78 # 'powerstate?newstate=116' is not (?) working
79 #self.WI('remotecontrol?command=116')
80 self.WI('powerstate?newstate=0')
81
82 time.sleep(5)
83 current_sid=self.currentchannelsid()
84
85 return(current_sid)
86
87
88 def zap(self,channelsid):
89 self.WI('zap?sRef='+channelsid)
90
91 def reloadepgdat(self):
92 self.WI('powerstate?newstate=10')
93
94 def currentchannelsid(self):
95 # DM must be SWITCHED ON
96 # if DM is in standby mode, it return 'none'
97 data=self.WI('subservices')
98
99 if data == None :
100 return(None)
101
102 try:
103 xmldoc = minidom.parseString(data)
104 except:
105 return(None)
106
107 r=xmldoc.getElementsByTagName('e2servicereference')[0].firstChild.data
108 if r == 'N/A':
109 return(None)
110
111 return(r)
112
113 def is_recording(self):
114 data=self.WI("timerlist")
115 if data.find("<e2state>2</e2state>") == -1:
116 return(False) # not recording
117 else:
118 return(True) # recording
119
120 def message(self,txt,timeout=10,type=1):
121 is_on=self.currentchannelsid()
122 # WARNING: if DM is switched off, sending a message cause a lock/crash in the system
123 if is_on != None:
124 self.WI("message?text="+quote_plus("E2_LOADEPG - "+txt)+"&type="+str(type)+"&timeout="+str(timeout))
125
126
Note: See TracBrowser for help on using the repository browser.