Show More
@@ -1,32 +1,33 | |||||
1 | import sys, os |
|
1 | import sys, os | |
2 | import osutil |
|
2 | import osutil | |
3 |
|
3 | |||
4 | def _rcfiles(path): |
|
4 | def _rcfiles(path): | |
5 | rcs = [os.path.join(path, 'hgrc')] |
|
5 | rcs = [os.path.join(path, 'hgrc')] | |
6 | rcdir = os.path.join(path, 'hgrc.d') |
|
6 | rcdir = os.path.join(path, 'hgrc.d') | |
7 | try: |
|
7 | try: | |
8 | rcs.extend([os.path.join(rcdir, f) |
|
8 | rcs.extend([os.path.join(rcdir, f) | |
9 | for f, kind in osutil.listdir(rcdir) |
|
9 | for f, kind in osutil.listdir(rcdir) | |
10 | if f.endswith(".rc")]) |
|
10 | if f.endswith(".rc")]) | |
11 | except OSError: |
|
11 | except OSError: | |
12 | pass |
|
12 | pass | |
13 | return rcs |
|
13 | return rcs | |
14 |
|
14 | |||
15 | def systemrcpath(): |
|
15 | def systemrcpath(): | |
16 | path = [] |
|
16 | path = [] | |
17 | if sys.platform == 'plan9': |
|
17 | if sys.platform == 'plan9': | |
18 | root = 'lib/mercurial' |
|
18 | root = 'lib/mercurial' | |
19 | else: |
|
19 | else: | |
20 | root = 'etc/mercurial' |
|
20 | root = 'etc/mercurial' | |
21 | # old mod_python does not set sys.argv |
|
21 | # old mod_python does not set sys.argv | |
22 | if len(getattr(sys, 'argv', [])) > 0: |
|
22 | if len(getattr(sys, 'argv', [])) > 0: | |
23 | p = os.path.dirname(os.path.dirname(sys.argv[0])) |
|
23 | p = os.path.dirname(os.path.dirname(sys.argv[0])) | |
24 | path.extend(_rcfiles(os.path.join(p, root))) |
|
24 | if p != '/': | |
|
25 | path.extend(_rcfiles(os.path.join(p, root))) | |||
25 | path.extend(_rcfiles('/' + root)) |
|
26 | path.extend(_rcfiles('/' + root)) | |
26 | return path |
|
27 | return path | |
27 |
|
28 | |||
28 | def userrcpath(): |
|
29 | def userrcpath(): | |
29 | if sys.platform == 'plan9': |
|
30 | if sys.platform == 'plan9': | |
30 | return [os.environ['home'] + '/lib/hgrc'] |
|
31 | return [os.environ['home'] + '/lib/hgrc'] | |
31 | else: |
|
32 | else: | |
32 | return [os.path.expanduser('~/.hgrc')] |
|
33 | return [os.path.expanduser('~/.hgrc')] |
@@ -1,46 +1,46 | |||||
1 | import os |
|
1 | import os | |
2 | import osutil |
|
2 | import osutil | |
3 | import util |
|
3 | import util | |
4 | import _winreg |
|
4 | import _winreg | |
5 |
|
5 | |||
6 | def systemrcpath(): |
|
6 | def systemrcpath(): | |
7 | '''return default os-specific hgrc search path''' |
|
7 | '''return default os-specific hgrc search path''' | |
8 | rcpath = [] |
|
8 | rcpath = [] | |
9 | filename = util.executablepath() |
|
9 | filename = util.executablepath() | |
10 | # Use mercurial.ini found in directory with hg.exe |
|
10 | # Use mercurial.ini found in directory with hg.exe | |
11 | progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') |
|
11 | progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') | |
12 | if os.path.isfile(progrc): |
|
12 | if os.path.isfile(progrc): | |
13 | rcpath.append(progrc) |
|
13 | rcpath.append(progrc) | |
14 | return rcpath |
|
14 | return rcpath | |
15 | # Use hgrc.d found in directory with hg.exe |
|
15 | # Use hgrc.d found in directory with hg.exe | |
16 | progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d') |
|
16 | progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d') | |
17 | if os.path.isdir(progrcd): |
|
17 | if os.path.isdir(progrcd): | |
18 | for f, kind in osutil.listdir(progrcd): |
|
18 | for f, kind in osutil.listdir(progrcd): | |
19 | if f.endswith('.rc'): |
|
19 | if f.endswith('.rc'): | |
20 | rcpath.append(os.path.join(progrcd, f)) |
|
20 | rcpath.append(os.path.join(progrcd, f)) | |
21 | return rcpath |
|
21 | return rcpath | |
22 | # else look for a system rcpath in the registry |
|
22 | # else look for a system rcpath in the registry | |
23 | value = util.lookupreg('SOFTWARE\\Mercurial', None, |
|
23 | value = util.lookupreg('SOFTWARE\\Mercurial', None, | |
24 | _winreg.HKEY_LOCAL_MACHINE) |
|
24 | _winreg.HKEY_LOCAL_MACHINE) | |
25 | if not isinstance(value, str) or not value: |
|
25 | if not isinstance(value, str) or not value: | |
26 | return rcpath |
|
26 | return rcpath | |
27 | value = util.localpath(value) |
|
27 | value = util.localpath(value) | |
28 | for p in value.split(os.pathsep): |
|
28 | for p in value.split(os.pathsep): | |
29 | if p.lower().endswith('mercurial.ini'): |
|
29 | if p.lower().endswith('mercurial.ini'): | |
30 | rcpath.append(p) |
|
30 | rcpath.append(p) | |
31 | elif os.path.isdir(p): |
|
31 | elif os.path.isdir(p): | |
32 | for f, kind in osutil.listdir(p): |
|
32 | for f, kind in osutil.listdir(p): | |
33 | if f.endswith('.rc'): |
|
33 | if f.endswith('.rc'): | |
34 | rcpath.append(os.path.join(p, f)) |
|
34 | rcpath.append(os.path.join(p, f)) | |
35 | return rcpath |
|
35 | return rcpath | |
36 |
|
36 | |||
37 | def userrcpath(): |
|
37 | def userrcpath(): | |
38 | '''return os-specific hgrc search path to the user dir''' |
|
38 | '''return os-specific hgrc search path to the user dir''' | |
39 | home = os.path.expanduser('~') |
|
39 | home = os.path.expanduser('~') | |
40 | path = [os.path.join(home, 'mercurial.ini'), |
|
40 | path = [os.path.join(home, 'mercurial.ini'), | |
41 | os.path.join(home, '.hgrc')] |
|
41 | os.path.join(home, '.hgrc')] | |
42 | userprofile = os.environ.get('USERPROFILE') |
|
42 | userprofile = os.environ.get('USERPROFILE') | |
43 | if userprofile: |
|
43 | if userprofile and userprofile != home: | |
44 | path.append(os.path.join(userprofile, 'mercurial.ini')) |
|
44 | path.append(os.path.join(userprofile, 'mercurial.ini')) | |
45 | path.append(os.path.join(userprofile, '.hgrc')) |
|
45 | path.append(os.path.join(userprofile, '.hgrc')) | |
46 | return path |
|
46 | return path |
General Comments 0
You need to be logged in to leave comments.
Login now