예제 #1
0
    def do_ssh(self, args, arguments):
        """
        ::

            Usage:
                ssh list [--format=FORMAT]
                ssh register NAME PARAMETERS
                ssh ARGUMENTS


            conducts a ssh login on a machine while using a set of
            registered machines specified in ~/.ssh/config

            Arguments:

              NAME        Name or ip of the machine to log in
              list        Lists the machines that are registered and
                          the commands to login to them
              PARAMETERS  Register te resource and add the given
                          parameters to the ssh config file.  if the
                          resoource exists, it will be overwritten. The
                          information will be written in /.ssh/config

            Options:

               -v       verbose mode
               --format=FORMAT   the format in which this list is given
                                 formats incluse table, json, yaml, dict
                                 [default: table]

               --user=USER       overwrites the username that is
                                 specified in ~/.ssh/config

               --key=KEY         The keyname as defined in the key list
                                 or a location that contains a pblic key

        """
        # pprint(arguments)
        if arguments["list"]:
            output_format = arguments["--format"]
            Console.ok('list {}'.format(output_format))
            hosts = ssh_config()
            print(hosts.list())
            TOTO("Complete implementation with dict_printer")
        elif arguments["register"]:
            name = arguments["NAME"]
            parameters = arguments["PARAMETERS"]
            Console.ok('register {} {}'.format(name, parameters))
            TODO("Not implemented")
        else:  # ssh ARGUMENTS...
            args = arguments["ARGUMENTS"]
            os.system("ssh {}".format(args))
            return
예제 #2
0
    def do_banner(self, arg, arguments):
        """
        ::

            Usage:
                banner [-c CHAR] [-n WIDTH] [-i INDENT] [-r COLOR] TEXT

            Arguments:
                TEXT   The text message from which to create the banner
                CHAR   The character for the frame. 
                WIDTH  Width of the banner
                INDENT indentation of the banner
                COLOR  the color

            Options:
                -c CHAR   The character for the frame. [default: #]
                -n WIDTH  The width of the banner. [default: 70]
                -i INDENT  The width of the banner. [default: 0]            
                -r COLOR  The color of the banner. [default: BLACK]

            Prints a banner form a one line text message.
        """
        print (arguments)
        n = int(arguments['-n'])
        c = arguments['-c']
        i = int(arguments['-i'])
        color = arguments['-r'].upper()

        
        Console._print(color, "", i * " " + (n-i) * c)
        Console._print(color, "",  i * " " + c + " " + arguments['TEXT'])
        Console._print(color, "",  i * " " + (n-i) * c)
예제 #3
0
    def do_open(self, args, arguments):
        """
        ::

            Usage:
                    open FILENAME

            ARGUMENTS:
                FILENAME  the file to open in the cwd if . is
                          specified. If file in in cwd
                          you must specify it with ./FILENAME

            Opens the given URL in a browser window.
        """
        filename = arguments['FILENAME']
        filename = self._expand_filename(filename)
        Console.ok("open {0}".format(filename))

        if not (filename.startswith("file:") or filename.startswith("http:")):
            try:
                with open(filename):
                    pass
                filename += "file://"
            except:
                Console.error("unsupported browser format in file {0}".format(filename))
                return

        try:
            webbrowser.open("%s" % filename)
        except:
            Console.error("can not open browser with file {0}".format(filename))
예제 #4
0
    def do_commands(self, arg, arguments):
        """
        ::

            Usage:
                commands

            Prints all registered commands
        """
        print (arguments)
        print (vars())

        names  = [cls.__name__ for cls in Cmd3Command.__subclasses__()]

        classes  = [cls for cls in Cmd3Command.__subclasses__()]

        name_list = '\n'.join(names)

        Console.ok("Registered Commands")
        Console.ok("===================")
        for name in names:
            Console.ok(name)
        print()

        Console.ok("Registered Classes")
        Console.ok("===================")
        for c in classes:
            Console.ok(str(c))