# File: c (Python 1.5)

import SER

class Config:
    
    def load(self):
        
        try:
            f = open('settings.ini', 'r')
            settings_line = f.read().split('%%%')
            for line in settings_line:
                values = line.split('=')
                if len(values) > 1:
                    self.config[values[0]] = values[1]
                
            
            f.close()
        except Exception:
            self.config = { }


    
    def __init__(self):
        self.config = { }
        self.load()

    
    def get(self, name):
        return self.config.get(name, '')

    
    def save(self, settings_line):
        
        try:
            f = open('settings.ini', 'w')
            f.write(settings_line)
            f.close()
        except Exception:
            print 'Something went wrong while saving settings...'


    
    def dump(self):
        
        try:
            f = open('settings.ini', 'r')
            settings_line = f.read()
        except Exception:
            settings_line = 'no file'

        SER.send(settings_line)

    
    def get_password(self):
        
        try:
            f = open('srvcpswd.dat')
            pswd = f.read().strip()
            f.close()
            return pswd
        except Exception:
            return '5492'


    
    def set_password(self, pswd):
        
        try:
            f = open('srvcpswd.dat', 'w')
            pswd = pswd.strip()
            if pswd:
                f.write(pswd)
            else:
                f.write('5492')
            f.close()
        except Exception:
            print 'Something went wrong when saving the service code...'



