src/mercurialserver/config.py
branchdebian
changeset 229 3a28047ec6dc
parent 225 ff08fd5b1a62
child 242 03d8f07230b3
equal deleted inserted replaced
228:f98f716b2ae8 229:3a28047ec6dc
       
     1 # Copyright 2008-2009 LShift Ltd
       
     2 
       
     3 import sys
       
     4 import os
       
     5 import os.path
       
     6 import pwd
       
     7 import ConfigParser
       
     8 
       
     9 globalconfig = None
       
    10 
       
    11 def _getConf():
       
    12     global globalconfig
       
    13     if globalconfig is None:
       
    14         globalconfig = ConfigParser.RawConfigParser()
       
    15         globalconfig.read(os.path.expanduser("~/.mercurial-server"))
       
    16     return globalconfig
       
    17 
       
    18 def _getPath(name):
       
    19     return os.path.expanduser(_getConf().get("paths", name))
       
    20 
       
    21 def _getPaths(name): 
       
    22     return [os.path.expanduser(p)
       
    23         for p in _getConf().get("paths", name).split(":")]
       
    24 
       
    25 def getReposPath(): return _getPath("repos")
       
    26 def getAuthorizedKeysPath(): return _getPath("authorized_keys")
       
    27 
       
    28 def configExists():
       
    29     try:
       
    30         getAuthorizedKeysPath()
       
    31         return True
       
    32     except Exception, e:
       
    33         print e
       
    34         return False
       
    35 
       
    36 def getKeysPaths(): return _getPaths("keys")
       
    37 def getAccessPaths(): return _getPaths("access")
       
    38 
       
    39 def getEnv(): return _getConf().items("env")
       
    40 
       
    41 # Work out where we are, don't use config.
       
    42 def initExe():
       
    43     global _exePath
       
    44     _exePath = os.path.dirname(os.path.abspath(sys.argv[0]))
       
    45     # Fix $HOME in case of "sudo -u hg refresh-auth"
       
    46     os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir
       
    47 
       
    48 def getExePath():
       
    49     return _exePath
       
    50