<commit_before>from __future__ import print_function
from __future__ import absolute_import
from Components.config import config, configfile

from Screens.MessageBox import MessageBox

from enigma import eTimer

from .RadioTimesEmulator import RadioTimesEmulator

from time import localtime, time, strftime, mktime

autoScheduleTimer = None


def Scheduleautostart(reason, session=None, **kwargs):
	#
	# This gets called twice at start up,once by WHERE_AUTOSTART without session,
	# and once by WHERE_SESSIONSTART with session. WHERE_AUTOSTART is needed though
	# as it is used to wake from deep standby. We need to read from session so if
	# session is not set just return and wait for the second call to this function.
	#
	# Called with reason=1 during /sbin/shutdown.sysvinit, and with reason=0 at startup.
	# Called with reason=1 only happens when using WHERE_AUTOSTART.
	# If only using WHERE_SESSIONSTART there is no call to this function on shutdown.
	#
	print("[RadioTimesEmulator][Scheduleautostart] reason(%d), session" % reason, session)
	if reason == 0 and session is None:
		return
	global autoScheduleTimer
	global wasScheduleTimerWakeup
	wasScheduleTimerWakeup = False
	now = int(time())
	if reason == 0:
		if config.plugins.RadioTimesEmulator.schedule.value:
			# check if box was woken up by a timer, if so, check if this plugin set this timer. This is not conclusive.
			if session.nav.wasTimerWakeup() and abs(config.plugins.RadioTimesEmulator.nextscheduletime.value - time()) <= 360:
				wasScheduleTimerWakeup = True
				# if box is not in standby do it now
				from Screens.Standby import Standby, inStandby
				if not inStandby:
					# hack alert: session requires "pipshown" to avoid a crash in standby.py
					if not hasattr(session, "pipshown"):
						session.pipshown = False
					from Tools import Notifications
					Notifications.AddNotificationWithID("Standby", Standby)

		print("[RadioTimesEmulator][Scheduleautostart] AutoStart Enabled")
		if autoScheduleTimer is None:
			autoScheduleTimer = AutoScheduleTimer(session)
	else:
		print("[RadioTimesEmulator][Scheduleautostart] Stop")
		if autoScheduleTimer is not None:
			autoScheduleTimer.schedulestop()


class AutoScheduleTimer:
	instance = None

	def __init__(self, session):
		self.schedulename = "RadioTimesEmulator"
		self.config = config.plugins.RadioTimesEmulator
		self.itemtorun = RadioTimesEmulator
		self.session = session
		self.scheduletimer = eTimer()
		self.scheduletimer.callback.append(self.ScheduleonTimer)
		self.scheduleactivityTimer = eTimer()
		self.scheduleactivityTimer.timeout.get().append(self.scheduledatedelay)
		self.ScheduleTime = 0
		now = int(time())
		if self.config.schedule.value:
			print("[%s][AutoScheduleTimer] Schedule Enabled at " % self.schedulename, strftime("%c", localtime(now)))
			if now > 1546300800:  # Tuesday, January 1, 2019 12:00:00 AM
				self.scheduledate()
			else:
				print("[%s][AutoScheduleTimer] STB clock not yet set." % self.schedulename)
				self.scheduleactivityTimer.start(36000)
		else:
			print("[%s][AutoScheduleTimer] Schedule Disabled at" % self.schedulename, strftime("%c", localtime(now)))
			self.scheduleactivityTimer.stop()

		assert AutoScheduleTimer.instance is None, "class AutoScheduleTimer is a singleton class and just one instance of this class is allowed!"
		AutoScheduleTimer.instance = self

	def __onClose(self):
		AutoScheduleTimer.instance = None

	def scheduledatedelay(self):
		self.scheduleactivityTimer.stop()
		self.scheduledate()

	def getScheduleTime(self):
		now = localtime(time())
		return int(mktime((now.tm_year, now.tm_mon, now.tm_mday, self.config.scheduletime.value[0], self.config.scheduletime.value[1], 0, now.tm_wday, now.tm_yday, now.tm_isdst)))

	def getScheduleDayOfWeek(self):
		today = self.getToday()
		for i in range(1, 8):
			if self.config.days[(today + i)%7].value:
				return i

	def getToday(self):
		return localtime(time()).tm_wday

	def scheduledate(self, atLeast=0):
		self.scheduletimer.stop()<commit_msg>update PEP8 - E228 missing whitespace around modulo operator<commit_after>from __future__ import print_function
from __future__ import absolute_import
from Components.config import config, configfile

from Screens.MessageBox import MessageBox

from enigma import eTimer

from .RadioTimesEmulator import RadioTimesEmulator

from time import localtime, time, strftime, mktime

autoScheduleTimer = None


def Scheduleautostart(reason, session=None, **kwargs):
	#
	# This gets called twice at start up,once by WHERE_AUTOSTART without session,
	# and once by WHERE_SESSIONSTART with session. WHERE_AUTOSTART is needed though
	# as it is used to wake from deep standby. We need to read from session so if
	# session is not set just return and wait for the second call to this function.
	#
	# Called with reason=1 during /sbin/shutdown.sysvinit, and with reason=0 at startup.
	# Called with reason=1 only happens when using WHERE_AUTOSTART.
	# If only using WHERE_SESSIONSTART there is no call to this function on shutdown.
	#
	print("[RadioTimesEmulator][Scheduleautostart] reason(%d), session" % reason, session)
	if reason == 0 and session is None:
		return
	global autoScheduleTimer
	global wasScheduleTimerWakeup
	wasScheduleTimerWakeup = False
	now = int(time())
	if reason == 0:
		if config.plugins.RadioTimesEmulator.schedule.value:
			# check if box was woken up by a timer, if so, check if this plugin set this timer. This is not conclusive.
			if session.nav.wasTimerWakeup() and abs(config.plugins.RadioTimesEmulator.nextscheduletime.value - time()) <= 360:
				wasScheduleTimerWakeup = True
				# if box is not in standby do it now
				from Screens.Standby import Standby, inStandby
				if not inStandby:
					# hack alert: session requires "pipshown" to avoid a crash in standby.py
					if not hasattr(session, "pipshown"):
						session.pipshown = False
					from Tools import Notifications
					Notifications.AddNotificationWithID("Standby", Standby)

		print("[RadioTimesEmulator][Scheduleautostart] AutoStart Enabled")
		if autoScheduleTimer is None:
			autoScheduleTimer = AutoScheduleTimer(session)
	else:
		print("[RadioTimesEmulator][Scheduleautostart] Stop")
		if autoScheduleTimer is not None:
			autoScheduleTimer.schedulestop()


class AutoScheduleTimer:
	instance = None

	def __init__(self, session):
		self.schedulename = "RadioTimesEmulator"
		self.config = config.plugins.RadioTimesEmulator
		self.itemtorun = RadioTimesEmulator
		self.session = session
		self.scheduletimer = eTimer()
		self.scheduletimer.callback.append(self.ScheduleonTimer)
		self.scheduleactivityTimer = eTimer()
		self.scheduleactivityTimer.timeout.get().append(self.scheduledatedelay)
		self.ScheduleTime = 0
		now = int(time())
		if self.config.schedule.value:
			print("[%s][AutoScheduleTimer] Schedule Enabled at " % self.schedulename, strftime("%c", localtime(now)))
			if now > 1546300800:  # Tuesday, January 1, 2019 12:00:00 AM
				self.scheduledate()
			else:
				print("[%s][AutoScheduleTimer] STB clock not yet set." % self.schedulename)
				self.scheduleactivityTimer.start(36000)
		else:
			print("[%s][AutoScheduleTimer] Schedule Disabled at" % self.schedulename, strftime("%c", localtime(now)))
			self.scheduleactivityTimer.stop()

		assert AutoScheduleTimer.instance is None, "class AutoScheduleTimer is a singleton class and just one instance of this class is allowed!"
		AutoScheduleTimer.instance = self

	def __onClose(self):
		AutoScheduleTimer.instance = None

	def scheduledatedelay(self):
		self.scheduleactivityTimer.stop()
		self.scheduledate()

	def getScheduleTime(self):
		now = localtime(time())
		return int(mktime((now.tm_year, now.tm_mon, now.tm_mday, self.config.scheduletime.value[0], self.config.scheduletime.value[1], 0, now.tm_wday, now.tm_yday, now.tm_isdst)))

	def getScheduleDayOfWeek(self):
		today = self.getToday()
		for i in range(1, 8):
			if self.config.days[(today + i) %7].value:
				return i

	def getToday(self):
		return localtime(time()).tm_wday

	def scheduledate(self, atLeast=0):
		self.scheduletimer.stop()
{'fraction_non_alphanumeric': 0.09101040118870728, 'fraction_numerical': 0.010896483407627538, 'mean_word_length': 4.874181818181818, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7310636', 'n_tokens_mistral': 2732, 'n_tokens_neox': 2448, 'n_words': 733}