-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader-rgs.py
31 lines (25 loc) · 931 Bytes
/
loader-rgs.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
# RedisEdge initialization script - RG scripts loader
import argparse
import os
from urllib.parse import urlparse
import redis
if __name__ == '__main__':
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--url', help='Redis URL', type=str, default='redis://localhost:6379')
args = parser.parse_args()
# Set up Redis connection
url = urlparse(args.url)
conn = redis.Redis(host=url.hostname, port=url.port)
if not conn.ping():
raise Exception('Redis unavailable')
# Load the gears
print('Loading gears - ', end='')
dir_path = r'./'
for file in os.listdir(dir_path):
if file.startswith('rg-'):
with open(file, 'rb') as f:
gear = f.read()
res = conn.execute_command('RG.PYEXECUTE', gear, 'REQUIREMENTS', 'kats')
print(res)
print('Flag initialization as done - ', end='')