src/mercurialserver/paths.py
author Paul Crowley <paul@lshift.net>
Tue, 10 Nov 2009 16:15:58 +0000
changeset 196 1ad9d5841a48
parent 165 3606d60b07e5
permissions -rw-r--r--
Bump to 0.8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
70
abb9ed8972e0 Move more into hg-ssh
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     1
# Copyright 2008-2009 LShift Ltd
abb9ed8972e0 Move more into hg-ssh
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     2
79
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
     3
import sys
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
     4
import os.path
165
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
     5
import mercurial.config
79
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
     6
165
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
     7
globalconfig = None
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
     8
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
     9
def _getConf():
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    10
    global globalconfig
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    11
    if globalconfig is None:
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    12
        globalconfig = mercurial.config.config()
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    13
        globalconfig.read(os.path.expanduser("~/.mercurial-server"))
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    14
    return globalconfig
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    15
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    16
def configExists():
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    17
    try:
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    18
        _getConf()
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    19
        return True
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    20
    except:
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    21
        return False
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    22
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    23
def _getPath(name):
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    24
    return os.path.expanduser(_getConf()["paths"][name])
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    25
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    26
def _getPaths(name): 
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    27
    return [os.path.expanduser(p)
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    28
        for p in _getConf()["paths"][name].split(":")]
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    29
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    30
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    31
def getExePath(): return _getPath("exe")
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    32
def getReposPath(): return _getPath("repos")
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    33
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    34
def getKeysPaths(): return _getPaths("keys")
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    35
def getAccessPaths(): return _getPaths("access")
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    36
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    37
# This goes into an env var, so pass it on verbatim.
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    38
def getHgrcPaths(): return _getConf()["paths"]["hgrc"]
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    39
3606d60b07e5 Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents: 79
diff changeset
    40
# Work out where we are, don't use config.
79
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
    41
def setExePath():
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
    42
    global _exePath
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
    43
    _exePath = os.path.dirname(os.path.abspath(sys.argv[0]))
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
    44
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
    45
def getExePath():
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
    46
    return _exePath
3a58a95fae2f abolish hg-ssh-wrapper
Paul Crowley <paul@lshift.net>
parents: 70
diff changeset
    47