src/mercurialserver/config.py
changeset 215 584df0f2e5c7
parent 213 72e7ba8b41a6
child 216 0122df83ebd0
equal deleted inserted replaced
214:7374d0147875 215:584df0f2e5c7
     1 # Copyright 2008-2009 LShift Ltd
     1 # Copyright 2008-2009 LShift Ltd
     2 
     2 
     3 import sys
     3 import sys
     4 import os.path
     4 import os.path
     5 import mercurial.config
     5 import ConfigParser
     6 
     6 
     7 globalconfig = None
     7 globalconfig = None
     8 
     8 
     9 def _getConf():
     9 def _getConf():
    10     global globalconfig
    10     global globalconfig
    11     if globalconfig is None:
    11     if globalconfig is None:
    12         globalconfig = mercurial.config.config()
    12         globalconfig = ConfigParser.RawConfigParser()
    13         globalconfig.read(os.path.expanduser("~/.mercurial-server"))
    13         globalconfig.read(os.path.expanduser("~/.mercurial-server"))
    14     return globalconfig
    14     return globalconfig
    15 
    15 
    16 def configExists():
    16 def configExists():
    17     try:
    17     try:
    19         return True
    19         return True
    20     except:
    20     except:
    21         return False
    21         return False
    22 
    22 
    23 def _getPath(name):
    23 def _getPath(name):
    24     return os.path.expanduser(_getConf()["paths"][name])
    24     return os.path.expanduser(_getConf().get("paths", name))
    25 
    25 
    26 def _getPaths(name): 
    26 def _getPaths(name): 
    27     return [os.path.expanduser(p)
    27     return [os.path.expanduser(p)
    28         for p in _getConf()["paths"][name].split(":")]
    28         for p in _getConf().get("paths", name).split(":")]
    29 
    29 
    30 def getReposPath(): return _getPath("repos")
    30 def getReposPath(): return _getPath("repos")
    31 def getAuthorizedKeysPath(): return _getPath("authorized_keys")
    31 def getAuthorizedKeysPath(): return _getPath("authorized_keys")
    32 
    32 
    33 def getKeysPaths(): return _getPaths("keys")
    33 def getKeysPaths(): return _getPaths("keys")
    34 def getAccessPaths(): return _getPaths("access")
    34 def getAccessPaths(): return _getPaths("access")
    35 
    35 
    36 def getEnv(): return _getConf()["env"]
    36 def getEnv(): return _getConf().items("env")
    37 
    37 
    38 # Work out where we are, don't use config.
    38 # Work out where we are, don't use config.
    39 def setExePath():
    39 def setExePath():
    40     global _exePath
    40     global _exePath
    41     _exePath = os.path.dirname(os.path.abspath(sys.argv[0]))
    41     _exePath = os.path.dirname(os.path.abspath(sys.argv[0]))