Advertisement
SharkyEXE

Untitled

Nov 19th, 2018
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from enigma import eTimer
  3. from Components.config import config
  4. from Components.Console import Console
  5. from enigma import eTimer, eDVBLocalTimeHandler, eEPGCache
  6. try:
  7. from Tools.StbHardware import setRTCtime
  8. except:
  9. from Tools.DreamboxHardware import setRTCtime
  10. from time import time
  11. from Tools import Notifications
  12. from Screens.MessageBox import MessageBox
  13. import os.path
  14. from os import popen
  15. import datetime
  16.  
  17. class NTPSyncPoller:
  18. """Automatically Poll NTP"""
  19. run_num=0
  20. def __init__(self):
  21. self.timer = eTimer()
  22. self.Console = Console()
  23.  
  24. def start(self):
  25. if not self.timer.callback:
  26. self.timer.callback.append(self.NTPStart)
  27. self.timer.startLongTimer(0)
  28.  
  29. def stop(self):
  30. if self.timer.callback:
  31. self.timer.callback.remove(self.NTPStart)
  32. self.timer.stop()
  33.  
  34. def NTPStart(self):
  35. NTPSyncPoller.run_num+=1
  36. dt=datetime.datetime.now()
  37. open('/usr/lib/enigma2/python/Plugins/Extensions/SetClock/log.txt', 'a').write(str(dt)+' Run# '+str(NTPSyncPoller.run_num)+'\n')
  38. if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/SetClock/ntpdate"):
  39. if NTPSyncPoller.run_num==1: #1
  40. open('/usr/lib/enigma2/python/Plugins/Extensions/SetClock/log.txt', 'a').write(str(dt)+' First run!\n')
  41. #pass
  42. self.timer.startLongTimer(int(config.plugins.SetClock.useNTPminutes.value) * 60)
  43. else:#2
  44. open('/usr/lib/enigma2/python/Plugins/Extensions/SetClock/log.txt', 'a').write(str(dt)+' NextRun# '+str(NTPSyncPoller.run_num)+'\n')
  45. if config.plugins.SetClock.choiceSystemTime.value == "1":
  46. if not config.plugins.SetClock.useNTPminutes.value == "0":
  47. cmd = '/usr/lib/enigma2/python/Plugins/Extensions/SetClock/ntpdate -s -u %s' % config.plugins.SetClock.ip.value
  48. res = popen(cmd).read()
  49. if res == "":
  50. cmd = "ls -l %s" % ("/usr/lib/enigma2/python/Plugins/Extensions/SetClock/ntpdate")
  51. res = popen(cmd).read()
  52. if res[3]!="x":
  53. cmd = "chmod 755 %s" % ("/usr/lib/enigma2/python/Plugins/Extensions/SetClock/ntpdate")
  54. res = popen(cmd).read()
  55. Notifications.AddPopup(text=_('"ntpdate" problem: attributes for "ntpdate" have not been correct! Fixed now! Try again!%s' % res), type=MessageBox.TYPE_INFO, timeout=10, id='NTPSyncPoller')
  56. else:
  57. #if not res == "":
  58. self.Console.ePopen(cmd, self.update_schedule)
  59. self.timer.startLongTimer(int(config.plugins.SetClock.useNTPminutes.value) * 60)
  60. else:
  61. Notifications.AddPopup(text=_('"ntpdate" не установлен !'), type=MessageBox.TYPE_INFO, timeout=10, id='NTPSyncPoller')
  62.  
  63. def update_schedule(self, result = None, retval = None, extra_args = None):
  64. if eDVBLocalTimeHandler.getInstance().ready():
  65. nowTime = time()
  66. if nowTime > 1388534400:
  67. setRTCtime(nowTime)
  68. if config.plugins.SetClock.choiceSystemTime.value == "0":
  69. eDVBLocalTimeHandler.getInstance().setUseDVBTime(True)
  70. else:
  71. eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
  72. try:
  73. eEPGCache.getInstance().timeUpdated()
  74. except:
  75. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement