Advertisement
SharkyEXE

Untitled

Jul 31st, 2018
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1. # 2018.07.29 18:10:21 EAT
  2. #Embedded file name: /usr/lib/enigma2/python/Plugins/Extensions/SetClock/plugin.py
  3. from Plugins.Plugin import PluginDescriptor
  4. from Screens.Screen import Screen
  5. from Screens.MessageBox import MessageBox
  6. from Components.Button import Button
  7. from Components.ActionMap import ActionMap
  8. from Components.ConfigList import ConfigListScreen
  9. from Components.config import config, ConfigSubsection, ConfigDateTime, ConfigClock, ConfigText, getConfigListEntry
  10. import enigma
  11. from enigma import eTimer, iServiceInformation
  12. from datetime import datetime
  13. from os import system
  14. import gettext
  15. import time, httplib
  16. config.plugins.SetClock = ConfigSubsection()
  17. config.plugins.SetClock.HostName = ConfigText(default='ya.ru', fixed_size=False)
  18. ver = '1.1'
  19.  
  20. def _(txt):
  21. t = gettext.gettext(txt)
  22. return t
  23.  
  24.  
  25. def Plugins(**kwargs):
  26. return [PluginDescriptor(name='SetClock', description='SetClock plug-in v.' + ver + ' (c)2011 by SatCat', where=PluginDescriptor.WHERE_PLUGINMENU, icon='set_clock.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)]
  27.  
  28.  
  29. def main(session, servicereference = None, **kwargs):
  30. try:
  31. session.open(SetClockMain)
  32. except:
  33. print '[SetClock] Pluginexecution failed'
  34.  
  35.  
  36. def autostart(reason, **kwargs):
  37. global session
  38. if reason == 0 and kwargs.has_key('session'):
  39. session = kwargs['session']
  40. session.open(AutoCorrTime)
  41.  
  42.  
  43. class AutoCorrTime(Screen):
  44. skin = '<screen position="100,100" size="280,300" title="SetClock" > </screen>'
  45.  
  46. def __init__(self, session):
  47. Screen.__init__(self, session)
  48. self.session = session
  49. if time.localtime().tm_year == 2000:
  50. self.limit = 0
  51. self.cursorTimer = eTimer()
  52. self.cursorTimer.callback.append(self.timer)
  53. self.cursorTimer.start(75, False)
  54.  
  55. def timer(self):
  56. if time.localtime().tm_year > 2000:
  57. refstr = dtt = 'n/a'
  58. try:
  59. service = self.session.nav.getCurrentService()
  60. if service:
  61. info = service.info()
  62. if info:
  63. refstr = info.getInfoString(iServiceInformation.sServiceref)
  64. except:
  65. refstr = 'ref error'
  66.  
  67. if refstr == '1:0:1:1:65:64:3840000:0:0:0:':
  68. tc = time.time() - 189391980
  69. dtt = datetime.fromtimestamp(tc).strftime('%Y%m%d%H%M')
  70. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  71. try:
  72. system('/bin/date -s %s' % dtt)
  73. print '[SetClock] Set clock!'
  74. except:
  75. pass
  76.  
  77. self.cursorTimer.stop()
  78. print '[SetClock] Stop timer.'
  79. self.limit = self.limit + 1
  80. if self.limit > 1200:
  81. self.cursorTimer.stop()
  82. print '[SetClock] Stop timer (limit).'
  83.  
  84.  
  85. class SetClockMain(ConfigListScreen, Screen):
  86. 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>'
  87.  
  88. def __init__(self, session, args = 0):
  89. self.skin = SetClockMain.skin
  90. self.session = session
  91. Screen.__init__(self, session)
  92. self.list = []
  93. self.date_en = ConfigDateTime(default=time.time(), formatstring='%d.%m.%y')
  94. self.entryDate = getConfigListEntry(_('Date'), self.date_en)
  95. self.time_en = ConfigClock(default=time.time())
  96. self.entryTime = getConfigListEntry(_('Time'), self.time_en)
  97. self.list.append(self.entryDate)
  98. self.list.append(self.entryTime)
  99. self.list.append(getConfigListEntry('HTTP host:', config.plugins.SetClock.HostName))
  100. self['key_green'] = Button(_('SET!'))
  101. self['key_blue'] = Button(_('HTTP SET'))
  102. self['key_red'] = Button(_('Cancel'))
  103. ConfigListScreen.__init__(self, self.list, session=session)
  104. self['setupActions'] = ActionMap(['SetupActions', 'ColorActions'], {'red': self.cancel,
  105. 'green': self.set,
  106. 'blue': self.inet_set,
  107. 'save': self.set,
  108. 'cancel': self.cancel,
  109. 'ok': self.pressed_ok}, -2)
  110. self['config'].list = self.list
  111. self['config'].l.setList(self.list)
  112.  
  113. def pressed_ok(self):
  114. config.plugins.SetClock.HostName.save()
  115. self.set()
  116.  
  117. def set(self, dtt = 0):
  118. d = time.localtime(self.date_en.value)
  119. dtt = '%d%02d%02d%02d%02d' % (d.tm_year,
  120. d.tm_mon,
  121. d.tm_mday,
  122. self.time_en.value[0],
  123. self.time_en.value[1])
  124. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  125. try:
  126. system('/bin/date -s %s' % dtt)
  127. except:
  128. pass
  129.  
  130. self.close()
  131. print '[SetClock] SET! ** %s' % time.strftime('%X %x (%Y) %Z')
  132.  
  133. def inet_set(self):
  134. config.plugins.SetClock.HostName.save()
  135. conn = httplib.HTTPConnection(config.plugins.SetClock.HostName.value)
  136. try:
  137. conn.request('HEAD', '/favicon.ico')
  138. t_rtt = time.clock()
  139. res_time = conn.getresponse().getheader('date')
  140. except:
  141. self.session.open(MessageBox, 'Error: No server responce: ' + config.plugins.SetClock.HostName.value, MessageBox.TYPE_ERROR, timeout=3)
  142. return
  143.  
  144. t = time.localtime(time.mktime(time.strptime(res_time, '%a, %d %b %Y %H:%M:%S %Z')) - time.timezone)
  145. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  146. dtt = time.strftime('%Y%m%d%H%M.%S', t)
  147. try:
  148. system('/bin/date -s %s' % dtt)
  149. except:
  150. pass
  151.  
  152. self.close()
  153. print '[SetClock] inet SET! ** %s' % time.strftime('%X %x (%Y) %Z')
  154.  
  155. def cancel(self):
  156. self.close()
  157. # okay decompyling /tmp/plugin.pyo
  158. # decompiled 1 files: 1 okay, 0 failed, 0 verify failed
  159. # 2018.07.29 18:10:27 EAT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement