Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Plugins.Plugin import PluginDescriptor
- from Screens.Screen import Screen
- from Screens.MessageBox import MessageBox
- from Components.Button import Button
- from Components.ActionMap import ActionMap
- from Components.ConfigList import ConfigListScreen
- from Components.config import config, ConfigSubsection, ConfigDateTime, ConfigClock, ConfigText, getConfigListEntry
- import enigma
- from enigma import eTimer, iServiceInformation
- from datetime import datetime, time as dt_time
- from os import system
- import gettext
- import time, httplib
- config.plugins.SetClock = ConfigSubsection()
- config.plugins.SetClock.HostName = ConfigText(default='ya.ru', fixed_size=False)
- ver = '1.1'
- def _(txt):
- t = gettext.gettext(txt)
- return t
- def Plugins(**kwargs):
- 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)]
- def main(session, servicereference = None, **kwargs):
- try:
- session.open(SetClockMain)
- except:
- print '[SetClock] Pluginexecution failed'
- def autostart(reason, **kwargs):
- global session
- if reason == 0 and kwargs.has_key('session'):
- session = kwargs['session']
- session.open(AutoCorrTime)
- def get_time_str(res_time):
- replace_months = {
- 'Jan': '1'
- 'Feb': '2'
- 'Mar': '3'
- 'Apr': '4'
- 'May': '5'
- 'Jun': '6'
- 'Jul': '7'
- 'Aug': '8'
- 'Sep': '9'
- 'Oct': '10'
- 'Nov': '11'
- 'Dec': '12'
- }
- try:
- time_tuple = time.strptime(res_time, '%a, %d %b %Y %H:%M:%S %Z')
- except ValueError:
- date_str, time_str = res_time.replace(' GMT', '').split(', ')[1].rsplit(' ', 1)
- _t = dt_time(*[int(i) for i in time_str.split(':')])
- try:
- _d = datetime.strptime(date_str, '%d %b %Y')
- except ValueError:
- for m1, m2 in replace_months.items():
- date_str = date_str.replace(m1, m2)
- _d = datetime.strptime(date_str, '%d %m %Y')
- time_tuple = datetime.combine(_d, _t).timetuple()
- t = time.localtime(time.mktime(time_tuple) - time.timezone)
- return time.strftime('%Y%m%d%H%M.%S', t)
- class AutoCorrTime(Screen):
- skin = '<screen position="100,100" size="280,300" title="SetClock" > </screen>'
- def __init__(self, session):
- Screen.__init__(self, session)
- self.session = session
- if time.localtime().tm_year == 2000:
- self.limit = 0
- self.cursorTimer = eTimer()
- self.cursorTimer.callback.append(self.timer)
- self.cursorTimer.start(75, False)
- def timer(self):
- if time.localtime().tm_year > 2000:
- refstr = dtt = 'n/a'
- try:
- service = self.session.nav.getCurrentService()
- if service:
- info = service.info()
- if info:
- refstr = info.getInfoString(iServiceInformation.sServiceref)
- except:
- refstr = 'ref error'
- if refstr == '1:0:1:1:65:64:3840000:0:0:0:':
- tc = time.time() - 189391980
- dtt = datetime.fromtimestamp(tc).strftime('%Y%m%d%H%M')
- enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
- try:
- system('/bin/date -s %s' % dtt)
- print '[SetClock] Set clock!'
- except:
- pass
- self.cursorTimer.stop()
- print '[SetClock] Stop timer.'
- self.limit = self.limit + 1
- if self.limit > 1200:
- self.cursorTimer.stop()
- print '[SetClock] Stop timer (limit).'
- class SetClockMain(ConfigListScreen, Screen):
- 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>'
- def __init__(self, session, args = 0):
- self.skin = SetClockMain.skin
- self.session = session
- Screen.__init__(self, session)
- self.list = []
- self.date_en = ConfigDateTime(default=time.time(), formatstring='%d.%m.%y')
- self.entryDate = getConfigListEntry(_('Date'), self.date_en)
- self.time_en = ConfigClock(default=time.time())
- self.entryTime = getConfigListEntry(_('Time'), self.time_en)
- self.list.append(self.entryDate)
- self.list.append(self.entryTime)
- self.list.append(getConfigListEntry('HTTP host:', config.plugins.SetClock.HostName))
- self['key_green'] = Button(_('SET!'))
- self['key_blue'] = Button(_('HTTP SET'))
- self['key_red'] = Button(_('Cancel'))
- ConfigListScreen.__init__(self, self.list, session=session)
- self['setupActions'] = ActionMap(['SetupActions', 'ColorActions'], {'red': self.cancel,
- 'green': self.set,
- 'blue': self.inet_set,
- 'save': self.set,
- 'cancel': self.cancel,
- 'ok': self.pressed_ok}, -2)
- self['config'].list = self.list
- self['config'].l.setList(self.list)
- def pressed_ok(self):
- config.plugins.SetClock.HostName.save()
- self.set()
- def set(self, dtt = 0):
- d = time.localtime(self.date_en.value)
- dtt = '%d%02d%02d%02d%02d' % (d.tm_year,
- d.tm_mon,
- d.tm_mday,
- self.time_en.value[0],
- self.time_en.value[1])
- enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
- try:
- system('/bin/date -s %s' % dtt)
- except:
- pass
- self.close()
- print '[SetClock] SET! ** %s' % time.strftime('%X %x (%Y) %Z')
- def inet_set(self):
- config.plugins.SetClock.HostName.save()
- conn = httplib.HTTPConnection(config.plugins.SetClock.HostName.value)
- try:
- conn.request('HEAD', '/favicon.ico')
- t_rtt = time.clock()
- res_time = conn.getresponse().getheader('date')
- except:
- self.session.open(MessageBox, 'Error: No server responce: ' + config.plugins.SetClock.HostName.value, MessageBox.TYPE_ERROR, timeout=3)
- return
- enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(False)
- try:
- system('/bin/date -s %s' % get_time_str(res_time))
- except:
- pass
- self.close()
- print '[SetClock] inet SET! ** %s' % time.strftime('%X %x (%Y) %Z')
- def cancel(self):
- self.close()
- # okay decompyling /tmp/plugin.pyo
- # decompiled 1 files: 1 okay, 0 failed, 0 verify failed
- # 2018.07.29 18:10:27 EAT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement