Example #1
0
    def restore_menu(self, message, delay):
        """
        Prints a table with all existing backups and lets the user select
        the backup that should be restored.
        """
        backups = self.get_backups()
        backups = list(backups.items())
        backups.sort(key=lambda e: e[0])

        # Break if there is no backup available.
        if not backups:
            print("{} - restore-menu: failure: there is no backup available."\
                  .format(self.world.name))
            return None

        # Continue with the restore.
        body = [(date.ctime(),
                 filesize_to_string(os.path.getsize(path))
                 ) for date, path in backups]
        head = ["Date", "Size"]
        table_printer = pprinttable.TablePrinter("Nr.", "<")
        table_printer.print(body, head)

        backup = userinput.get_value(
            prompt="Select the backup that you want to restore: ",
            conv_func=lambda s: int(s.strip()),
            check_func=lambda s: s in range(len(backups))
            )
        date, backup = backups[backup]
        return self.restore(backup, message, delay)
Example #2
0
    def uninstall(self):
        """
        Uninstalls the server.

        Before the server will be uninstalled, there will be some checks to
        make sure the server can be uninstalled without any side effects.
        """
        # We need a server that could replace this one.
        avlb_server = self.app.server.get_names()
        avlb_server.pop( avlb_server.index(self.server.name) )

        # Break if there is no other server available.
        if not avlb_server:
            print("{} - uninstall: failure: There's no other server that "\
                  "could replace this one.".format(self.server.name))
            return None
        
        # Make sure, that the server should be removed.
        question = "{} - uninstall: Are you sure, that you want to "\
                   "uninstall the server? ".format(self.server.name)
        if not userinput.ask(question):
            return None
        
        # Get the name of the server that should replace this one.
        replacement = userinput.get_value(
            prompt=("{} - uninstall: Which server should replace this one?\n\t"
                    "(Chose from: {}) ".format(self.server.name, avlb_server)),
            check_func=lambda server: server in avlb_server,
            )
        replacement = self.app.server.get(replacement)        
        
        # Remove the server.
        try:
            self.server.uninstall(replacement)
        except server_wrapper.ServerIsOnlineError as error:
            print("{} - uninstall: The server is still running. ",
                  "\n\t'{}'".format(self.server.name, error))
        return None