##// END OF EJS Templates
ui: add configoverride context manager...
Kostia Balytskyi -
r30480:b0a8337b default
parent child Browse files
Show More
@@ -7,6 +7,7 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import contextlib
10 import errno
11 import errno
11 import getpass
12 import getpass
12 import inspect
13 import inspect
@@ -1193,6 +1194,23 b' class ui(object):'
1193 " update your code.)") % version
1194 " update your code.)") % version
1194 self.develwarn(msg, stacklevel=2, config='deprec-warn')
1195 self.develwarn(msg, stacklevel=2, config='deprec-warn')
1195
1196
1197 @contextlib.contextmanager
1198 def configoverride(self, overrides, source=""):
1199 """Context manager for temporary config overrides
1200 `overrides` must be a dict of the following structure:
1201 {(section, name) : value}"""
1202 backups = {}
1203 for (section, name), value in overrides.items():
1204 backups[(section, name)] = self.backupconfig(section, name)
1205 self.setconfig(section, name, value, source)
1206 yield
1207 for __, backup in backups.items():
1208 self.restoreconfig(backup)
1209 # just restoring ui.quiet config to the previous value is not enough
1210 # as it does not update ui.quiet class member
1211 if ('ui', 'quiet') in overrides:
1212 self.fixconfig(section='ui')
1213
1196 class paths(dict):
1214 class paths(dict):
1197 """Represents a collection of paths and their configs.
1215 """Represents a collection of paths and their configs.
1198
1216
General Comments 0
You need to be logged in to leave comments. Login now