def clean(args): try: Eris.getProxy().status() print >> sys.stderr, "eris must be stopped" except Pyro4.errors.PyroError: try: print "storage deleted" os.remove(Storage.dbFile()) except: pass
def count(args): try: proxy = Eris.getProxy() c = proxy.count() print "{} packets in storage".format(c) except Pyro4.errors.PyroError: print >> sys.stderr, "eris not available"
def status(args=None): def printStatus(statusFile, pid=None, cpu=None, mem=None, uptime=None, du=None): status = ( color("WORKING", "green") if statusFile and pid else color("NOT WORKING", "red") if not statusFile and pid is None else color("UNKNOWN", "red") ) print "Status: " + status if pid: print " PID: {}".format(pid) print " CPU: {:.1f}%".format(cpu) print " MEM: {:.1f}%".format(mem) print " Storage: {} KiB".format(du) print " Up-time: {}".format(str(timedelta(uptime.days, uptime.seconds, 0))) statusFile = False try: with open(config.statusFile, "r") as f: statusFile = f.read() == config.STATUS_LINE except: pass try: (pid, cpu, mem, uptime, du) = Eris.getProxy().status() printStatus(statusFile, pid, cpu, mem, uptime, du) except Pyro4.errors.PyroError: printStatus(statusFile)
def get(args): try: proxy = Eris.getProxy() packets = proxy.get(args.since, 0, args.limit) print "<packets>" for p in packets: print '<packet timestamp="{}">\n{}\n</packet>'.format(p[0], " " + p[1].replace("\n", "\n ")) print "</packets>" except Pyro4.errors.PyroError: print >> sys.stderr, "eris not available"
def put(args): try: data = open(args.file, "r").read() if args.file else sys.stdin.read() packets = [(args.timestamp, data)] proxy = Eris.getProxy() proxy.put(packets) except IOError as e: print >> sys.stderr, e except Pyro4.errors.PyroError: print >> sys.stderr, "eris not available"
def start(args): Eris().start() proxy = Eris.getProxy() for _ in range(STATUS_RETRIES): try: if proxy.ping() == config.PNAME: break except Pyro4.errors.CommunicationError: time.sleep(SLEEP_PERIOD) status()
def stop(args): proxy = Eris.getProxy() try: proxy.stop() except Pyro4.errors.CommunicationError: pass for _ in range(STATUS_RETRIES): try: if proxy.ping() != config.PNAME: break time.sleep(SLEEP_PERIOD) except Pyro4.errors.CommunicationError: break status() try: with open(config.statusFile, "w"): pass except: pass