Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from enigma import eTimer
- from Components.config import config
- from Components.Console import Console
- from enigma import eTimer, eDVBLocalTimeHandler, eEPGCache
- try:
- from Tools.StbHardware import setRTCtime
- except:
- from Tools.DreamboxHardware import setRTCtime
- from time import time
- from Tools import Notifications
- from Screens.MessageBox import MessageBox
- import os.path
- from os import popen
- import datetime
- class NTPSyncPoller:
- """Automatically Poll NTP"""
- run_num=0
- def __init__(self):
- self.timer = eTimer()
- self.Console = Console()
- def start(self):
- if not self.timer.callback:
- self.timer.callback.append(self.NTPStart)
- self.timer.startLongTimer(0)
- def stop(self):
- if self.timer.callback:
- self.timer.callback.remove(self.NTPStart)
- self.timer.stop()
- def NTPStart(self):
- NTPSyncPoller.run_num+=1
- dt=datetime.datetime.now()
- open('/usr/lib/enigma2/python/Plugins/Extensions/SetClock/log.txt', 'a').write(str(dt)+' Run# '+str(NTPSyncPoller.run_num)+'\n')
- if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/SetClock/ntpdate"):
- if NTPSyncPoller.run_num==1: #1
- open('/usr/lib/enigma2/python/Plugins/Extensions/SetClock/log.txt', 'a').write(str(dt)+' First run!\n')
- #pass
- self.timer.startLongTimer(int(config.plugins.SetClock.useNTPminutes.value) * 60)
- else:#2
- open('/usr/lib/enigma2/python/Plugins/Extensions/SetClock/log.txt', 'a').write(str(dt)+' NextRun# '+str(NTPSyncPoller.run_num)+'\n')
- if config.plugins.SetClock.choiceSystemTime.value == "1":
- if not config.plugins.SetClock.useNTPminutes.value == "0":
- cmd = '/usr/lib/enigma2/python/Plugins/Extensions/SetClock/ntpdate -s -u %s' % config.plugins.SetClock.ip.value
- res = popen(cmd).read()
- if res == "":
- cmd = "ls -l %s" % ("/usr/lib/enigma2/python/Plugins/Extensions/SetClock/ntpdate")
- res = popen(cmd).read()
- if res[3]!="x":
- cmd = "chmod 755 %s" % ("/usr/lib/enigma2/python/Plugins/Extensions/SetClock/ntpdate")
- res = popen(cmd).read()
- 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')
- else:
- #if not res == "":
- self.Console.ePopen(cmd, self.update_schedule)
- self.timer.startLongTimer(int(config.plugins.SetClock.useNTPminutes.value) * 60)
- else:
- Notifications.AddPopup(text=_('"ntpdate" не установлен !'), type=MessageBox.TYPE_INFO, timeout=10, id='NTPSyncPoller')
- def update_schedule(self, result = None, retval = None, extra_args = None):
- if eDVBLocalTimeHandler.getInstance().ready():
- nowTime = time()
- if nowTime > 1388534400:
- setRTCtime(nowTime)
- if config.plugins.SetClock.choiceSystemTime.value == "0":
- eDVBLocalTimeHandler.getInstance().setUseDVBTime(True)
- else:
- eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
- try:
- eEPGCache.getInstance().timeUpdated()
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement