src/mercurialserver/paths.py
branchdebian
changeset 229 3a28047ec6dc
parent 228 f98f716b2ae8
parent 227 8ce190faa5c2
child 230 d6fb7689b2e4
equal deleted inserted replaced
228:f98f716b2ae8 229:3a28047ec6dc
     1 # Copyright 2008-2009 LShift Ltd
       
     2 
       
     3 import sys
       
     4 import os.path
       
     5 import mercurial.config
       
     6 
       
     7 globalconfig = None
       
     8 
       
     9 def _getConf():
       
    10     global globalconfig
       
    11     if globalconfig is None:
       
    12         globalconfig = mercurial.config.config()
       
    13         globalconfig.read(os.path.expanduser("~/.mercurial-server"))
       
    14     return globalconfig
       
    15 
       
    16 def configExists():
       
    17     try:
       
    18         _getConf()
       
    19         return True
       
    20     except:
       
    21         return False
       
    22 
       
    23 def _getPath(name):
       
    24     return os.path.expanduser(_getConf()["paths"][name])
       
    25 
       
    26 def _getPaths(name): 
       
    27     return [os.path.expanduser(p)
       
    28         for p in _getConf()["paths"][name].split(":")]
       
    29 
       
    30 
       
    31 def getExePath(): return _getPath("exe")
       
    32 def getReposPath(): return _getPath("repos")
       
    33 
       
    34 def getKeysPaths(): return _getPaths("keys")
       
    35 def getAccessPaths(): return _getPaths("access")
       
    36 
       
    37 # This goes into an env var, so pass it on verbatim.
       
    38 def getHgrcPaths(): return _getConf()["paths"]["hgrc"]
       
    39 
       
    40 # Work out where we are, don't use config.
       
    41 def setExePath():
       
    42     global _exePath
       
    43     _exePath = os.path.dirname(os.path.abspath(sys.argv[0]))
       
    44 
       
    45 def getExePath():
       
    46     return _exePath
       
    47