Ticket #7750: trac_7750-search-doc.patch

File trac_7750-search-doc.patch, 4.4 KB (added by jhpalmieri, 13 years ago)
  • sage/misc/sagedoc.py

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1261516591 28800
    # Node ID cedac3ec5d7a8f8717ed08856226c3c94ac89973
    # Parent  63a11ca790a5e94daae960e27f0bb7d15595f80c
    search_doc: warning if some docs are missing
    
    diff -r 63a11ca790a5 -r cedac3ec5d7a sage/misc/sagedoc.py
    a b  
    363363        sage: 'divisors' in _search_src_or_doc('src', '^ *def prime', interact=False)
    364364        True
    365365    """
     366    ROOT = os.environ['SAGE_ROOT']
    366367    if what == 'src':
    367368        if module.find('sage') == 0:
    368369            module = module[4:].lstrip(".")  # remove 'sage' or 'sage.' from module
    369             base_path = 'devel/sage/sage'
     370            base_path = os.path.join('devel', 'sage', 'sage')
    370371        else:
    371             base_path = 'devel/sage'
    372         module = module.replace(".", "/")
     372            base_path = os.path.join('devel', 'sage')
     373        module = module.replace(".", os.sep)
    373374        exts = ['py', 'pyx', 'pxd']
    374375        title = 'Source Code'
    375376    else:
    376377        module = ''
    377         base_path = 'devel/sage/doc/output/'
    378378        exts = ['html']
    379379        title = 'Documentation'
     380        base_path = os.path.join('devel', 'sage', 'doc', 'output')
    380381
    381     base_path = os.path.join(os.environ['SAGE_ROOT'], base_path)
     382        # read the start of SAGE_ROOT/devel/sage/doc/common/builder.py
     383        # to find list of languages, documents, and documents to omit
     384        doc_path = os.path.join(ROOT, 'devel', 'sage', 'doc')
     385        builder = open(os.path.join(doc_path, 'common', 'builder.py'))
     386        s = builder.read()[:1000]
     387        builder.close()
     388        # list of languages
     389        lang = []
     390        idx = s.find("LANGUAGES")
     391        if idx != -1:
     392            start = s[idx:].find('[')
     393            end =  s[idx:].find(']')
     394            if start != -1 and end != -1:
     395                lang = s[idx+start+1:idx+end].translate(None, "'\" ").split(",")
     396        # documents in SAGE_ROOT/devel/sage/doc/LANG/ to omit
     397        omit = []
     398        idx = s.find("OMIT")
     399        if idx != -1:
     400            start = s[idx:].find('[')
     401            end =  s[idx:].find(']')
     402            if start != -1 and end != -1:
     403                omit = s[idx+start+1:idx+end].translate(None, "'\" ").split(",")
     404        # list of documents, minus the omitted ones
     405        documents = []
     406        for L in lang:
     407            documents += [os.path.join(L, dir) for dir
     408                          in os.listdir(os.path.join(doc_path, L))
     409                          if dir not in omit]
     410        # now check to see if any documents are missing.  this just
     411        # checks to see if the appropriate output directory exists,
     412        # not that it contains a complete build of the docs.
     413        missing = [os.path.join(ROOT, base_path, 'html', doc)
     414                   for doc in documents if not
     415                   os.path.exists(os.path.join(ROOT, base_path, 'html', doc))]
     416        num_missing = len(missing)
     417        if num_missing > 0:
     418            print """Warning, the following Sage documentation hasn't been built,
     419so documentation search results may be incomplete:
     420"""
     421            for s in missing:
     422                print s
     423            if num_missing > 1:
     424                print """
     425You can build these with 'sage -docbuild DOCUMENT html',
     426where DOCUMENT is one of""",
     427                for s in missing:
     428                    if s.find('en') != -1:
     429                        print "'%s'," % os.path.split(s)[-1],
     430                    else:
     431                        print "'%s'," % os.path.join(
     432                            os.path.split(os.path.split(s)[0])[-1],
     433                            os.path.split(s)[-1]),
     434                print """
     435or you can use 'sage -docbuild all html' to build all of the missing documentation."""
     436            else:
     437                s = missing[0]
     438                if s.find('en') != -1:
     439                    s = os.path.split(s)[-1]
     440                else:
     441                    s = os.path.join(
     442                        os.path.split(os.path.split(s)[0])[-1],
     443                        os.path.split(s)[-1])
     444                print """
     445You can build this with 'sage -docbuild %s html'.""" % s
     446
     447    base_path = os.path.join(ROOT, base_path)
    382448    strip = len(base_path)
    383449    results = ''
    384450    for dirpath, dirs, files in os.walk(os.path.join(base_path, module)):