config.py 1.14 KB
Newer Older
putro's avatar
putro committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import os
import sys
import checks
from configobj import ConfigObj, ConfigObjError

class ConfigError(Exception):
    pass


configfile = os.path.dirname(sys.argv[0]) + "/config.ini"

try:
    config = ConfigObj(configfile, file_error=True)
except (ConfigObjError, IOError), e:
    print 'Could not read "%s": %s' % (configfile, e)
    sys.exit(-1)


nyms = config['nym']




def writeConfig():
    config.write()

def checkSection(section, config=config):
    if section in listSection(config):
        return True

def listSection(config):
    return config.keys()

34
def configSection(nym, subject="", subj_type="", passphrase=""):
putro's avatar
putro committed
35 36 37 38 39 40
    config['nym'][nym] = {}
    config['nym'][nym]['subject'] = subject
    config['nym'][nym]['subj_type'] = subj_type
    config['nym'][nym]['passphrase'] = passphrase


41 42
def delSection(nym):
    del config['nym'][nym]
putro's avatar
putro committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

def checkNymConfig(nym):
    return nyms.has_key(nym)

def nymList(nyms):
    nymlist = []
    for n in nyms.keys():
        nymlist.append(n)
    return nymlist

def printNymList():
    nymlist = nymList()
    counter = 0
    for n in nymlist:
        print counter, "-", n
        counter += 1
    return counter