src/mercurialserver/config.py
author Paul Crowley <paul@lshift.net>
Fri, 13 Nov 2009 12:32:43 +0000
changeset 213 72e7ba8b41a6
parent 212 ab5e0e4f5a0c
child 215 584df0f2e5c7
permissions -rw-r--r--
Don't hardwire location of authorized_keys file

# Copyright 2008-2009 LShift Ltd

import sys
import os.path
import mercurial.config

globalconfig = None

def _getConf():
    global globalconfig
    if globalconfig is None:
        globalconfig = mercurial.config.config()
        globalconfig.read(os.path.expanduser("~/.mercurial-server"))
    return globalconfig

def configExists():
    try:
        _getConf()
        return True
    except:
        return False

def _getPath(name):
    return os.path.expanduser(_getConf()["paths"][name])

def _getPaths(name): 
    return [os.path.expanduser(p)
        for p in _getConf()["paths"][name].split(":")]

def getReposPath(): return _getPath("repos")
def getAuthorizedKeysPath(): return _getPath("authorized_keys")

def getKeysPaths(): return _getPaths("keys")
def getAccessPaths(): return _getPaths("access")

def getEnv(): return _getConf()["env"]

# Work out where we are, don't use config.
def setExePath():
    global _exePath
    _exePath = os.path.dirname(os.path.abspath(sys.argv[0]))

def getExePath():
    return _exePath