mercurial/extensions.py
changeset 14317 660b0c1b6196
parent 14316 d5b525697ddb
child 14318 1f46be4689ed
equal deleted inserted replaced
14316:d5b525697ddb 14317:660b0c1b6196
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 import imp, os
     8 import imp, os
     9 import util, cmdutil, help, error
     9 import util, cmdutil, error
    10 from i18n import _, gettext
    10 from i18n import _, gettext
    11 
    11 
    12 _extensions = {}
    12 _extensions = {}
    13 _order = []
    13 _order = []
    14 _ignore = ['hbisect', 'bookmarks', 'parentrevspec']
    14 _ignore = ['hbisect', 'bookmarks', 'parentrevspec']
   207         if name in exts or name in _order or name == '__init__':
   207         if name in exts or name in _order or name == '__init__':
   208             continue
   208             continue
   209         exts[name] = path
   209         exts[name] = path
   210     return exts
   210     return exts
   211 
   211 
       
   212 def _moduledoc(file):
       
   213     '''return the top-level python documentation for the given file
       
   214 
       
   215     Loosely inspired by pydoc.source_synopsis(), but rewritten to
       
   216     handle triple quotes and to return the whole text instead of just
       
   217     the synopsis'''
       
   218     result = []
       
   219 
       
   220     line = file.readline()
       
   221     while line[:1] == '#' or not line.strip():
       
   222         line = file.readline()
       
   223         if not line:
       
   224             break
       
   225 
       
   226     start = line[:3]
       
   227     if start == '"""' or start == "'''":
       
   228         line = line[3:]
       
   229         while line:
       
   230             if line.rstrip().endswith(start):
       
   231                 line = line.split(start)[0]
       
   232                 if line:
       
   233                     result.append(line)
       
   234                 break
       
   235             elif not line:
       
   236                 return None # unmatched delimiter
       
   237             result.append(line)
       
   238             line = file.readline()
       
   239     else:
       
   240         return None
       
   241 
       
   242     return ''.join(result)
       
   243 
   212 def _disabledhelp(path):
   244 def _disabledhelp(path):
   213     '''retrieve help synopsis of a disabled extension (without importing)'''
   245     '''retrieve help synopsis of a disabled extension (without importing)'''
   214     try:
   246     try:
   215         file = open(path)
   247         file = open(path)
   216     except IOError:
   248     except IOError:
   217         return
   249         return
   218     else:
   250     else:
   219         doc = help.moduledoc(file)
   251         doc = moduledoc(file)
   220         file.close()
   252         file.close()
   221 
   253 
   222     if doc: # extracting localized synopsis
   254     if doc: # extracting localized synopsis
   223         return gettext(doc).splitlines()[0]
   255         return gettext(doc).splitlines()[0]
   224     else:
   256     else: