code: def install_hg(path):
      
      hook = op.join(path, 'hgrc')
      if not op.isfile(hook):
          open(hook, 'w+').close()
  
      c = ConfigParser()
      c.readfp(open(hook, 'r'))
      if not c.has_section('hooks'):
          c.add_section('hooks')
  
      if not c.has_option('hooks', 'commit'):
          c.set('hooks', 'commit', 'python:pylama.hooks.hg_hook')
  
      if not c.has_option('hooks', 'qrefresh'):
          c.set('hooks', 'qrefresh', 'python:pylama.hooks.hg_hook')
  
      c.write(open(hook, 'w+'))
docs: Install hook in Mercurial repository.