import ConfigParser import os class Configuration: def __init__(self,conf_file="/etc/lliurex-amic/pref.conf"): self.config=ConfigParser.RawConfigParser() self.file=conf_file if os.path.exists(conf_file): self.config.read(self.file) self.joy_name=self.config.get("Joystick","name") self.axes=self.config.get("Joystick","axes") self.buttons=self.config.getboolean("Joystick","buttons") self.threshold=self.config.getfloat("Joystick","threshold") self.mouse=self.config.get("Mouse","name") self.scanperiod=self.config.getfloat("Behaviour","scanperiod") else: self.config.add_section('Joystick') self.config.add_section('Mouse') self.config.add_section('Behaviour') self.joy_name="none" self.axes="none" self.buttons=False self.threshold=0.3 self.mouse="none" self.scanperiod=1 self.save() #def read_conf def save(self): self.config.set("Joystick","name",self.joy_name) self.config.set("Joystick","axes",self.axes) self.config.set("Joystick","threshold",self.threshold) if(self.buttons): self.config.set("Joystick","buttons","True") else: self.config.set("Joystick","buttons","False") self.config.set("Mouse","name",self.mouse) self.config.set("Behaviour","scanperiod",self.scanperiod) with open(self.file, 'wb') as configfile: self.config.write(configfile) print "saving file" #def save #class Configuration