Ejemplo n.º 1
0
    def exposed_cmd_list(self, *args):
        # don't call this 'exposed_list'!
        c = get_collect(args, allow_collection=True)
        try:
            if c is None:
                for m in all_collect(skip=False):
                    yield m.name,
            elif isinstance(c, Collection):
                if args[-1] == "*":
                    for n, m in c.items():
                        yield n, m
                    return
                for n, m in c.items():
                    try:
                        m = m.info
                    except AttributeError:
                        m = m.name
                    else:
                        if callable(m):
                            m = m()
                        if isinstance(m, six.string_types):
                            m = m.split("\n")[0].strip()

                    if m is not None:
                        yield (n, m)
                    else:
                        yield n,
            else:
                for p, t in flatten((c, )):
                    if isinstance(t, datetime):
                        if TESTING:
                            if t.year != 2003:
                                t = "%s" % (humandelta(t -
                                                       now(t.year != 2003)), )
                            else:
                                t = "%s (%s)" % (
                                    humandelta(t - now(t.year != 2003)), t)
                            ti = t.rfind('.')
                            if ti > 0 and len(t) - ti > 3 and len(
                                    t) - ti < 9:  # limit to msec
                                t = t[:ti + 3] + ")"
                        # otherwise transmit the datetime as-is
                    elif not isinstance(t, (date, time, timedelta)):
                        t = six.text_type(t)

                    yield p, t

        except Exception as e:
            fix_exception(e)
            yield "* ERROR *", repr(e)
            process_failure(e)
Ejemplo n.º 2
0
    def _list(self, args=(), **kw):
        c = get_collect(args, allow_collection=True)
        res = []
        if c is None:
            for m in all_collect(skip=False):
                res.append((m.name, ))
        elif isinstance(c, Collection):
            if args[-1] == "*":
                for n, m in c.items():
                    res.append((n, m))
                return
            for n, m in c.items():
                try:
                    m = m.info
                except AttributeError:
                    m = m.name
                else:
                    if callable(m):
                        m = m()
                    if isinstance(m, str):
                        m = m.split("\n")[0].strip()

                if m is not None:
                    res.append((n, m))
                else:
                    res.append((n, ))
        else:
            q = Queue(3)
            job = spawn(flatten, q, (c, ))
            job.link(lambda _: q.put(None))

            for p, t in flatten((c, )):
                if isinstance(t, datetime):
                    if moat.TESTING:
                        if t.year != 2003:
                            t = "%s" % (humandelta(t - now(t.year != 2003)), )
                        else:
                            t = "%s (%s)" % (
                                humandelta(t - now(t.year != 2003)), t)
                        ti = t.rfind('.')
                        if ti > 0 and len(t) - ti > 3 and len(
                                t) - ti < 9:  # limit to msec
                            t = t[:ti + 3] + ")"
                    # otherwise transmit the datetime as-is
                elif not isinstance(t, (date, time, timedelta)):
                    t = str(t)

                res.append((p, t))
        return res
Ejemplo n.º 3
0
Archivo: rpc.py Proyecto: smurfix/MoaT
	def exposed_cmd_list(self,*args):
		# don't call this 'exposed_list'!
		c = get_collect(args, allow_collection=True)
		try:
			if c is None:
				for m in all_collect(skip=False):
					yield m.name,
			elif isinstance(c,Collection):
				if args[-1] == "*":
					for n,m in c.items():
						yield n,m
					return
				for n,m in c.items():
					try:
						m = m.info
					except AttributeError:
						m = m.name
					else:
						if callable(m):
							m = m()
						if isinstance(m,six.string_types):
							m = m.split("\n")[0].strip()

					if m is not None:
						yield (n,m)
					else:
						yield n,
			else:
				for p,t in flatten((c,)):
					if isinstance(t,datetime):
						if TESTING:
							if t.year != 2003:
								t = "%s" % (humandelta(t-now(t.year != 2003)),)
							else: 
								t = "%s (%s)" % (humandelta(t-now(t.year != 2003)),t)
							ti = t.rfind('.')
							if ti>0 and len(t)-ti > 3 and len(t)-ti<9: # limit to msec
								t= t[:ti+3]+")"
						# otherwise transmit the datetime as-is
					elif not isinstance(t,(date,time,timedelta)):
						t = six.text_type(t)

					yield p,t

		except Exception as e:
				fix_exception(e)
				yield "* ERROR *",repr(e)
				process_failure(e)
Ejemplo n.º 4
0
	def _list(self, args=(), **kw):
		c = get_collect(args, allow_collection=True)
		res = []
		if c is None:
			for m in all_collect(skip=False):
				res.append(( m.name,))
		elif isinstance(c,Collection):
			if args[-1] == "*":
				for n,m in c.items():
					res.append(( n,m ))
				return
			for n,m in c.items():
				try:
					m = m.info
				except AttributeError:
					m = m.name
				else:
					if callable(m):
						m = m()
					if isinstance(m,str):
						m = m.split("\n")[0].strip()

				if m is not None:
					res.append(( n,m ))
				else:
					res.append(( n, ))
		else:
			q = Queue(3)
			job = spawn(flatten,q,(c,))
			job.link(lambda _:q.put(None))

			for p,t in flatten((c,)):
				if isinstance(t,datetime):
					if moat.TESTING:
						if t.year != 2003:
							t = "%s" % (humandelta(t-now(t.year != 2003)),)
						else: 
							t = "%s (%s)" % (humandelta(t-now(t.year != 2003)),t)
						ti = t.rfind('.')
						if ti>0 and len(t)-ti > 3 and len(t)-ti<9: # limit to msec
							t= t[:ti+3]+")"
					# otherwise transmit the datetime as-is
				elif not isinstance(t,(date,time,timedelta)):
					t = str(t)

				res.append(( p,t ))
		return res
Ejemplo n.º 5
0
Archivo: data.py Proyecto: M-o-a-T/moat
		def out_one(c):
			for p,t in flatten((c,)):
				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]+")"

				elif isinstance(t,float):
					ft=float("%.4f"%t)
					if abs(ft-t)<0.00000001:
						t=ft
				print(p+u": "+six.text_type(t), file=self.ctx.out)
Ejemplo n.º 6
0
        def out_one(c):
            for p, t in flatten((c, )):
                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] + ")"

                elif isinstance(t, float):
                    ft = float("%.4f" % t)
                    if abs(ft - t) < 0.00000001:
                        t = ft
                print(p + u": " + six.text_type(t), file=self.ctx.out)