def save(self): if self.config_changed: self.config_changed = False db = Database(self.package_name) db.open() db.save_config(self.config) db.close()
def add_from_config(self): """Attempt to add all configured devices.""" store_updated_settings = False try: database = Database('candleappstore') if not database.open(): print("Could not open settings database") return config = database.load_config() database.close() except: print("Error! Failed to open settings database.") if not config: print("Error loading config from database") return #print(str(config)) if 'Debugging' in config: print("-Debugging was in config") self.DEBUG = bool(config['Debugging']) if self.DEBUG: print("Debugging enabled") if 'Keep addon data when uninstalling' in config: if self.DEBUG: print("-Keep addon data when uninstalling preference was in config: " + str(config['Keep addon data when uninstalling'])) self.keep_data_on_uninstall = bool(config['Keep addon data when uninstalling']) if 'Show developer options' in config: if self.DEBUG: print("-Developer preference was in config: " + str(config['Show developer options'])) self.developer = bool(config['Show developer options']) # Currently not used anymore. Settings are now stored in persistence.json where possible. try: # Store the settings that were changed by the add-on. if store_updated_settings: if self.DEBUG: print("Storing overridden settings") database = Database('candleappstore') if not database.open(): print("Error, could not open settings database to store modified settings") #return else: database.save_config(config) database.close() if self.DEBUG: print("Stored overridden preferences into the database") except Exception as ex: print("Error! Failed to store overridden settings in database: " + str(ex)) # Candleappstore name try: if 'Candleappstore name' in config: if self.DEBUG: print("-Candleappstore name is present in the config data.") self.candleappstore_name = str(config['Candleappstore name']) except Exception as ex: print("Error loading candleappstore name from config: " + str(ex)) # Candleappstore password try: if 'Candleappstore password' in config: if self.DEBUG: print("-Candleappstore password is present in the config data.") self.candleappstore_password = str(config['Candleappstore password']) except Exception as ex: print("Error loading candleappstore password from config: " + str(ex)) # Api token try: if 'Authorization token' in config: if str(config['Authorization token']) != "": self.token = str(config['Authorization token']) self.persistent_data['token'] = str(config['Authorization token']) if self.DEBUG: print("-Authorization token is present in the config data.") except Exception as ex: print("Error loading api token from settings: " + str(ex))