예제 #1
0
	def start(self):
		# initially we're running but not counting
		self.timer_service.pause()
		self.timer_service.start()
		#self.session_service.start()
		#self.input_service.start()

		while True:
			try:
				sleep(1)
			except KeyboardInterrupt:
				info ("\nStopping!")
				self.timer_service.stop()
				break
예제 #2
0
	def timer_alert(self):
		info ("timer alert!")

		result = self.ui_service.get_input()
		if Results.TIMEOUT == result:
			info ("timeout")
		elif Results.SHUTDOWN == result:
			info ("shutdown")
		else:
			ext = datetime.now().replace(hour=0, minute=result, second=0, microsecond=0)
			self.timer_service.extension = ext

		self.timer_service.activate_alerts()
예제 #3
0
	def active(self):
		info ("active!")
		self.timer_service.resume()
예제 #4
0
	def inactive(self):
		info ("inactive!")
		self.timer_service.pause()
예제 #5
0
	def logout(self):
		info ("logout!")
		self.timer_service.pause()
예제 #6
0
	def login(self):
		info ("login!")
		self.timer_service.resume()
예제 #7
0
	def load_config(self):
		f = open(self.config_file, 'r')
		content = f.read()
		f.close()

		# load the daily contingent
		m = re.search('dailyContingent\s*=\s*(\d+)h(\d+)m', content)
		self.dailyContingent = datetime.time(int(m.group(1)), int(m.group(2)))
		info ("Daily contingent: %s" % self.dailyContingent)

		# load the password timeout
		m = re.search('pwTimeout\s*=\s*(\d+)', content)
		self.timeout = int(m.group(1))
		info ("Password timeout: %s minutes" % self.timeout)
		
		# load the password
		m = re.search('password\s*=\s*(.+)', content)
		self.password = m.group(1)
		info ("Password: %s" % "*****")

		# load the lock times
		self.get_lock_times(content)
		info ("Lock times:")
		for tme in self.lock_times:
			info ("  %s" % tme)
		info ("")
예제 #8
0
	def tick(self):
		info ("TICK")

		# calculate the passed time
		diff = datetime.datetime.now() - self.last_tick

		# count down the extension if any
		if self.extension:
			new_ext = self.extension - diff
			if new_ext.date() != self.extension.date():
				self.extension = None
				info ("Extension exhausted!")
			else:
				self.extension = new_ext
				debug ("Extension: %s" % self.extension.time())
		else:
			info ("No extension")

    # if we're paused, we don't send any alerts and don't count the usage
		if self.paused:
			return

		# increment the usage time
		# if the new usage is at a new date -> set the usage to 0
		new_usage = self.usage + diff
		if new_usage.date() != self.usage.date():
			debug ("usage has crossed the date border -> setting it to 0")
			self.usage = datetime.datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
		else:
			self.usage = new_usage

		info ("Usage: %s" % new_usage.time())

		# remember the last time of increment
		self.last_tick = datetime.datetime.now()

		# if we're not supposed to send alerts, we're done here
		if not self.send_alerts:
			debug ("Alerts are deactivated")
			return

		# if we're running on an extension, we're done here
		if self.extension:
			debug ("We're in an extension, don't send any alerts")
			return

		alert = False
		# if the usage exceeds the daily contingent -> timer_alert
		if self.usage.time() > self.config_service.dailyContingent:
			info ("Usage exceeds the daily contingent!")
			alert = True

		# if there's no contingent related alert -> check lock times
		if not alert:
			for tme in self.config_service.lock_times:
				if tme.is_in(datetime.datetime.now().time()):
					info ("We are in a locked timeslice!")
					alert = True
					break

		# execute timer alert if necessary
		if alert:
			self.deactivate_alerts()
			start_new_thread(self.callback.timer_alert, ())
		info ("END OF TICK")