Exemplo n.º 1
0
Arquivo: data.py Projeto: M-o-a-T/moat
	def run(self,ctx,**k):
		event = self.params(ctx)
		if not event:
			for m in all_collect("del"):
				print(" ".join(m.name), file=self.ctx.out)
			print(".", file=self.ctx.out)
			return
		c = get_collect(event)
		if c is None:
			raise SyntaxError(u"Usage: del ‹type› ‹name…›")
		if not hasattr(c,"delete"):
			raise SyntaxError(u"You cannot delete those items.")
		return c.delete(ctx)
Exemplo n.º 2
0
 def run(self, ctx, **k):
     event = self.params(ctx)
     if not event:
         for m in all_collect("del"):
             print(" ".join(m.name), file=self.ctx.out)
         print(".", file=self.ctx.out)
         return
     c = get_collect(event)
     if c is None:
         raise SyntaxError(u"Usage: del ‹type› ‹name…›")
     if not hasattr(c, "delete"):
         raise SyntaxError(u"You cannot delete those items.")
     return c.delete(ctx)
Exemplo n.º 3
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)
Exemplo 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
Exemplo n.º 5
0
Arquivo: rpc.py Projeto: 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)
Exemplo n.º 6
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
Exemplo n.º 7
0
Arquivo: data.py Projeto: M-o-a-T/moat
	def run(self,ctx,**k):

		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)

		event = self.params(ctx)
		c = get_collect(event, allow_collection=True)

		try:
			if c is None:
				for m in all_collect(skip=False):
					print(" ".join(m.name), file=self.ctx.out)
			elif isinstance(c,Collection):
				if event[-1] == "*":
					for m in c.items():
						print("* %s :: %s" % (n,m), file=self.ctx.out)
						out_one(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 isinstance(n,Name):
						n = u" ".join(six.text_type(x) for x in n)
					if m is not None:
						print(u"%s :: %s" % (n,m), file=self.ctx.out)
					else:
						print(u"%s" % (n,), file=self.ctx.out)
			else:
				out_one(c)

		except Exception as e:
			fix_exception(e)
			print("* ERROR *",repr(e), file=self.ctx.out)
			print_exception(e,file=self.ctx.out)
		finally:
			print(".", file=self.ctx.out)
Exemplo n.º 8
0
    def run(self, ctx, **k):
        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)

        event = self.params(ctx)
        c = get_collect(event, allow_collection=True)

        try:
            if c is None:
                for m in all_collect(skip=False):
                    print(" ".join(m.name), file=self.ctx.out)
            elif isinstance(c, Collection):
                if event[-1] == "*":
                    for m in c.items():
                        print("* %s :: %s" % (n, m), file=self.ctx.out)
                        out_one(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 isinstance(n, Name):
                        n = u" ".join(six.text_type(x) for x in n)
                    if m is not None:
                        print(u"%s :: %s" % (n, m), file=self.ctx.out)
                    else:
                        print(u"%s" % (n, ), file=self.ctx.out)
            else:
                out_one(c)

        except Exception as e:
            fix_exception(e)
            print("* ERROR *", repr(e), file=self.ctx.out)
            print_exception(e, file=self.ctx.out)
        finally:
            print(".", file=self.ctx.out)