##// END OF EJS Templates
rcutil: split osrcpath to return default.d paths (API)...
Jun Wu -
r31680:448889f9 default
parent child Browse files
Show More
@@ -1,64 +1,62
1 1 # rcutil.py - utilities about config paths, special config sections etc.
2 2 #
3 3 # Copyright Mercurial Contributors
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 import os
11 11
12 12 from . import (
13 13 encoding,
14 14 osutil,
15 15 pycompat,
16 16 util,
17 17 )
18 18
19 19 if pycompat.osname == 'nt':
20 20 from . import scmwindows as scmplatform
21 21 else:
22 22 from . import scmposix as scmplatform
23 23
24 24 systemrcpath = scmplatform.systemrcpath
25 25 userrcpath = scmplatform.userrcpath
26 26
27 def osrcpath():
28 '''return default os-specific hgrc search path'''
27 def defaultrcpath():
28 '''return rc paths in default.d'''
29 29 path = []
30 30 defaultpath = os.path.join(util.datapath, 'default.d')
31 31 if os.path.isdir(defaultpath):
32 32 for f, kind in osutil.listdir(defaultpath):
33 33 if f.endswith('.rc'):
34 34 path.append(os.path.join(defaultpath, f))
35 path.extend(systemrcpath())
36 path.extend(userrcpath())
37 path = [os.path.normpath(f) for f in path]
38 35 return path
39 36
40 37 _rcpath = None
41 38
42 39 def rcpath():
43 40 '''return hgrc search path. if env var HGRCPATH is set, use it.
44 41 for each item in path, if directory, use files ending in .rc,
45 42 else use item.
46 43 make HGRCPATH empty to only look in .hg/hgrc of current repo.
47 44 if no HGRCPATH, use default os-specific path.'''
48 45 global _rcpath
49 46 if _rcpath is None:
50 47 if 'HGRCPATH' in encoding.environ:
51 48 _rcpath = []
52 49 for p in encoding.environ['HGRCPATH'].split(pycompat.ospathsep):
53 50 if not p:
54 51 continue
55 52 p = util.expandpath(p)
56 53 if os.path.isdir(p):
57 54 for f, kind in osutil.listdir(p):
58 55 if f.endswith('.rc'):
59 56 _rcpath.append(os.path.join(p, f))
60 57 else:
61 58 _rcpath.append(p)
62 59 else:
63 _rcpath = osrcpath()
60 paths = defaultrcpath() + systemrcpath() + userrcpath()
61 _rcpath = pycompat.maplist(os.path.normpath, paths)
64 62 return _rcpath
General Comments 0
You need to be logged in to leave comments. Login now