Show More
@@ -74,7 +74,7 b' def hook(ui, repo, hooktype, node=None, ' | |||
|
74 | 74 | user = getpass.getuser() |
|
75 | 75 | cfg = ui.config('acl', 'config') |
|
76 | 76 | if cfg: |
|
77 |
ui.read |
|
|
77 | ui.readconfig(cfg, sections = ['acl.allow', 'acl.deny']) | |
|
78 | 78 | allow = buildmatch(ui, repo, user, 'acl.allow') |
|
79 | 79 | deny = buildmatch(ui, repo, user, 'acl.deny') |
|
80 | 80 |
@@ -139,7 +139,7 b' class bugzilla_2_16(object):' | |||
|
139 | 139 | timeout = int(self.ui.config('bugzilla', 'timeout', 5)) |
|
140 | 140 | usermap = self.ui.config('bugzilla', 'usermap') |
|
141 | 141 | if usermap: |
|
142 |
self.ui.read |
|
|
142 | self.ui.readconfig(usermap, 'usermap') | |
|
143 | 143 | self.ui.note(_('connecting to %s:%s as %s, password %s\n') % |
|
144 | 144 | (host, db, user, '*' * len(passwd))) |
|
145 | 145 | self.conn = MySQLdb.connect(host=host, user=user, passwd=passwd, |
@@ -99,7 +99,7 b' class notifier(object):' | |||
|
99 | 99 | self.ui = ui |
|
100 | 100 | cfg = self.ui.config('notify', 'config') |
|
101 | 101 | if cfg: |
|
102 |
self.ui.read |
|
|
102 | self.ui.readconfig(cfg, sections=['usersubs', 'reposubs']) | |
|
103 | 103 | self.repo = repo |
|
104 | 104 | self.stripcount = int(self.ui.config('notify', 'strip', 0)) |
|
105 | 105 | self.root = self.strip(self.repo.root) |
@@ -20,6 +20,8 b' def updateconfig(source, dest, sections=' | |||
|
20 | 20 | for section in sections: |
|
21 | 21 | if not dest.has_section(section): |
|
22 | 22 | dest.add_section(section) |
|
23 | if not source.has_section(section): | |
|
24 | continue | |
|
23 | 25 | for name, value in source.items(section, raw=True): |
|
24 | 26 | dest.set(section, name, value) |
|
25 | 27 | |
@@ -39,7 +41,8 b' class ui(object):' | |||
|
39 | 41 | self.ucdata = util.configparser() |
|
40 | 42 | |
|
41 | 43 | # we always trust global config files |
|
42 | self.readconfig(util.rcpath(), assumetrusted=True) | |
|
44 | for f in util.rcpath(): | |
|
45 | self.readconfig(f, assumetrusted=True) | |
|
43 | 46 | else: |
|
44 | 47 | # parentui may point to an ui object which is already a child |
|
45 | 48 | self.parentui = parentui.parentui or parentui |
@@ -51,6 +54,7 b' class ui(object):' | |||
|
51 | 54 | |
|
52 | 55 | # we want the overlay from the parent, not the root |
|
53 | 56 | self.overlay = dupconfig(parentui.overlay) |
|
57 | self.fixconfig() | |
|
54 | 58 | |
|
55 | 59 | def __getattr__(self, key): |
|
56 | 60 | return getattr(self.parentui, key) |
@@ -84,66 +88,36 b' class ui(object):' | |||
|
84 | 88 | 'user %s, group %s\n') % (f, user, group)) |
|
85 | 89 | return False |
|
86 | 90 | |
|
87 |
def readconfig(self, fn, root=None, assumetrusted=False |
|
|
88 | cdata = util.configparser() | |
|
91 | def readconfig(self, filename, root=None, assumetrusted=False, | |
|
92 | sections = None): | |
|
93 | try: | |
|
94 | fp = open(filename) | |
|
95 | except IOError: | |
|
96 | if not sections: # ignore unless we were looking for something | |
|
97 | return | |
|
98 | raise | |
|
89 | 99 | |
|
90 | if isinstance(fn, basestring): | |
|
91 | fn = [fn] | |
|
92 | for f in fn: | |
|
93 | try: | |
|
94 | fp = open(f) | |
|
95 | except IOError: | |
|
96 | continue | |
|
97 | ||
|
98 | trusted = assumetrusted or self._is_trusted(fp, f) | |
|
100 | cdata = util.configparser() | |
|
101 | trusted = sections or assumetrusted or self._is_trusted(fp, filename) | |
|
99 | 102 | |
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
103 | try: | |
|
104 | cdata.readfp(fp, filename) | |
|
105 | except ConfigParser.ParsingError, inst: | |
|
106 | msg = _("Failed to parse %s\n%s") % (filename, inst) | |
|
107 | if trusted: | |
|
108 | raise util.Abort(msg) | |
|
109 | self.warn(_("Ignored: %s\n") % msg) | |
|
107 | 110 | |
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
111 | if trusted: | |
|
112 | updateconfig(cdata, self.cdata, sections) | |
|
113 | updateconfig(self.overlay, self.cdata, sections) | |
|
114 | updateconfig(cdata, self.ucdata, sections) | |
|
115 | updateconfig(self.overlay, self.ucdata, sections) | |
|
113 | 116 | |
|
114 | 117 | if root is None: |
|
115 | 118 | root = os.path.expanduser('~') |
|
116 | 119 | self.fixconfig(root=root) |
|
117 | 120 | |
|
118 | def readsections(self, filename, *sections): | |
|
119 | """Read filename and add only the specified sections to the config data | |
|
120 | ||
|
121 | The settings are added to the trusted config data. | |
|
122 | """ | |
|
123 | if not sections: | |
|
124 | return | |
|
125 | ||
|
126 | cdata = util.configparser() | |
|
127 | try: | |
|
128 | try: | |
|
129 | fp = open(filename) | |
|
130 | except IOError, inst: | |
|
131 | raise util.Abort(_("unable to open %s: %s") % | |
|
132 | (filename, getattr(inst, "strerror", inst))) | |
|
133 | try: | |
|
134 | cdata.readfp(fp, filename) | |
|
135 | finally: | |
|
136 | fp.close() | |
|
137 | except ConfigParser.ParsingError, inst: | |
|
138 | raise util.Abort(_("failed to parse %s\n%s") % (filename, inst)) | |
|
139 | ||
|
140 | for section in sections: | |
|
141 | if not cdata.has_section(section): | |
|
142 | cdata.add_section(section) | |
|
143 | ||
|
144 | updateconfig(cdata, self.cdata, sections) | |
|
145 | updateconfig(cdata, self.ucdata, sections) | |
|
146 | ||
|
147 | 121 | def fixconfig(self, section=None, name=None, value=None, root=None): |
|
148 | 122 | # translate paths relative to root (or home) into absolute paths |
|
149 | 123 | if section is None or section == 'paths': |
@@ -473,10 +473,10 b' adding foo/file.txt revisions' | |||
|
473 | 473 | adding quux/file.py revisions |
|
474 | 474 | added 3 changesets with 3 changes to 3 files |
|
475 | 475 | calling hook pretxnchangegroup.acl: hgext.acl.hook |
|
476 |
error: pretxnchangegroup.acl hook |
|
|
476 | error: pretxnchangegroup.acl hook raised an exception: [Errno 2] No such file or directory: '../acl.config' | |
|
477 | 477 | transaction abort! |
|
478 | 478 | rollback completed |
|
479 | abort: unable to open ../acl.config: No such file or directory | |
|
479 | abort: No such file or directory: ../acl.config | |
|
480 | 480 | no rollback information available |
|
481 | 481 | 0:6675d58eff77 |
|
482 | 482 |
@@ -60,7 +60,7 b' EOF' | |||
|
60 | 60 | |
|
61 | 61 | echo % fail for config file is missing |
|
62 | 62 | hg --cwd b rollback |
|
63 |
hg --cwd b pull ../a 2>&1 | grep ' |
|
|
63 | hg --cwd b pull ../a 2>&1 | grep 'error.*\.notify\.conf' > /dev/null && echo pull failed | |
|
64 | 64 | |
|
65 | 65 | touch "$HGTMP/.notify.conf" |
|
66 | 66 |
@@ -133,13 +133,13 b" testui(user='abc', group='def', cuser=No" | |||
|
133 | 133 | print "# prints debug warnings" |
|
134 | 134 | u = testui(user='abc', group='def', cuser='foo', debug=True) |
|
135 | 135 | |
|
136 | print "# ui.readsections" | |
|
136 | print "# ui.readconfig sections" | |
|
137 | 137 | filename = 'foobar' |
|
138 | 138 | f = open(filename, 'w') |
|
139 | 139 | f.write('[foobar]\n') |
|
140 | 140 | f.write('baz = quux\n') |
|
141 | 141 | f.close() |
|
142 |
u.read |
|
|
142 | u.readconfig(filename, sections = ['foobar']) | |
|
143 | 143 | print u.config('foobar', 'baz') |
|
144 | 144 | |
|
145 | 145 |
General Comments 0
You need to be logged in to leave comments.
Login now