[enh] adds clitools
This commit is contained in:
parent
0e9e7717c9
commit
249932a9dd
5 changed files with 519 additions and 0 deletions
55
clitools/exports/toRedis.py
Executable file
55
clitools/exports/toRedis.py
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- mode: Python -*-
|
||||
|
||||
|
||||
'''
|
||||
|
||||
redis exporter
|
||||
v0.1.0
|
||||
|
||||
A basic exporter
|
||||
|
||||
LICENCE : CC
|
||||
|
||||
by cocoa
|
||||
|
||||
|
||||
'''
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import redis
|
||||
import time
|
||||
|
||||
argsparser = argparse.ArgumentParser(description="Redis exporter LJ")
|
||||
argsparser.add_argument("-i","--ip",help="IP address of the Redis server ",default="127.0.0.1",type=str)
|
||||
argsparser.add_argument("-p","--port",help="Port of the Redis server ",default="6379",type=str)
|
||||
argsparser.add_argument("-k","--key",help="Redis key to update",default="0",type=int)
|
||||
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose")
|
||||
args = argsparser.parse_args()
|
||||
|
||||
ip = args.ip
|
||||
port = args.port
|
||||
key = args.key
|
||||
verbose=args.verbose
|
||||
|
||||
def debug(*args, **kwargs):
|
||||
if( verbose == False ):
|
||||
return
|
||||
print(*args, file=sys.stderr, **kwargs)
|
||||
|
||||
r=redis.StrictRedis(host=ip, port=port, db=0)
|
||||
|
||||
try:
|
||||
while True:
|
||||
line = sys.stdin.readline()
|
||||
if line == "":
|
||||
time.sleep(0.01)
|
||||
line = line.rstrip('\n')
|
||||
if r.set(key,line)==True:
|
||||
debug("exports::redis set("+str(key)+") to "+line)
|
||||
except EOFError:
|
||||
debug("break")# no more information
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue