示例#1
0
    def saveConfigFile(self, cf="MassMailer.conf", pw=False):
        """
    Save all passed in command line arguments
    and user input to the config file specified
    by cf.  pw is a boolean that controls whether
    the password gets saved to the config.
    """
        with open(cf, "w") as cpf:
            self.cp = cp()
            for member in self.__dict__:
                member_obj = getattr(self, member)
                if "_" in member and not inspect.ismethod(member_obj):
                    section = member.split("_")[0]
                    name = member[member.find("_") + 1 :]
                    val = getattr(self, member)

                    # Don't want the string "None" saved
                    if val is None:
                        val = ""

                    # Special handling of the password
                    if name == "password":
                        if not pw:
                            val = ""

                    # Save values in the SafeConfigParser object
                    if section not in self.cp.sections():
                        self.cp.add_section(section)
                    self.cp.set(section, name, str(val))

            # Write to the file
            self.cp.write(cpf)
示例#2
0
def parse_conf_to_dict(conf_path):
    parser = cp()
    try:
        parser.read(conf_path)
    except ConfigParser.Error, e:
        log("EXCEPTION: Parsing of {} failed.\n{}".format(conf_path, e.message))
        sys.exit(1)
示例#3
0
    def __init__(self):
        """
    MassMailer constructor.
    
    Takes a path to a config file compatible with
    Python's ConfigParser standard library module.
    Defaults to a .conf file named after this class
    in the same directory as this module.
    """
        # Parse command line args
        self.parseArgs()

        # If necessary, parse the config file
        if self.config and os.path.isfile(self.config):
            self.cp = cp()
            self.cp.read(self.config)

            # Parse the config file
            self.parseConfig()
def read_db_config(filename='config.ini', section='mysql'):
    """ Read database config file and return a dictionary object.
  :param filename: name of the config file
  :param section: section of database configuration
  :return: a dictionary of database parameters
  """
    # Create parser and read ini config file
    parser = cp()
    parser.read(filename)

    # get section, default to mysql
    db = {}
    if parser.has_section(section):
        items = parser.items(section)
        for item in items:
            db[item[0]] = item[1]
    else:
        raise Exception('{0} not found in the {1} file'.format(
            section, filename))

    return db
示例#5
0
import os
import yaml
from ConfigParser import ConfigParser as cp

path = os.environ['HOME'] + "/.config/sflphone/sflphonedrc"
# path = "sflphonedrc"
c = cp()
c.read(path)
accnodes = ['srtp', 'tls', 'zrtp']
auxnodes = ['alsa', 'pulse', 'dtmf']
dico = {}
dico['accounts'] = []

# Dictionary used to convert string used in prior configuration file to new one.
conversion = {

    # addressbook
    'addressbook': 'addressbook',
    'contact_photo': 'photo',
    'enable': 'enabled',
    'max_results': 'maxResults',
    'phone_business': 'business',
    'phone_home': 'photo',
    'phone_mobile': 'mobile',

    # audio
    'audio': 'audio',
    'cardid_in': 'cardIn',
    'cardid_out': 'cardOut',
    'cardid_ring': 'cardRing',
    'framesize': 'frameSize',
示例#6
0
 def __init__(self, f=None):
     self._values = cp()
     if f: self._values.read(f)
示例#7
0
文件: config.py 项目: ajdiaz/mole
 def __init__(self, f=None):
     self._values = cp()
     if f: self._values.read(f)
示例#8
0
import os
import yaml
from ConfigParser import ConfigParser as cp

path = os.environ['HOME'] + "/.config/sflphone/sflphonedrc"
# path = "sflphonedrc"
c = cp()
c.read(path)
accnodes = ['srtp', 'tls', 'zrtp']
auxnodes = ['alsa', 'pulse', 'dtmf']
dico = {}
dico['accounts'] = []

# Dictionary used to convert string used in prior configuration file to new one.
conversion = {

	# addressbook
	'addressbook': 'addressbook',
	'contact_photo': 'photo',
	'enable': 'enabled',
	'max_results': 'maxResults',
	'phone_business': 'business',
	'phone_home': 'photo',
	'phone_mobile': 'mobile',

	# audio
	'audio': 'audio',
	'cardid_in': 'cardIn',
	'cardid_out': 'cardOut',
	'cardid_ring': 'cardRing',
	'framesize': 'frameSize',
示例#9
0
from ConfigParser import ConfigParser as cp

CONFIGFILE = "python.txt"

config = cp()

config.read(CONFIGFILE)

print config.get('messages', 'greeting')

radius = input(config.get('messages', 'question') + ' ')

print config.get('messages', 'result_message'),

print config.getfloat('numbers', 'pi') * radius**2