comparison mercurial/util_win32.py @ 5619:55d3e845736a

win32: favor local mercurial.ini over registry key Hopefully this is the best of both worlds. Multiple py2exe based installers can coexist on one machine, while source and lib based Mercurial users can still use a registry key in lieu of resorting to HGRCPATH.
author Steve Borho <steve@borho.org>
date Wed, 05 Dec 2007 22:57:35 -0600
parents 7c976bb039af
children c67dfc4ecba6 e52383c7e7ab
comparison
equal deleted inserted replaced
5618:6e1a61b14bbf 5619:55d3e845736a
178 return details[0] != winerror.ERROR_INVALID_PARAMETER 178 return details[0] != winerror.ERROR_INVALID_PARAMETER
179 return True 179 return True
180 180
181 def system_rcpath_win32(): 181 def system_rcpath_win32():
182 '''return default os-specific hgrc search path''' 182 '''return default os-specific hgrc search path'''
183 proc = win32api.GetCurrentProcess()
184 try:
185 # This will fail on windows < NT
186 filename = win32process.GetModuleFileNameEx(proc, 0)
187 except:
188 filename = win32api.GetModuleFileName(0)
189 # Use mercurial.ini found in directory with hg.exe
190 progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
191 if os.path.isfile(progrc):
192 return [progrc]
193 # else look for a system rcpath in the registry
183 try: 194 try:
184 value = win32api.RegQueryValue( 195 value = win32api.RegQueryValue(
185 win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Mercurial') 196 win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Mercurial')
186 rcpath = [] 197 rcpath = []
187 for p in value.split(os.pathsep): 198 for p in value.split(os.pathsep):
191 for f, kind in osutil.listdir(p): 202 for f, kind in osutil.listdir(p):
192 if f.endswith('.rc'): 203 if f.endswith('.rc'):
193 rcpath.append(os.path.join(p, f)) 204 rcpath.append(os.path.join(p, f))
194 return rcpath 205 return rcpath
195 except pywintypes.error: 206 except pywintypes.error:
196 pass 207 return []
197 proc = win32api.GetCurrentProcess()
198 try:
199 # This will fail on windows < NT
200 filename = win32process.GetModuleFileNameEx(proc, 0)
201 except:
202 filename = win32api.GetModuleFileName(0)
203 return [os.path.join(os.path.dirname(filename), 'mercurial.ini')]
204 208
205 def user_rcpath_win32(): 209 def user_rcpath_win32():
206 '''return os-specific hgrc search path to the user dir''' 210 '''return os-specific hgrc search path to the user dir'''
207 userdir = os.path.expanduser('~') 211 userdir = os.path.expanduser('~')
208 if sys.getwindowsversion() != 2 and userdir == '~': 212 if sys.getwindowsversion() != 2 and userdir == '~':