Grossschreibung
This commit is contained in:
66
Userconfig/cfgfile.py
Normal file
66
Userconfig/cfgfile.py
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
#
|
||||
# $Id$
|
||||
# $URL$
|
||||
|
||||
"""
|
||||
cfgfile.py
|
||||
|
||||
Created by Marcus Stoegbauer on 2013-01-12.
|
||||
Copyright (c) 2013 __MyCompanyName__. All rights reserved.
|
||||
"""
|
||||
import ConfigParser
|
||||
|
||||
class Conf(object):
|
||||
confobj = ConfigParser.RawConfigParser()
|
||||
cfgfile = ''
|
||||
|
||||
def __init__(self, filename = None):
|
||||
"""if filename is set, open config file and initialize the ConfigParser
|
||||
"""
|
||||
self.confobj = ConfigParser.RawConfigParser()
|
||||
if filename:
|
||||
self.setfilename(filename)
|
||||
# if filename
|
||||
# def __init__
|
||||
|
||||
def setfilename(self, filename):
|
||||
"""initialize the ConfigParser
|
||||
"""
|
||||
ret = self.confobj.read(filename)
|
||||
if len(ret) == 0 or ret[0] != filename:
|
||||
raise Exception('Cannot read config file ' + filename)
|
||||
# if cannot read
|
||||
self.cfgfile = filename
|
||||
# def setfilename
|
||||
|
||||
def get(self, section, option):
|
||||
"""returns the value of option in section
|
||||
"""
|
||||
if not self.cfgfile:
|
||||
raise Exception('No config file set')
|
||||
# if not cfgfile
|
||||
return self.confobj.get(section, option)
|
||||
# def get
|
||||
|
||||
def set(self, section, option, value):
|
||||
"""docstring for update"""
|
||||
self.confobj.set(section, option, value)
|
||||
# def set
|
||||
|
||||
|
||||
def getitems(self, section):
|
||||
"""returns all items in section
|
||||
"""
|
||||
if not self.cfgfile:
|
||||
raise Exception('No config file set')
|
||||
# if not cfgfile
|
||||
return self.confobj.items(section)
|
||||
# def getitems
|
||||
|
||||
def check(self, section, option):
|
||||
"""checks for option in section"""
|
||||
return self.confobj.has_option(section, option)
|
||||
# def check
|
||||
# class Conf
|
||||
Reference in New Issue
Block a user