-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstable-cli
More file actions
executable file
·49 lines (35 loc) · 1.18 KB
/
stable-cli
File metadata and controls
executable file
·49 lines (35 loc) · 1.18 KB
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
#!/usr/bin/env python3
# Copyright (c) 2020 Jarret Dyrbye
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php
import os
import sys
from configparser import ConfigParser
from twisted.internet import reactor
from txjsonrpc.web.jsonrpc import Proxy
from stable.cmd_parse import StabledCmdParse
CONFIG_FILE = os.path.join(os.path.expanduser("~"),
".stabled/stabled.conf")
if not os.path.exists(CONFIG_FILE):
sys.exit("*** could not find %s" % CONFIG_FILE)
config = ConfigParser()
config.read(CONFIG_FILE)
rpc_interface = config['Rpc']['ExternalHost']
rpc_port = int(config['Rpc']['ExternalPort'])
URL = "http://%s:%d" % (rpc_interface, rpc_port)
def printValue(value):
print(value)
def printError(error):
print("*** - %s" % error.getErrorMessage())
def shutDown(data):
reactor.stop()
proxy = Proxy(URL)
parser = StabledCmdParse.get_parser()
if len(sys.argv) == 1:
parser.print_help()
sys.exit(-1)
parsed = parser.parse_args()
cmd = sys.argv[1]
d = proxy.callRemote(cmd, sys.argv[2:])
d.addCallback(printValue).addErrback(printError).addBoth(shutDown)
reactor.run()