def save(self): """Save this gesture map to disk. @precondition: L{load} must have been called. """ if globalVars.appArgs.secure: return if not self.fileName: raise ValueError("No file name") out = configobj.ConfigObj(encoding="UTF-8") out.filename = self.fileName for gesture, scripts in self._map.items(): for module, className, script in scripts: key = "%s.%s" % (module, className) try: outSect = out[key] except KeyError: out[key] = {} outSect = out[key] if script is None: script = "None" try: outVal = outSect[script] except KeyError: # Write the first value as a string so configobj doesn't output a comma if there's only one value. outVal = outSect[script] = gesture else: if isinstance(outVal, list): outVal.append(gesture) else: outSect[script] = [outVal, gesture] with FaultTolerantFile(out.filename) as f: out.write(f)
def save(self): """Save all modified profiles and the base configuration to disk. """ if globalVars.appArgs.secure: # Never save the config if running securely. return try: with FaultTolerantFile(self.profiles[0].filename) as f: self.profiles[0].write(f) log.info("Base configuration saved") for name in self._dirtyProfiles: with FaultTolerantFile(self._profileCache[name].filename) as f: self._profileCache[name].write(f) log.info("Saved configuration profile %s" % name) self._dirtyProfiles.clear() except Exception as e: log.warning("Error saving configuration; probably read only file system") log.debugWarning("", exc_info=True) raise e
def _writeProfileToFile(self, filename, profile): with FaultTolerantFile(filename) as f: profile.write(f)