-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlxca_shell
executable file
·54 lines (41 loc) · 1.51 KB
/
lxca_shell
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
#!python
'''
@since: 15 Sep 2015
@author: Prashant Bhosale <[email protected]>, Girish Kumar <[email protected]>
@license: Lenovo License
@copyright: Lenovo Copyright
@organization: Lenovo Group Ltd
@summary: The main script for PYLXCA Tool, It creates a shell and accept raw input to process it.
'''
import os, time, code
import signal, time, sys
from pylxca import __version__
from pylxca.pylxca_cmd import lxca_ishell
from pylxca.pylxca_cmd.lxca_pyshell import *
class Application(object):
def __init__(self):
self.client = None
def run(self,api_mode):
if api_mode and "api" in api_mode :
set_interactive()
else:
global __version__
shell = lxca_ishell.InteractiveShell(banner="Welcome to LXCA Command Shell v" + __version__ , prompt="PyLXCA >> ")
shell.run()
def handle_ctrl_c(signum, frame):
# restore the original signal handler as otherwise evil things will happen
# in raw_input when CTRL+C is pressed, and our signal handler is not re-entrant
signal.signal(signal.SIGINT, original_sigint)
print ('\nKeyboardInterrupt: Press ctrl+D to exit')
# restore the exit gracefully handler here
signal.signal(signal.SIGINT, handle_ctrl_c)
def main():
api_mode = None
if len(sys.argv) > 1:
api_mode = sys.argv[1]
app = Application()
app.run(api_mode)
if __name__ == "__main__":
original_sigint = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, handle_ctrl_c)
main()