#!/usr/bin/env python # -*- coding: utf-8 -*- # Author : Steven Harper # License : GNU GENERAL PUBLIC LICENSE import pygtk import os import sys import ConfigParser CONFIG_PATH = os.path.expanduser( "~/.usb-adsl-modem-config.conf" ) class USBAdslModemConfig: # Declare global variables for configuration as dictionary options = { "username":"default", "password":"default", "lang":"English", "vp":"0", "vc":"38", "authtype":"pppoa", "autostart_on_login":"true", "connect_on_boot":"false","leave_connected_on_exit":"false"} def __init__( self): self.debug = False if (self.debug):print("Config Started") self.config = ConfigParser.RawConfigParser(self.options) self.readConfig() self.writeConfig() def writeConfig( self ): self.config.write( open( CONFIG_PATH, 'w' ) ) if self.debug:print("done writing") def getOptions( self ) : return self.options def getOption( self, optionKey ) : if self.config.has_option( 'DEFAULT', optionKey ): return self.config.get('DEFAULT', optionKey) else: return "" def setOption( self, optionKey, optionValue ) : if self.config.has_option( 'DEFAULT', optionKey ): self.config.set('DEFAULT',optionKey,optionValue) def readConfig( self ): if self.debug:print("reading config") readFile = self.config.read(CONFIG_PATH) for key in self.options.keys(): if self.debug:print("checking key : " + key) if self.config.has_option( 'DEFAULT', key ): if self.debug:print("got a value!") else: self.config.set('DEFAULT',key,self.options[key]) if self.debug:print("Defaulting") if self.debug:print("done reading") if __name__ == "__main__": config = SpeedtouchConfig()