Advertisement
SharkyEXE

Untitled

Aug 2nd, 2018
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.89 KB | None | 0 0
  1. from Plugins.Plugin import PluginDescriptor
  2. from Screens.Screen import Screen
  3. from Screens.MessageBox import MessageBox
  4. from Components.Button import Button
  5. from Components.ActionMap import ActionMap
  6. from Components.ConfigList import ConfigListScreen
  7. from Components.config import config, ConfigSubsection, ConfigDateTime, ConfigClock, ConfigText, getConfigListEntry
  8. import enigma
  9. from enigma import eTimer, iServiceInformation
  10. from datetime import datetime, time as dt_time
  11. from os import system
  12. import gettext
  13. import time, httplib
  14.  
  15. config.plugins.SetClock = ConfigSubsection()
  16. config.plugins.SetClock.HostName = ConfigText(default='ya.ru', fixed_size=False)
  17. ver = '1.1'
  18.  
  19. def _(txt):
  20. t = gettext.gettext(txt)
  21. return t
  22.  
  23.  
  24. def Plugins(**kwargs):
  25. return [PluginDescriptor(name='SetClock', description='SetClock plug-in v.' + ver + ' (c)2011 by SatCat', where=PluginDescriptor.WHERE_PLUGINMENU, icon='plugin.png', fnc=main), PluginDescriptor(name='SetClock', description='SetClock plug-in v.' + ver + '(c)2011 by SatCat', where=[PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc=autostart)]
  26.  
  27.  
  28. def main(session, servicereference = None, **kwargs):
  29. try:
  30. session.open(SetClockMain)
  31. except:
  32. print '[SetClock] Pluginexecution failed'
  33.  
  34.  
  35. def autostart(reason, **kwargs):
  36. global session
  37. if reason == 0 and kwargs.has_key('session'):
  38. session = kwargs['session']
  39. session.open(AutoCorrTime)
  40.  
  41.  
  42. def get_time_str(res_time):
  43. replace_months = {
  44. 'Jan': '1'
  45. 'Feb': '2'
  46. 'Mar': '3'
  47. 'Apr': '4'
  48. 'May': '5'
  49. 'Jun': '6'
  50. 'Jul': '7'
  51. 'Aug': '8'
  52. 'Sep': '9'
  53. 'Oct': '10'
  54. 'Nov': '11'
  55. 'Dec': '12'
  56. }
  57. try:
  58. time_tuple = time.strptime(res_time, '%a, %d %b %Y %H:%M:%S %Z')
  59. except ValueError:
  60. date_str, time_str = res_time.replace(' GMT', '').split(', ')[1].rsplit(' ', 1)
  61. _t = dt_time(*[int(i) for i in time_str.split(':')])
  62. try:
  63. _d = datetime.strptime(date_str, '%d %b %Y')
  64. except ValueError:
  65. for m1, m2 in replace_months.items():
  66. date_str = date_str.replace(m1, m2)
  67. _d = datetime.strptime(date_str, '%d %m %Y')
  68. time_tuple = datetime.combine(_d, _t).timetuple()
  69. t = time.localtime(time.mktime(time_tuple) - time.timezone)
  70. return time.strftime('%Y%m%d%H%M.%S', t)
  71.  
  72. class AutoCorrTime(Screen):
  73. skin = '<screen position="100,100" size="280,300" title="SetClock" > </screen>'
  74.  
  75. def __init__(self, session):
  76. Screen.__init__(self, session)
  77. self.session = session
  78. if time.localtime().tm_year == 2000:
  79. self.limit = 0
  80. self.cursorTimer = eTimer()
  81. self.cursorTimer.callback.append(self.timer)
  82. self.cursorTimer.start(75, False)
  83.  
  84. def timer(self):
  85. if time.localtime().tm_year > 2000:
  86. refstr = dtt = 'n/a'
  87. try:
  88. service = self.session.nav.getCurrentService()
  89. if service:
  90. info = service.info()
  91. if info:
  92. refstr = info.getInfoString(iServiceInformation.sServiceref)
  93. except:
  94. refstr = 'ref error'
  95.  
  96. if refstr == '1:0:1:1:65:64:3840000:0:0:0:':
  97. tc = time.time() - 189391980
  98. dtt = datetime.fromtimestamp(tc).strftime('%Y%m%d%H%M')
  99. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  100. try:
  101. system('/bin/date -s %s' % dtt)
  102. print '[SetClock] Set clock!'
  103. except:
  104. pass
  105.  
  106. self.cursorTimer.stop()
  107. print '[SetClock] Stop timer.'
  108. self.limit = self.limit + 1
  109. if self.limit > 1200:
  110. self.cursorTimer.stop()
  111. print '[SetClock] Stop timer (limit).'
  112.  
  113.  
  114. class SetClockMain(ConfigListScreen, Screen):
  115. skin = '\n\t\t<screen position="50,250" size="420,190" title="SetClock Menu" >\n\t\t\t<widget name="config" position="10,10" size="400,130" scrollbarMode="showOnDemand" />\n\t\t\t<widget name="key_green" \tposition="0,150" \tsize="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;18" transparent="1"/> \n\t\t\t<ePixmap name="green" \t\tposition="0,150" \tsize="140,40" zPosition="2" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />\n\t\t\t<widget name="key_blue" \tposition="140,150" \tsize="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;18" transparent="1"/> \n\t\t\t<ePixmap name="blue" \t\tposition="140,150" \tsize="140,40" zPosition="2" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />\n\t\t\t<widget name="key_red" \t\tposition="280,150" \tsize="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;18" transparent="1"/> \n\t\t\t<ePixmap name="red" \t\tposition="280,150" \tsize="140,40" zPosition="2" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />\n\t\t</screen>'
  116.  
  117. def __init__(self, session, args = 0):
  118. self.skin = SetClockMain.skin
  119. self.session = session
  120. Screen.__init__(self, session)
  121. self.list = []
  122. self.date_en = ConfigDateTime(default=time.time(), formatstring='%d.%m.%y')
  123. self.entryDate = getConfigListEntry(_('Date'), self.date_en)
  124. self.time_en = ConfigClock(default=time.time())
  125. self.entryTime = getConfigListEntry(_('Time'), self.time_en)
  126. self.list.append(self.entryDate)
  127. self.list.append(self.entryTime)
  128. self.list.append(getConfigListEntry('HTTP host:', config.plugins.SetClock.HostName))
  129. self['key_green'] = Button(_('SET!'))
  130. self['key_blue'] = Button(_('HTTP SET'))
  131. self['key_red'] = Button(_('Cancel'))
  132. ConfigListScreen.__init__(self, self.list, session=session)
  133. self['setupActions'] = ActionMap(['SetupActions', 'ColorActions'], {'red': self.cancel,
  134. 'green': self.set,
  135. 'blue': self.inet_set,
  136. 'save': self.set,
  137. 'cancel': self.cancel,
  138. 'ok': self.pressed_ok}, -2)
  139. self['config'].list = self.list
  140. self['config'].l.setList(self.list)
  141.  
  142. def pressed_ok(self):
  143. config.plugins.SetClock.HostName.save()
  144. self.set()
  145.  
  146. def set(self, dtt = 0):
  147. d = time.localtime(self.date_en.value)
  148. dtt = '%d%02d%02d%02d%02d' % (d.tm_year,
  149. d.tm_mon,
  150. d.tm_mday,
  151. self.time_en.value[0],
  152. self.time_en.value[1])
  153. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  154. try:
  155. system('/bin/date -s %s' % dtt)
  156. except:
  157. pass
  158.  
  159. self.close()
  160. print '[SetClock] SET! ** %s' % time.strftime('%X %x (%Y) %Z')
  161.  
  162. def inet_set(self):
  163. config.plugins.SetClock.HostName.save()
  164. conn = httplib.HTTPConnection(config.plugins.SetClock.HostName.value)
  165. try:
  166. conn.request('HEAD', '/favicon.ico')
  167. t_rtt = time.clock()
  168. res_time = conn.getresponse().getheader('date')
  169. except:
  170. self.session.open(MessageBox, 'Error: No server responce: ' + config.plugins.SetClock.HostName.value, MessageBox.TYPE_ERROR, timeout=3)
  171. return
  172.  
  173. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  174.  
  175. try:
  176. system('/bin/date -s %s' % get_time_str(res_time))
  177. except:
  178. pass
  179.  
  180. self.close()
  181. print '[SetClock] inet SET! ** %s' % time.strftime('%X %x (%Y) %Z')
  182.  
  183. def cancel(self):
  184. self.close()
  185. # okay decompyling /tmp/plugin.pyo
  186. # decompiled 1 files: 1 okay, 0 failed, 0 verify failed
  187. # 2018.07.29 18:10:27 EAT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement