mercurial/ui.py
changeset 2944 2efa9b8aed30
parent 2738 ad4155e757da
child 2945 731f6b3d27c2
equal deleted inserted replaced
2943:8e59010158ce 2944:2efa9b8aed30
    10 demandload(globals(), "errno getpass os re smtplib socket sys tempfile")
    10 demandload(globals(), "errno getpass os re smtplib socket sys tempfile")
    11 demandload(globals(), "ConfigParser templater traceback util")
    11 demandload(globals(), "ConfigParser templater traceback util")
    12 
    12 
    13 class ui(object):
    13 class ui(object):
    14     def __init__(self, verbose=False, debug=False, quiet=False,
    14     def __init__(self, verbose=False, debug=False, quiet=False,
    15                  interactive=True, traceback=False, parentui=None):
    15                  interactive=True, traceback=False, parentui=None,
       
    16                  readhooks=[]):
    16         self.overlay = {}
    17         self.overlay = {}
    17         if parentui is None:
    18         if parentui is None:
    18             # this is the parent of all ui children
    19             # this is the parent of all ui children
    19             self.parentui = None
    20             self.parentui = None
       
    21             self.readhooks = list(readhooks)
    20             self.cdata = ConfigParser.SafeConfigParser()
    22             self.cdata = ConfigParser.SafeConfigParser()
    21             self.readconfig(util.rcpath())
    23             self.readconfig(util.rcpath())
    22 
    24 
    23             self.quiet = self.configbool("ui", "quiet")
    25             self.quiet = self.configbool("ui", "quiet")
    24             self.verbose = self.configbool("ui", "verbose")
    26             self.verbose = self.configbool("ui", "verbose")
    32             self.prev_header = []
    34             self.prev_header = []
    33             self.revlogopts = self.configrevlog()
    35             self.revlogopts = self.configrevlog()
    34         else:
    36         else:
    35             # parentui may point to an ui object which is already a child
    37             # parentui may point to an ui object which is already a child
    36             self.parentui = parentui.parentui or parentui
    38             self.parentui = parentui.parentui or parentui
       
    39             self.readhooks = list(parentui.readhooks or readhooks)
    37             parent_cdata = self.parentui.cdata
    40             parent_cdata = self.parentui.cdata
    38             self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults())
    41             self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults())
    39             # make interpolation work
    42             # make interpolation work
    40             for section in parent_cdata.sections():
    43             for section in parent_cdata.sections():
    41                 self.cdata.add_section(section)
    44                 self.cdata.add_section(section)
    76         if root is None:
    79         if root is None:
    77             root = os.path.expanduser('~')
    80             root = os.path.expanduser('~')
    78         for name, path in self.configitems("paths"):
    81         for name, path in self.configitems("paths"):
    79             if path and "://" not in path and not os.path.isabs(path):
    82             if path and "://" not in path and not os.path.isabs(path):
    80                 self.cdata.set("paths", name, os.path.join(root, path))
    83                 self.cdata.set("paths", name, os.path.join(root, path))
       
    84         for hook in self.readhooks:
       
    85             hook(self)
    81 
    86 
    82     def setconfig(self, section, name, val):
    87     def setconfig(self, section, name, val):
    83         self.overlay[(section, name)] = val
    88         self.overlay[(section, name)] = val
    84 
    89 
    85     def config(self, section, name, default=None):
    90     def config(self, section, name, default=None):