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))
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
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))