Esempio n. 1
0
    def loadFile(cfile=None):
        retVal = False
        if cfile == None:
            cfile = Config.configfile
            hostnameMatch = False
        else:
            hostnameMatch = customDir + "/" + CUSTOM_NAME == cfile
        # returns false if no file or no 'defaults' section
        print "Processing conf <%s>" % cfile
        if not exists(cfile):
            print "\tfile not found..."
        else:
            f = open(cfile, "r")
            c = cfgParser()
            c.readfp(f)

            for s in c.sections():
                if s == "defaults":
                    if hostnameMatch:
                        retVal = True
                        Config.active = c.get("defaults", "active") or "avision"  # if (zero-length)
                        Config.offset = c.getpair("defaults", "offset") or [0, 0]
                        Config.res = c.getint("defaults", "resolution") or 300
                        # switch here?
                else:
                    Config.getConfig(c, s)
            # generate data dict based on cfg file
            if not retVal:
                print "\t(wrong hostname or no 'defaults' section)"
            else:
                print "\t*Default found!"
            f.close()
        return retVal
Esempio n. 2
0
    def saveFile(filename=None, callbacks=[]):
        if filename == None:
            filename = Config.configfile
        c = cfgParser()

        # preserve other sections
        if exists(filename):
            f = open(filename, "r")
            c.readfp(f)
            f.close()

        f = open(filename, "w")

        Config.setConfig(
            c, "defaults", [["active", Config.active], ["offset", str(Config.offset)], ["resolution", str(Config.res)]]
        )
        for callback in callbacks:
            callback(c)

        c.write(f)
        f.close()
        Config.configModified = modification_date(customDir)
        print "Configuration file<%s> saved" % filename
Esempio n. 3
0
@route('/settings', method='POST')
def saveSettings(): 
    return 'Settings stub'

@route('/filter/:name/:value')
@view('design/filter')
def filter(name, value): 
    return entries.find({name : value})

#------------------------------------------------------------------
# Загрузка сервера

def startup(cfg):
    global entries, settings
    db = dbConnect(cfg.get('db', 'host'), cfg.getint('db', 'port')).contacts
    entries = db.entries
    if entries.count() == 0:
        entries.insert({
                '_id': 'new',
                'FullName':'',
                'Email':'',
                'Phone':''})
    settings = db.settings
    debug(cfg.getboolean('etc', 'debug'))
    run(host=cfg.get('http', 'host'), port=cfg.getint('http', 'port'))

cfg = cfgParser()
cfg.read('contacts.cfg')
startup(cfg) # Do it