2016-07-06 08:17:38 +02:00
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
|
2016-08-08 22:42:35 +02:00
|
|
|
from lbrynet.conf import API_CONNECTION_STRING
|
2016-07-06 08:17:38 +02:00
|
|
|
from jsonrpc.proxy import JSONRPCProxy
|
|
|
|
|
2016-08-20 04:12:02 +02:00
|
|
|
help_msg = "Usage: lbrynet-cli method json-args\n" \
|
2016-07-06 09:02:55 +02:00
|
|
|
+ "Examples: " \
|
|
|
|
+ "lbrynet-cli resolve_name '{\"name\": \"what\"}'\n" \
|
|
|
|
+ "lbrynet-cli get_balance\n" \
|
|
|
|
+ "lbrynet-cli help '{\"function\": \"resolve_name\"}'\n" \
|
|
|
|
+ "\n******lbrynet-cli functions******\n"
|
|
|
|
|
2016-07-06 08:17:38 +02:00
|
|
|
|
|
|
|
def main():
|
2016-07-06 08:20:18 +02:00
|
|
|
api = JSONRPCProxy.from_url(API_CONNECTION_STRING)
|
|
|
|
|
|
|
|
try:
|
|
|
|
s = api.is_running()
|
|
|
|
except:
|
|
|
|
print "lbrynet-daemon isn't running"
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-07-06 08:17:38 +02:00
|
|
|
args = sys.argv[1:]
|
|
|
|
meth = args[0]
|
2016-07-06 09:02:55 +02:00
|
|
|
|
|
|
|
msg = help_msg
|
|
|
|
for f in api.help():
|
|
|
|
msg += f + "\n"
|
|
|
|
|
|
|
|
if meth in ['--help', '-h', 'help']:
|
|
|
|
print msg
|
|
|
|
sys.exit(1)
|
|
|
|
|
2016-07-06 08:17:38 +02:00
|
|
|
if len(args) > 1:
|
|
|
|
if isinstance(args[1], dict):
|
|
|
|
params = args[1]
|
2016-07-14 05:44:02 +02:00
|
|
|
elif isinstance(args[1], basestring):
|
2016-07-06 08:17:38 +02:00
|
|
|
params = json.loads(args[1])
|
|
|
|
else:
|
|
|
|
params = None
|
|
|
|
|
|
|
|
if meth in api.help():
|
2016-07-06 09:02:55 +02:00
|
|
|
try:
|
|
|
|
if params:
|
|
|
|
r = api.call(meth, params)
|
|
|
|
else:
|
|
|
|
r = api.call(meth)
|
2016-09-08 19:41:11 +02:00
|
|
|
print json.dumps(r, sort_keys=True)
|
2016-07-06 09:02:55 +02:00
|
|
|
except:
|
|
|
|
print "Something went wrong, here's the usage for %s:" % meth
|
|
|
|
print api.help({'function': meth})
|
2016-07-06 08:17:38 +02:00
|
|
|
else:
|
2016-07-06 09:02:55 +02:00
|
|
|
print "Unknown function"
|
|
|
|
print msg
|
2016-07-06 08:17:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-07-14 05:44:02 +02:00
|
|
|
main()
|