-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvuart.py
executable file
·73 lines (59 loc) · 2.51 KB
/
vuart.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env python
# coding: utf8
'''
Tool for opening an interactive shell through virtual UART.
@file
@author Felipe Torres González<[email protected]>
@date November 17, 2015
@copyright LGPL v2.1
@ingroup tools
'''
#------------------------------------------------------------------------------|
# GNU LESSER GENERAL PUBLIC LICENSE |
# ------------------------------------ |
# This source file is free software; you can redistribute it and/or modify it |
# under the terms of the GNU Lesser General Public License as published by the |
# Free Software Foundation; either version 2.1 of the License, or (at your |
# option) any later version. This source is distributed in the hope that it |
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warrant |
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
# General Public License for more details. You should have received a copy of |
# the GNU Lesser General Public License along with this source; if not, |
# download it from http://www.gnu.org/licenses/lgpl-2.1.html |
#------------------------------------------------------------------------------|
# Imports
import argparse as arg
import sys
import socket
from core.vuart import VUART_shell
def main():
'''
Tool for opening an interactive shell through virtual UART.
'''
parser = arg.ArgumentParser(description='VUART shell for WR-LEN')
parser.add_argument('IP', type=str, help='IP of the device')
parser.add_argument('--input','-i',help='Execute an input script of WRPC commands')
parser.add_argument('--output','-o',help='Save the output of an input script to a file')
args = parser.parse_args()
try:
socket.inet_aton(args.IP)
except socket.error as ip_error:
print("Illegal IP address passed (%s)\n" % args.IP)
exit(1)
try:
shell = VUART_shell(args.IP)
if args.input:
fin = open(args.input, 'r')
fout = open(args.output,'a+') if args.output else None
shell.run_script(fin, fout)
else:
shell.run()
#TODO: use exceptions from vuart (not defined yet)
except Exception as e:
print e
sys.stdout.write ("\033[1;31mError\033[0m: Failed connection with the WR-LEN (%s)\n" % (args.IP))
print ("See the manual for more deatils")
except Error as e:
print e
if __name__ == '__main__':
main()