3 Copyright 2016 Intel Corporation
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
28 persishist = os.path.expanduser('~/.vpphistory')
29 persishist_size = 1000
31 os.mknod(persishist, stat.S_IFREG)
35 def historyWrite(self):
37 readline.set_history_length(persishist_size)
38 readline.write_history_file(persishist)
40 def runVat(self, line):
41 input_prefix = "exec "
42 input_command = input_prefix + line
43 line_remove = '^load_one_plugin:'
45 command = ['vpp_api_test']
48 command = ['sudo', 'vpp_api_test']
50 vpp_process = subprocess.Popen(command,
51 stderr=subprocess.PIPE,
52 stdin=subprocess.PIPE,
53 stdout=subprocess.PIPE)
54 stdout_value = vpp_process.communicate(input_command)[0]
56 buffer_stdout = stdout_value.splitlines()
58 buffer_stdout[:] = [b for b in buffer_stdout
59 if line_remove not in b]
61 for i, num in enumerate(buffer_stdout):
62 buffer_stdout[i] = num.replace('vat# ','')
64 stdout_value = s.join(buffer_stdout)
67 def do_help(self, line):
70 def default(self, line):
73 def do_exit(self, line):
82 if readline and os.path.exists(persishist):
83 readline.read_history_file(persishist)
85 def postcmd(self, stop, line):
88 if __name__ == '__main__':
89 command_args = sys.argv
92 if not len(command_args) > 1:
96 if sys.stdout.isatty():
97 prompt.prompt = 'vpp# '
98 prompt.cmdloop(red_set + " _______ _ " + norm_set + " _ _____ ___ \n" +
99 red_set + " __/ __/ _ \ (_)__ " + norm_set + " | | / / _ \/ _ \\\n" +
100 red_set + " _/ _// // / / / _ \\" + norm_set + " | |/ / ___/ ___/\n" +
101 red_set + " /_/ /____(_)_/\___/ " + norm_set + "|___/_/ /_/ \n")
106 stdout_value = " ".join(command_args)
107 VatAddress = Vppctl()
108 VatAddress.runVat(stdout_value)