-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgears.py
78 lines (62 loc) · 2.24 KB
/
gears.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import redis
import click
import os
class Colors(object):
@staticmethod
def Cyan(data):
return '\033[36m' + data + '\033[0m'
@staticmethod
def Yellow(data):
return '\033[33m' + data + '\033[0m'
@staticmethod
def Bold(data):
return '\033[1m' + data + '\033[0m'
@staticmethod
def Bred(data):
return '\033[31;1m' + data + '\033[0m'
@staticmethod
def Gray(data):
return '\033[30;1m' + data + '\033[0m'
@staticmethod
def Lgray(data):
return '\033[30;47m' + data + '\033[0m'
@staticmethod
def Blue(data):
return '\033[34m' + data + '\033[0m'
@staticmethod
def Green(data):
return '\033[32m' + data + '\033[0m'
@click.group()
def rghibernate():
pass
def create_connection(host, port, password, decode_responses=True):
global args
try:
r = redis.Redis(host, port, password=password, decode_responses=decode_responses)
r.ping()
except Exception as e:
print(Colors.Bred('Cannot connect to Redis. Aborting (%s)' % str(e)))
exit(1)
return r
@rghibernate.command(help='Upload rghibernate recipe to RedisGears (MAPPING is a list of xml mappings in hibernate format)')
@click.option('--host', default='localhost', help='Redis host to connect to')
@click.option('--port', default=6379, type=int, help='Redis port to connect to')
@click.option('--password', default=None, help='Redis password')
@click.option('--rghibernate-jar', default='./target/rghibernate-0.0.3-SNAPSHOT-jar-with-dependencies.jar', help='Path to rghibernate jar file')
def upload_recipe(host, port, password, rghibernate_jar):
conn = create_connection(host, port, password)
if not os.path.exists(rghibernate_jar):
print(Colors.Bred('rghibernate jar file does not exists'))
exit(1)
with open(rghibernate_jar, 'rb') as f:
data = f.read()
try:
res = conn.execute_command('rg.jexecute', 'com.redislabs.WriteBehind', data)
except Exception as e:
print(Colors.Bred('Failed executing jexecute command. Aborting (%s)' % str(e).replace('|', '\n')))
exit(1)
print(Colors.Green(res))
def main():
rghibernate()
if __name__ == '__main__':
rghibernate()