author | Paul Crowley <paul@lshift.net> |
Thu, 17 Dec 2009 16:28:43 +0000 | |
changeset 238 | 4747f2920666 |
parent 225 | ff08fd5b1a62 |
child 242 | 03d8f07230b3 |
permissions | -rw-r--r-- |
70 | 1 |
# Copyright 2008-2009 LShift Ltd |
2 |
||
79 | 3 |
import sys |
217
32b431977bf9
Fix /home/paul if it's broken when we start
Paul Crowley <paul@lshift.net>
parents:
216
diff
changeset
|
4 |
import os |
79 | 5 |
import os.path |
217
32b431977bf9
Fix /home/paul if it's broken when we start
Paul Crowley <paul@lshift.net>
parents:
216
diff
changeset
|
6 |
import pwd |
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
7 |
import ConfigParser |
79 | 8 |
|
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
9 |
globalconfig = None |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
10 |
|
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
11 |
def _getConf(): |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
12 |
global globalconfig |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
13 |
if globalconfig is None: |
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
14 |
globalconfig = ConfigParser.RawConfigParser() |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
15 |
globalconfig.read(os.path.expanduser("~/.mercurial-server")) |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
16 |
return globalconfig |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
17 |
|
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
18 |
def _getPath(name): |
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
19 |
return os.path.expanduser(_getConf().get("paths", name)) |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
20 |
|
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
21 |
def _getPaths(name): |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
22 |
return [os.path.expanduser(p) |
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
23 |
for p in _getConf().get("paths", name).split(":")] |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
24 |
|
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
25 |
def getReposPath(): return _getPath("repos") |
213
72e7ba8b41a6
Don't hardwire location of authorized_keys file
Paul Crowley <paul@lshift.net>
parents:
212
diff
changeset
|
26 |
def getAuthorizedKeysPath(): return _getPath("authorized_keys") |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
27 |
|
216 | 28 |
def configExists(): |
29 |
try: |
|
225 | 30 |
getAuthorizedKeysPath() |
216 | 31 |
return True |
225 | 32 |
except Exception, e: |
33 |
print e |
|
216 | 34 |
return False |
35 |
||
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
36 |
def getKeysPaths(): return _getPaths("keys") |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
37 |
def getAccessPaths(): return _getPaths("access") |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
38 |
|
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
39 |
def getEnv(): return _getConf().items("env") |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
40 |
|
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
41 |
# Work out where we are, don't use config. |
217
32b431977bf9
Fix /home/paul if it's broken when we start
Paul Crowley <paul@lshift.net>
parents:
216
diff
changeset
|
42 |
def initExe(): |
79 | 43 |
global _exePath |
44 |
_exePath = os.path.dirname(os.path.abspath(sys.argv[0])) |
|
217
32b431977bf9
Fix /home/paul if it's broken when we start
Paul Crowley <paul@lshift.net>
parents:
216
diff
changeset
|
45 |
# Fix $HOME in case of "sudo -u hg refresh-auth" |
32b431977bf9
Fix /home/paul if it's broken when we start
Paul Crowley <paul@lshift.net>
parents:
216
diff
changeset
|
46 |
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir |
79 | 47 |
|
48 |
def getExePath(): |
|
49 |
return _exePath |
|
50 |