src/mercurialserver/paths.py
changeset 165 3606d60b07e5
parent 79 3a58a95fae2f
equal deleted inserted replaced
164:32131253c2f1 165:3606d60b07e5
     1 # Copyright 2008-2009 LShift Ltd
     1 # Copyright 2008-2009 LShift Ltd
     2 
       
     3 # Crude but it will do
       
     4 
     2 
     5 import sys
     3 import sys
     6 import os.path
     4 import os.path
       
     5 import mercurial.config
     7 
     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.
     8 def setExePath():
    41 def setExePath():
     9     global _exePath
    42     global _exePath
    10     _exePath = os.path.dirname(os.path.abspath(sys.argv[0]))
    43     _exePath = os.path.dirname(os.path.abspath(sys.argv[0]))
    11 
    44 
    12 def getExePath():
    45 def getExePath():
    13     return _exePath
    46     return _exePath
    14 
    47 
    15 def getEtcPath():
       
    16     return "/etc/mercurial-server"