author | Paul Crowley <paul@lshift.net> |
Wed, 07 Sep 2011 11:40:33 +0100 | |
changeset 330 | 77e6d9c545d4 |
parent 303 | 3f9f247b72bd |
child 374 | 7a1d6b228af6 |
permissions | -rw-r--r-- |
242
03d8f07230b3
Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents:
225
diff
changeset
|
1 |
""" |
03d8f07230b3
Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents:
225
diff
changeset
|
2 |
Fix $HOME and read ~/.mercurial-server |
03d8f07230b3
Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents:
225
diff
changeset
|
3 |
""" |
70 | 4 |
|
79 | 5 |
import sys |
217
32b431977bf9
Fix /home/paul if it's broken when we start
Paul Crowley <paul@lshift.net>
parents:
216
diff
changeset
|
6 |
import os |
79 | 7 |
import os.path |
217
32b431977bf9
Fix /home/paul if it's broken when we start
Paul Crowley <paul@lshift.net>
parents:
216
diff
changeset
|
8 |
import pwd |
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
9 |
import ConfigParser |
79 | 10 |
|
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
11 |
globalconfig = None |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
12 |
|
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
13 |
def _getConf(): |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
14 |
global globalconfig |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
15 |
if globalconfig is None: |
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
16 |
globalconfig = ConfigParser.RawConfigParser() |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
17 |
globalconfig.read(os.path.expanduser("~/.mercurial-server")) |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
18 |
return globalconfig |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
19 |
|
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
20 |
def _getPath(name): |
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
21 |
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
|
22 |
|
303 | 23 |
def _getPaths(name): |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
24 |
return [os.path.expanduser(p) |
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
25 |
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
|
26 |
|
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
27 |
def getReposPath(): return _getPath("repos") |
213
72e7ba8b41a6
Don't hardwire location of authorized_keys file
Paul Crowley <paul@lshift.net>
parents:
212
diff
changeset
|
28 |
def getAuthorizedKeysPath(): return _getPath("authorized_keys") |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
29 |
|
216 | 30 |
def configExists(): |
31 |
try: |
|
225 | 32 |
getAuthorizedKeysPath() |
216 | 33 |
return True |
225 | 34 |
except Exception, e: |
35 |
print e |
|
216 | 36 |
return False |
37 |
||
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
38 |
def getKeysPaths(): return _getPaths("keys") |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
39 |
def getAccessPaths(): return _getPaths("access") |
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
40 |
|
215
584df0f2e5c7
Use ConfigParser istead of mercurial.config
Paul Crowley <paul@lshift.net>
parents:
213
diff
changeset
|
41 |
def getEnv(): return _getConf().items("env") |
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
42 |
|
303 | 43 |
def _getdefault(section, option, default, f = lambda x: x): |
44 |
conf = _getConf() |
|
45 |
if conf.has_option(section, option): |
|
46 |
return f(conf.get(section, option)) |
|
47 |
else: |
|
48 |
return default |
|
49 |
||
50 |
def getAllowedDots(): |
|
51 |
return _getdefault("exceptions", "allowdots", [], |
|
52 |
lambda s: s.split(":")) |
|
53 |
||
165
3606d60b07e5
Use .mercurial-sever file instead of hardcoding
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
54 |
# 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
|
55 |
def initExe(): |
79 | 56 |
global _exePath |
57 |
_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
|
58 |
# 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
|
59 |
os.environ['HOME'] = pwd.getpwuid(os.geteuid()).pw_dir |
79 | 60 |
|
61 |
def getExePath(): |
|
62 |
return _exePath |