Ejemplo n.º 1
0
    def load_old(self):
        try:
            with open(RelativePathResolver().absolute("config.txt")) as file:
                for line in file:
                    if line.startswith("mcu_dir"):
                        self.mcu_dir = line.strip().split("=", 1)[1]
                    if line.startswith("root_dir"):
                        self.root_dir = line.strip().split("=", 1)[1]
                    elif line.startswith("send_sleep"):
                        self.send_sleep = float(line.strip().split("=", 1)[1])
                    elif line.startswith("read_sleep"):
                        self.read_sleep = float(line.strip().split("=", 1)[1])
                    elif line.startswith("use_transfer_scripts"):
                        self.use_transfer_scripts = bool(
                            int(line.strip().split("=", 1)[1]))
                    elif line.startswith("wifi_preset"):
                        value = line.strip().split("=", 1)[1]
                        name, ip, port = value.split(",")
                        self.wifi_presets.append((name, ip, int(port)))
                    elif line.startswith("python_flash_executable"):
                        self.python_flash_executable = line.strip().split(
                            "=", 1)[1]
                    elif line.startswith("last_firmware_directory"):
                        self.last_firmware_directory = line.strip().split(
                            "=", 1)[1]
        except FileNotFoundError:
            return False

        return True
Ejemplo n.º 2
0
    def load(self):
        try:
            with open(RelativePathResolver().absolute("config.json")) as file:
                for key, val in self.deserialize(json.load(file)).items():
                    self.__dict__[key] = val
        except (FileNotFoundError, ValueError):
            return False

        return True
Ejemplo n.º 3
0
 def save(self):
     config_file = RelativePathResolver().absolute("config.json")
     try:
         # Check if file exists (supports also hidden files)
         if os.path.isfile(config_file):
             # Use write mode that also works with hidden files
             with open(os.open(config_file, os.O_WRONLY | os.O_TRUNC),
                       'w') as file:
                 json.dump(self.serialize(), file)
         else:
             # Simply create a new file
             with open(config_file, "w") as file:
                 json.dump(self.serialize(), file)
     except IOError:
         pass