Skip to content

Commit 58248f4

Browse files
committed
separated arguments out of shell.py
1 parent 2bcae1f commit 58248f4

2 files changed

Lines changed: 30 additions & 27 deletions

File tree

arguments.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import argparse
2+
import sys
3+
4+
parser = argparse.ArgumentParser(description="Noninteractive and Interactive \
5+
command execution. Must provide all the details in cmd_list \
6+
in remote_commands.py for interactive commands.")
7+
8+
parser.add_argument("command", help="provide command. If interactive, \
9+
should be one of commands in remote_commands.py or all which would \
10+
execute every command in remote_commands.py one after another. e.g.\n \
11+
python shell.py testshell1 127.0.0.1 root password \n \
12+
python shell.py all 127.0.0.1 root password")
13+
14+
parser.add_argument("host", help="provide host name", nargs="?",
15+
default="localhost")
16+
parser.add_argument("username", help="provide user name", nargs="?",
17+
default="root")
18+
parser.add_argument("password", help="provide password", nargs="?",
19+
default="netsim")
20+
21+
if len(sys.argv) < 2:
22+
parser.print_help()
23+
sys.exit(1)
24+
25+
args = parser.parse_args()

shell.py

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
1-
import argparse
21
import pexpect
32
import subprocess
4-
import sys
53
from pexpect import pxssh
64

75
from log import logger
86
from remote_commands import cmd_list
97

10-
parser = argparse.ArgumentParser(description="Noninteractive and Interactive \
11-
command execution. Must provide all the details in cmd_list \
12-
in remote_commands.py for interactive commands.")
8+
import arguments
139

14-
parser.add_argument("command", help="provide command. If interactive, \
15-
should be one of commands in remote_commands.py or all which would \
16-
execute every command in remote_commands.py one after another. e.g.\n \
17-
python shell.py testshell1 127.0.0.1 root password \n \
18-
python shell.py all 127.0.0.1 root password")
19-
20-
parser.add_argument("host", help="provide host name", nargs="?",
21-
default="localhost")
22-
parser.add_argument("username", help="provide user name", nargs="?",
23-
default="root")
24-
parser.add_argument("password", help="provide password", nargs="?",
25-
default="netsim")
26-
#parser.add_argument("cmd_type", nargs='?',
27-
# help="provide i for interactive, n for non-interactive", default="n")
28-
29-
if len(sys.argv) < 2:
30-
parser.print_help()
31-
sys.exit(1)
32-
33-
args = parser.parse_args()
10+
args = arguments.args
3411

12+
# Setting command type to interactive if given command is found in cmd_list
3513
interactive = False
3614
icmd = None
3715
for i in cmd_list:
@@ -56,7 +34,7 @@ def remote(self):
5634
password = self.password
5735
s.login(hostname, username, password)
5836
if not interactive and args.command != "all":
59-
self.exec_remote_normal(s=s)
37+
self.exec_remote_noninteractive(s=s)
6038
elif args.command != "all":
6139
self.exec_remote(s=s)
6240
else:
@@ -95,7 +73,7 @@ def exec_remote_all(self, s):
9573
logger.info(s.before)
9674
logger.info(s.after)
9775

98-
def exec_remote_normal(self,s):
76+
def exec_remote_noninteractive(self,s):
9977
logger.info("remote non-interactive")
10078
cur_cmd = self.command
10179
logger.info("Executing COMMAND {0}".format(cur_cmd) +

0 commit comments

Comments
 (0)