LISP: Fix several control plane message issues, VPP-558
[vpp.git] / vpp-api-test / scripts / vppctl
index 160bdf7..4fdf03c 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#! /usr/bin/python
 '''
 Copyright 2016 Intel Corporation
 
@@ -42,8 +42,12 @@ class Vppctl(Cmd):
                 input_command = input_prefix + line
                 line_remove = '^load_one_plugin:'
                 s = '\n'
+                command = ['vpp_api_test']
 
-                vpp_process = subprocess.Popen(['sudo', 'vpp_api_test'],
+                if os.geteuid() != 0:
+                    command = ['sudo', 'vpp_api_test']
+
+                vpp_process = subprocess.Popen(command,
                         stderr=subprocess.PIPE,
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE)
@@ -68,12 +72,16 @@ class Vppctl(Cmd):
 
         def do_exit(self, line):
                 self.historyWrite()
-
                 raise SystemExit
 
         def emptyline(self):
                 pass
 
+        def do_EOF(self,line):
+                self.historyWrite()
+                sys.stdout.write('\n')
+                raise SystemExit
+
         def preloop(self):
                 if readline and os.path.exists(persishist):
                         readline.read_history_file(persishist)
@@ -84,13 +92,30 @@ class Vppctl(Cmd):
 if __name__ == '__main__':
         command_args = sys.argv
 
+
         if not len(command_args) > 1:
                 prompt = Vppctl()
-                prompt.prompt = 'vpp# '
-                prompt.cmdloop("Starting Vppctl...")
+                red_set = '\033[31m'
+                norm_set = '\033[0m'
+                if sys.stdout.isatty():
+                        prompt.prompt = 'vpp# '
+                        try:
+                                prompt.cmdloop(red_set + "    _______    _       " + norm_set + " _   _____  ___ \n" +
+                                        red_set + " __/ __/ _ \  (_)__   " + norm_set + " | | / / _ \/ _ \\\n" +
+                                        red_set + " _/ _// // / / / _ \\" + norm_set + "   | |/ / ___/ ___/\n" +
+                                        red_set + " /_/ /____(_)_/\___/   " + norm_set + "|___/_/  /_/   \n")
+                        except KeyboardInterrupt:
+                                sys.stdout.write('\n')
+                else:
+                        try:
+                                prompt.cmdloop()
+                        except KeyboardInterrupt:
+                                sys.stdout.write('\n')
         else:
                 del command_args[0]
                 stdout_value = " ".join(command_args)
                 VatAddress = Vppctl()
                 VatAddress.runVat(stdout_value)
 
+
+