comparison mercurial/scmwindows.py @ 18690:4c6f7f0dadab

scmutil: split platform-specific bits into their own modules This parallels what's done for the util module, which imports either mercurial.posix or mercurial.windows as 'platform' and then slurps the appropriate functions into its own namespace.
author Kevin Bullock <kbullock@ringworld.org>
date Tue, 12 Feb 2013 11:36:21 -0600
parents
children e3ddb4068757
comparison
equal deleted inserted replaced
18689:12721a20ed30 18690:4c6f7f0dadab
1 import os
2 import osutil
3 import _winreg
4
5 def systemrcpath():
6 '''return default os-specific hgrc search path'''
7 rcpath = []
8 filename = util.executablepath()
9 # Use mercurial.ini found in directory with hg.exe
10 progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
11 if os.path.isfile(progrc):
12 rcpath.append(progrc)
13 return rcpath
14 # Use hgrc.d found in directory with hg.exe
15 progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
16 if os.path.isdir(progrcd):
17 for f, kind in osutil.listdir(progrcd):
18 if f.endswith('.rc'):
19 rcpath.append(os.path.join(progrcd, f))
20 return rcpath
21 # else look for a system rcpath in the registry
22 value = util.lookupreg('SOFTWARE\\Mercurial', None,
23 _winreg.HKEY_LOCAL_MACHINE)
24 if not isinstance(value, str) or not value:
25 return rcpath
26 value = util.localpath(value)
27 for p in value.split(os.pathsep):
28 if p.lower().endswith('mercurial.ini'):
29 rcpath.append(p)
30 elif os.path.isdir(p):
31 for f, kind in osutil.listdir(p):
32 if f.endswith('.rc'):
33 rcpath.append(os.path.join(p, f))
34 return rcpath
35
36 def userrcpath():
37 '''return os-specific hgrc search path to the user dir'''
38 home = os.path.expanduser('~')
39 path = [os.path.join(home, 'mercurial.ini'),
40 os.path.join(home, '.hgrc')]
41 userprofile = os.environ.get('USERPROFILE')
42 if userprofile:
43 path.append(os.path.join(userprofile, 'mercurial.ini'))
44 path.append(os.path.join(userprofile, '.hgrc'))
45 return path