Exemple #1
0
    def loadServerConfig():

        try:  # Try to load the server configuration from file
            Config.server = json.load(open(Config.SERVER_CONFIG_PATH))
        except json.decoder.JSONDecodeError:  # If it fails, ask for overwrite (or it will use a default server configuration)
            Config.createDefaultServerConfig(
                Config.yes(
                    Logger.format(
                        "Config",
                        "Failed to parse the server config file ! Do you want to recreate it and delete the old one ?"
                    )))
    def loadInputs():

        try:  # Try to load the keyboard configuration from file
            inputsFile = json.load(open(Config.KEYBOARD_CONFIG_PATH))['inputs']
            Config.inputs = inputsFile
        except json.decoder.JSONDecodeError:  # If it fails, ask for overwrite (or it will use a default keyboard configuration)
            Config.createDefaultInputs(
                Config.yes(
                    Logger.format(
                        "Config",
                        "Failed to parse the key config file ! Do you want to recreate it and delete the old one ?"
                    )))
    def loadConfig():

        try:  # Try to load the configuration from file
            configFile = json.load(open(Config.MAIN_CONFIG_PATH))['config']
            Config.values = configFile
        except json.decoder.JSONDecodeError:  # If it fails, ask for overwrite (or it will use a default configuration)
            Config.createDefaultConfig(
                Config.yes(
                    Logger.format(
                        "Config",
                        "Failed to parse the config file ! Do you want to recreate it and delete the old one ?"
                    )))
Exemple #4
0
    def createDefaultServerConfig(overwrite=True):

        if Config.yes(
                Logger.format(
                    "Config",
                    "Do you want to use the default server configuration ? ")):
            # We set default values for the server configuration
            Config.server = {"ip": "127.0.0.1", "port": 34141}
        else:
            # We ask for server configuration values
            Config.server = {
                "ip":
                input(
                    "[1/2] What is the IP or the domain name of the server ? "
                ),
                "port":
                input(
                    "[2/2] On which port runs the server (by default, 34141) ? "
                )
            }

        # We overwrite the server configuration if needed
        if overwrite: Config.saveServerConfig()