-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_config.py
More file actions
43 lines (34 loc) · 868 Bytes
/
base_config.py
File metadata and controls
43 lines (34 loc) · 868 Bytes
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
#!/usr/bin/env python
import os
import sys
import krpc
from ConfigParser import ConfigParser
version = 0.1
cfg_file = "kvsw.config"
connect_name = "kVSW"
def begin(client=connect_name):
""" Returns the krpc connection object """
cf = ConfigParser()
try:
cf.readfp(open(cfg_file))
except Exception:
print("Error opening config file")
sys.exit(1)
try:
server = cf.get("krpc", "server")
port = int(cf.get("krpc", "port"))
stream_port = port+1
except Exception:
print("Error reading the server from " + cfg_file + ". Is the format correct?")
sys.exit(1)
conn = krpc.connect(
client + " " + str(version),
address = server,
rpc_port=port,
stream_port=stream_port)
return conn
def end(conn):
""" Closes conection """
conn.close()
def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")