Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
#!/usr/bin/python
# -*- coding: utf-8 -*-

from Plugins.Plugin import PluginDescriptor
from Components.config import config

from UpdateCheck import reload_value
from enigma import eTimer
from datetime import datetime, timedelta

import UpdateCheck

VERSION = "1.0-r2"

session = None
updateTimer = None
updateTimer_conn = None

def leaveStandbyUDC():
	global updateTimer
	global updateTimer_conn
	
	if session and session.shutdown:
		print "[UpdateCheck] aus standby aufgewacht - shutdown"
		return

	try:
		if config.plugins.updatecheck.enable_autocheck.value != "False":
			print "[UpdateCheck] aus standby aufgewacht - runUpdateCheck after %s seconds..." % config.plugins.updatecheck.updatecheck_delay.value
			updateTimer = eTimer()
			updateTimer_conn = updateTimer.timeout.connect(startUpdateCheck)
			updateTimer.start(int(config.plugins.updatecheck.updatecheck_delay.value)*1000)
		else:
			print "[UpdateCheck] aus standby aufgewacht - kein AutoUpdateCheck aktiviert"

	except:
		import traceback
		traceback.print_exc()

def standbyCounterChangedUDC(configElement):
	
	print "[UpdateCheck] gehe in standby..."
	from Screens.Standby import inStandby
	inStandby.onClose.append(leaveStandbyUDC)

def startUpdateCheck():
	global updateTimer
	global updateTimer_conn
	global session
	
	#print "=====[UpdateCheck] start UpdateCheck ..."
	updateTimer_conn = None
	updateTimer = None
	
	#check for next interval
	if config.plugins.updatecheck.autoCheck_interval.value != "0":
		lastcheck = int(config.plugins.updatecheck.lastAutoCheck.value)
		
		#calculate the time for next updateCheck
		if config.plugins.updatecheck.autoCheck_interval.value == "1":
			nextcheck = datetime.fromtimestamp(lastcheck) + timedelta(hours=1)
		elif config.plugins.updatecheck.autoCheck_interval.value == "2":
			nextcheck = datetime.fromtimestamp(lastcheck) + timedelta(hours=6)
		elif config.plugins.updatecheck.autoCheck_interval.value == "3":
			nextcheck = datetime.fromtimestamp(lastcheck) + timedelta(hours=12)
		elif config.plugins.updatecheck.autoCheck_interval.value == "4":
			nextcheck = datetime.fromtimestamp(lastcheck) + timedelta(days=1)
		elif config.plugins.updatecheck.autoCheck_interval.value == "5":
			nextcheck = datetime.fromtimestamp(lastcheck) + timedelta(weeks=1)
		else:
			next_month = datetime.fromtimestamp(lastcheck).replace(day=28) + timedelta(days=4)  # goto next month
			nextcheck = next_month.replace(day=datetime.fromtimestamp(lastcheck).day) # reset day in the next month date
		
		if datetime.now() < nextcheck: #no AutoUpdateCheck - wait for next interval
			print "[UpdateCheck] don't startUpdateCheck, wait for next interval:", nextcheck
			return
	
	
	
	if reload_value:
		reload(UpdateCheck)
	from UpdateCheck import updatecheck as checkupdate
	checkupdate(session)

def sessionstart(reason, **kwargs):
	global session
	global updateTimer
	global updateTimer_conn
	if kwargs.has_key("session") and reason == 0:
		session = kwargs["session"]
		#== add to set function at restart from standby
		config.misc.standbyCounter.addNotifier(standbyCounterChangedUDC, initial_call = False)
		
		if config.plugins.updatecheck.enable_autocheck.value != "False":			
			print "[UpdateCheck] sessionstart - runUpdateCheck after %s seconds:" % config.plugins.updatecheck.updatecheck_delay.value
			updateTimer = eTimer()
			updateTimer_conn = updateTimer.timeout.connect(startUpdateCheck)
			updateTimer.start(int(config.plugins.updatecheck.updatecheck_delay.value)*1000)
		else:
			print "[UpdateCheck] sessionstart - kein AutoUpdateCheck aktiviert"

	else:
		print "[UpdateCheck] sessionstart ohne session...."
		pass

def setup(session, **kwargs):
	if reload_value:
		reload(UpdateCheck)
	from UpdateCheck import UpdateCheckSetup
	session.open(UpdateCheckSetup)

def extmenusetup(session, **kwargs):
	setup(session, **kwargs)

def checkupdate(session, **kwargs):
	if reload_value:
		reload(UpdateCheck)
	from UpdateCheck import UpdateScreen
	session.open(UpdateScreen)

extMenuDescriptor = PluginDescriptor(name =_("UpdateCheck"), description=_("Check for Feed-Updates")+ " (" + VERSION + ")", where = [PluginDescriptor.WHERE_EXTENSIONSMENU], fnc = checkupdate, needsRestart = False, icon = "UpdateCheck.png")

pbrowserSetupDescriptor = PluginDescriptor(name =_("UpdateCheck Setup"), description=_("Check for Feed-Updates")+ " (" + VERSION + ")", where = [PluginDescriptor.WHERE_PLUGINMENU], fnc = setup, needsRestart = False, icon = "UpdateCheck.png")

extMenuSetupDescriptor = PluginDescriptor(name =_("UpdateCheck Setup"), description=_("Check for Feed-Updates")+ " (" + VERSION + ")", where = [PluginDescriptor.WHERE_EXTENSIONSMENU], fnc = extmenusetup, needsRestart = False, icon = "UpdateCheck.png")

def Plugins(**kwargs):

	descriptors = []
	descriptors.append( PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART], fnc=sessionstart) )
	if config.plugins.updatecheck.show_setup.value in ("pbrowser","both"):
		descriptors.append(pbrowserSetupDescriptor)
	if config.plugins.updatecheck.show_setup.value in ("extmenu","both"):
		descriptors.append(extMenuSetupDescriptor)
	if config.plugins.updatecheck.show_extmenu.value:
		descriptors.append(extMenuDescriptor)

	return descriptors