Example #1
0
File: cmd.py Project: pombreda/MoaT
	def getter(q):
		if TESTING:
			now = c.root.now
		else:
			def now(x):
				return c.root.now()
		while True:
			res = q.get()
			if res is None:
				return
			p,t = res
			if isinstance(t,datetime):
				if TESTING and t.year != 2003:
					t = "%s" % (humandelta(t-now(t.year != 2003)),)
				else:
					t = "%s (%s)" % (humandelta(t-now(t.year != 2003)),t)
				if TESTING:
					lim = 3
				else:
					lim = 4
				ti = t.rfind('.')
				if ti>0 and len(t)-ti>lim and len(t)-ti<lim+6: # limit to msec
					t = t[:ti+lim]+")"

			print(p+u": "+unicode(t))
Example #2
0
	def list(self):
		n=now()
		yield ("type",self.type)
		yield ("name"," ".join(unicode(x) for x in self.name))
		if self.state is not None:
			yield ("state",self.names[self.state])
		if self._value is not None:
			yield ("current",self._value)
		if self.last is not None:
			yield ("last",self.last)
		if self.next is not None:
			yield ("next",self.next)
		if self.t_off is not None:
			yield ("t_off",humandelta(self.t_off))
		if self.t_on is not None:
			yield ("t_on",humandelta(self.t_on))
Example #3
0
	def list(self):
		yield super(Waiter,self)
		yield("start",self.start)
		if self._plinger:
			end=now()+dt.timedelta(0,self.value)
			yield("end",end)
			yield("total", humandelta(end-self.start))
		w = self
		while True:
			w = getattr(w,"parent",None)
			if w is None: break
			n = getattr(w,"displayname",None)
			if n is not None:
				if not isinstance(n,basestring):
					n = " ".join(unicode(x) for x in n)
			else:
				try:
					if w.args:
						n = unicode(w.args)
				except AttributeError:
					pass
				if n is None:
					try:
						if isinstance(w.name,basestring):
							n = w.name
						else:
							n = " ".join(unicode(x) for x in w.name)
					except AttributeError:
						n = w.__class__.__name__
			if n is not None:
				yield("in",n)
Example #4
0
	def list(self):
		for r in super(DecayTimeAvg,self).list():
			yield r
		yield ("weight",self.p)
		yield ("time base",humandelta(self.p_base))
		yield ("weight/hour",1-(1-self.p)**(3600/self.p_base))
		yield ("weight/minute",1-(1-self.p)**(60/self.p_base))
		yield ("weight/second",1-(1-self.p)**(1/self.p_base))
Example #5
0
	def report(self, verbose=False):
		if self.name:
			yield "WORK: "+self.name
		if self.id:
			yield "id: "+str(self.id)
		yield "call count: "+str(self.call_count)
		if self.last_call:
			yield "last call: %s (%s)" % (humandelta(now()-self.last_call),self.last_call)
		if self.last_args:
			for a,b in self.last_args.iteritems():
				yield "last %s: %s" % (a,b)
Example #6
0
	def time_name(self):
		if self.started_at is None:
			return "never"
		if not self.running.is_set():
			delta = now() - self.started_at
		elif self.job:
			delta = self.started_at - now()
		else:
			delta = now() - self.started_at
		delta = unixdelta(delta)
		res = humandelta(delta)

		return u"‹"+res+"›"
Example #7
0
	def info(self):
		if self.last is not None:
			return "%s %d: %s" % (em_procs[self.group].em_name, self.code,
				humandelta(self.last-now()))
		else:
			return "%s %d: (never)" % (em_procs[self.group].em_name, self.code)
Example #8
0
	def info(self):
		if self.last_sent_at is None:
			return "Never"
		return humandelta(now()-self.last_sent_at)
Example #9
0
	def info(self):
		if self._value is None or self.t_on is None:
			return "(new)"
		return "%.3f %s / %s" % (self._value,humandelta(self.t_on),humandelta(self.t_off))
Example #10
0
	def _run_schedule(self):
		if self.sched_job is not None:
			self.sched_job.kill()
			self.sched_job = None
		if self.locked:
			if self.v.verbose:
				print >>sys.stderr,"SCHED LOCKED2 %s" % (self.v.name,)
			return
		n = now()

		try:
			if self.sched is not None:
				self.sched.refresh()
				if self.sched.start+self.sched.duration <= n:
					self._off()
					self.sched = None
				else:
					self.sched_job = gevent.spawn_later((self.sched.start+self.sched.duration-n).total_seconds(),self.run_sched_task,reason="_run_schedule 1")
					if self.v.verbose:
						print >>sys.stderr,"SCHED LATER %s: %s" % (self.v.name,humandelta(self.sched.start+self.sched.duration-n))
					return
		except ObjectDoesNotExist:
			pass # somebody deleted it *shrug*
		sched = None

		if self.sched_ts is None:
			try:
				sched = self.v.schedules.filter(start__lt=n).order_by("-start")[0]
			except IndexError:
				self.sched_ts = n-timedelta(1,0)
			else:
				self.sched_ts = sched.start+sched.duration
				if sched.start+sched.duration > n: # still running
					if self.v.verbose:
						print >>sys.stderr,"SCHED RUNNING %s: %s" % (self.v.name,humandelta(sched.start+sched.duration-n))
					try:
						self._on(sched, sched.start+sched.duration-n)
					except TooManyOn:
						self.log("Could not schedule: too many open valves")
					except NotConnected:
						self.log("Could not schedule: connection to HomEvenT failed")
					return

		try:
			sched = self.v.schedules.filter(start__gte=self.sched_ts).order_by("start")[0]
		except IndexError:
			if self.v.verbose:
				print >>sys.stderr,"SCHED EMPTY %s: %s" % (self.v.name,str_tz(self.sched_ts))
			self._off()
			return

		if sched.start > n:
			if self.v.verbose:
				print >>sys.stderr,"SCHED %s: sched %d in %s" % (self.v.name,sched.id,humandelta(sched.start-n))
			self._off()
			self.sched_job = gevent.spawn_later((sched.start-n).total_seconds(),self.run_sched_task,reason="_run_schedule 2")
			return
		try:
			self._on(sched)
		except TooManyOn:
			self.log("Could not schedule: too many open valves")
		except NotConnected:
			self.log("Could not schedule: connection to HomEvenT failed")