working on test stuff

This commit is contained in:
Edwin Eefting
2017-10-15 23:09:14 +02:00
parent e33f9c1709
commit 77e5d8f00e
5 changed files with 73 additions and 15 deletions
Executable
+90
View File
@@ -0,0 +1,90 @@
#!/usr/bin/env python3
import argparse
import json
import sys
import config
import node
import espeasy
import pydoc
import util
def get_epilog():
docs=pydoc.render_doc(node.Node) + pydoc.render_doc(espeasy.EspEasy)
docs=docs+"""
Examples:
Build, flash and connect to serial for node 2:
./espcli node 2 bfs
Configure wifi settings for node:
./espcli node 1 wificonfig
Configure node 1, controller 1 as domoticz mqtt:
./espcli espeasy 1 controller_domoticz_mqtt index=1 controllerip=1.2.3.4
"""
return(docs)
parser = argparse.ArgumentParser(description='ESPEasy testing framework', epilog=get_epilog(), formatter_class=argparse.RawDescriptionHelpFormatter)
# parser.add_argument('--url', default='http://localhost:8080/rpc', help='url of rpc server to connect to. default: %(default)s')
# parser.add_argument('--user', default=None, help='user to login.')
# parser.add_argument('--password', default=None, help='password.')
# parser.add_argument('--api_key', default=None, help='api_key, use instead of password to overrule all logins globally')
# parser.add_argument('--upload', default=None, help='File to upload')
# parser.add_argument('--json', action='store_true', help='interpret parameters as raw JSON data. (usefull when you want to pass complexer data type like subarrays or dicts) dont forget to use single quotes around the json string.')
# parser.add_argument('--short', action='store_true', help='return short single-line JSON output (for scripting)')
# parser.add_argument('--verbose', action='store_true', help='request verbose mode (module help output)')
# parser.add_argument('--insecure', action='store_true', help='dont verify SSL certificates. (use with self-signed certificates)')
parser.add_argument('--debug', action='store_true', help='enable http debugging output')
parser.add_argument('module', nargs=1, help='Module to use (node or espeasy)')
parser.add_argument('node', type=int,nargs=1, help='Node number (from config)')
parser.add_argument('command', nargs=1, help='Function from the module (help below)')
parser.add_argument('params', default=[], nargs='*', help='command parameters. in foo=bar form ')
args = parser.parse_args()
try:
if args.node[0]<1:
raise(Exception("node number should be 1 or higher"))
if args.debug:
util.enable_http_debug()
node_index=args.node[0]-1
#we always need a node instance
node_instance=node.Node(config.nodes[node_index])
#determine rpc parameters
params={}
for param in args.params:
(key,value)=param.split("=")
params[key]=value
if args.module[0]=='node':
command = getattr(node_instance, args.command[0])
command(**params)
elif args.module[0]=='espeasy':
espeasy_instance=espeasy.EspEasy(node_instance)
command = getattr(espeasy_instance, args.command[0])
command(**params)
else:
raise(Exception("Unknown module:"+args.module[0]))
sys.exit(0)
except Exception as e:
print("Error: "+str(e), file=sys.stderr)
if args.debug:
print()
print("Details:")
raise
sys.exit(1)