comparison python/hgrc.py @ 904:30006a5583fa

fix hgrc.py for python3
author Jeff Hammel <k0scist@gmail.com>
date Thu, 11 Apr 2024 08:23:38 -0700
parents 6da7d26e257b
children
comparison
equal deleted inserted replaced
903:08da6a1bb4c9 904:30006a5583fa
37 ### global methods 37 ### global methods
38 38
39 def isHTTP(path): 39 def isHTTP(path):
40 """is path an {http,https}:// URL?""" 40 """is path an {http,https}:// URL?"""
41 return urlparse.urlsplit(path)[0] in ('http', 'https') 41 return urlparse.urlsplit(path)[0] in ('http', 'https')
42
42 43
43 class section(object): 44 class section(object):
44 def __init__(self, section_name, *section_names): 45 def __init__(self, section_name, *section_names):
45 self.sections = [section_name] 46 self.sections = [section_name]
46 self.sections.extend(section_names) 47 self.sections.extend(section_names)
56 @section('paths') 57 @section('paths')
57 def set_default(parser, default): 58 def set_default(parser, default):
58 """set [paths]:default""" 59 """set [paths]:default"""
59 parser.set('paths', 'default', default) 60 parser.set('paths', 'default', default)
60 61
62
61 @section('paths') 63 @section('paths')
62 def set_default_push(parser, default_push): 64 def set_default_push(parser, default_push):
63 """ 65 """
64 set [paths]:default-push to `default_push` 66 set [paths]:default-push to `default_push`
65 """ 67 """
66 parser.set('paths', 'default-push', default_push) 68 parser.set('paths', 'default-push', default_push)
69
67 70
68 def set_default_push_to_ssh(parser): 71 def set_default_push_to_ssh(parser):
69 """ 72 """
70 set `[paths]:default-push` to that given by `[paths]:default` but 73 set `[paths]:default-push` to that given by `[paths]:default` but
71 turn the protocol to 'ssh' 74 turn the protocol to 'ssh'
173 else: 176 else:
174 assert os.path.isfile(path), "%s is not a file, exiting" % path 177 assert os.path.isfile(path), "%s is not a file, exiting" % path
175 hgrc.append(path) 178 hgrc.append(path)
176 179
177 # raise errors if encountered 180 # raise errors if encountered
178 if filter(None, errors.values()): 181 _errors = list(filter(None, errors.values()))
182 if _errors:
183 print('errors encountered: {}'.format(_errors))
179 for key, value in errors.items(): 184 for key, value in errors.items():
180 if value: 185 if value:
181 print ('%s: %s' % (key, ', '.join(value))) 186 print('%s: %s' % (key, ', '.join(value)))
182 parser.exit(1) 187 parser.exit(1)
183 188
184 # construct ConfigParser objects and 189 # construct ConfigParser objects and
185 # ensure that all the files are parseable 190 # ensure that all the files are parseable
186 config = {} 191 config = {}
187 for path in hgrc: 192 for path in hgrc:
188 config[path] = ConfigParser() 193 config[path] = ConfigParser()
189 if isinstance(path, basestring): 194 if isinstance(path, str):
190 if os.path.exists(path): 195 if os.path.exists(path):
191 config[path].read(path) 196 config[path].read(path)
192 elif path in urls: 197 elif path in urls:
193 if 'default' not in actions: 198 if 'default' not in actions:
194 set_default(config[path], path) 199 set_default(config[path], path)