Advertisement
SharkyEXE

Untitled

Aug 3rd, 2018
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 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. 'June': '6',
  50. 'Jun': '6',
  51. 'July': '7',
  52. 'Jul': '7',
  53. 'Aug': '8',
  54. 'Sept': '9',
  55. 'Sep': '9',
  56. 'Oct': '10',
  57. 'Nov': '11',
  58. 'Dec': '12',
  59. }
  60. try:
  61. time_tuple = time.strptime(res_time, '%a, %d %b %Y %H:%M:%S %Z')
  62. except ValueError:
  63. for m1, m2 in replace_months.items():
  64. res_time = res_time.replace(m1, m2)
  65. time_tuple = time.strptime(res_time, '%a, %d %m %Y %H:%M:%S %Z')
  66. t = time.localtime(time.mktime(time_tuple) - time.timezone)
  67. r = time.strftime('%Y%m%d%H%M.%S', t)
  68. open('/usr/lib/enigma2/python/Plugins/Extensions/SetClock/log.txt', 'a').write('({0}), ({1})'.format(type(r), r))
  69. return r
  70.  
  71. class AutoCorrTime(Screen):
  72. skin = '''
  73. <screen position="100,100" size="280,300" title="SetClock" >
  74. </screen>'''
  75.  
  76. def __init__(self, session):
  77. Screen.__init__(self, session)
  78. self.session = session
  79. if time.localtime().tm_year == 2000:
  80. self.limit = 0
  81. self.cursorTimer = eTimer()
  82. self.cursorTimer.callback.append(self.timer)
  83. self.cursorTimer.start(75, False)
  84.  
  85. def timer(self):
  86. if time.localtime().tm_year > 2000:
  87. refstr = dtt = 'n/a'
  88. try:
  89. service = self.session.nav.getCurrentService()
  90. if service:
  91. info = service.info()
  92. if info:
  93. refstr = info.getInfoString(iServiceInformation.sServiceref)
  94. except:
  95. refstr = 'ref error'
  96.  
  97. if refstr == '1:0:1:1:65:64:3840000:0:0:0:':
  98. tc = time.time() - 189391980
  99. dtt = datetime.fromtimestamp(tc).strftime('%Y%m%d%H%M')
  100. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  101. try:
  102. system('/bin/date -s %s' % dtt)
  103. print '[SetClock] Set clock!'
  104. except:
  105. pass
  106.  
  107. self.cursorTimer.stop()
  108. print '[SetClock] Stop timer.'
  109. self.limit = self.limit + 1
  110. if self.limit > 1200:
  111. self.cursorTimer.stop()
  112. print '[SetClock] Stop timer (limit).'
  113.  
  114.  
  115. class SetClockMain(ConfigListScreen, Screen):
  116. skin = '''
  117. <screen position="center,250" size="420,190" title="SetClock Menu" >
  118. <widget name="config" position="10,10" size="400,130" scrollbarMode="showOnDemand" />
  119. <widget name="key_green" position="0,150" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;18" transparent="1"/>
  120. <ePixmap name="green" position="0,150" size="140,40" zPosition="2" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
  121. <widget name="key_blue" position="140,150" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;18" transparent="1"/>
  122. <ePixmap name="blue" position="140,150" size="140,40" zPosition="2" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
  123. <widget name="key_red" position="280,150" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;18" transparent="1"/>
  124. <ePixmap name="red" position="280,150" size="140,40" zPosition="2" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
  125. </screen>'''
  126.  
  127. def __init__(self, session, args = 0):
  128. self.skin = SetClockMain.skin
  129. self.session = session
  130. Screen.__init__(self, session)
  131. self.list = []
  132. self.date_en = ConfigDateTime(default=time.time(), formatstring='%d.%m.%y')
  133. self.entryDate = getConfigListEntry(_('Date'), self.date_en)
  134. self.time_en = ConfigClock(default=time.time())
  135. self.entryTime = getConfigListEntry(_('Time'), self.time_en)
  136. self.list.append(self.entryDate)
  137. self.list.append(self.entryTime)
  138. self.list.append(getConfigListEntry('HTTP host:', config.plugins.SetClock.HostName))
  139. self['key_green'] = Button(_('SET!'))
  140. self['key_blue'] = Button(_('HTTP SET'))
  141. self['key_red'] = Button(_('Cancel'))
  142. ConfigListScreen.__init__(self, self.list, session=session)
  143. self['setupActions'] = ActionMap(['SetupActions', 'ColorActions'], {'red': self.cancel,
  144. 'green': self.set,
  145. 'blue': self.inet_set,
  146. 'save': self.set,
  147. 'cancel': self.cancel,
  148. 'ok': self.pressed_ok}, -2)
  149. self['config'].list = self.list
  150. self['config'].l.setList(self.list)
  151.  
  152. def pressed_ok(self):
  153. config.plugins.SetClock.HostName.save()
  154. self.set()
  155.  
  156. def set(self, dtt = 0):
  157. d = time.localtime(self.date_en.value)
  158. dtt = '%d%02d%02d%02d%02d' % (d.tm_year,
  159. d.tm_mon,
  160. d.tm_mday,
  161. self.time_en.value[0],
  162. self.time_en.value[1])
  163. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  164. try:
  165. system('/bin/date -s %s' % dtt)
  166. except:
  167. pass
  168.  
  169. self.close()
  170. print '[SetClock] SET! ** %s' % time.strftime('%X %x (%Y) %Z')
  171.  
  172. def inet_set(self):
  173. config.plugins.SetClock.HostName.save()
  174. conn = httplib.HTTPConnection(config.plugins.SetClock.HostName.value)
  175. try:
  176. conn.request('HEAD', '/favicon.ico')
  177. t_rtt = time.clock()
  178. res_time = conn.getresponse().getheader('date')
  179. except:
  180. self.session.open(MessageBox, 'Error: No server responce: ' + config.plugins.SetClock.HostName.value, MessageBox.TYPE_ERROR, timeout=3)
  181. return
  182.  
  183. enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  184.  
  185. try:
  186. system('/bin/date -s %s' % get_time_str(res_time))
  187. except:
  188. pass
  189.  
  190. self.close()
  191. print '[SetClock] inet SET! ** %s' % time.strftime('%X %x (%Y) %Z')
  192.  
  193. def cancel(self):
  194. self.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement