Exemple #1
0
def make_wiki(algo_name):
    """ Return wiki text for a given algorithm """ 
    initialize_Mantid()
    
    # Deprecated algorithms: Simply returnd the deprecation message
    deprec = mtd.algorithmDeprecationMessage(algo_name)
    if len(deprec) != 0:
        out = deprec
        out = out.replace(". Use ", ". Use [[")
        out = out.replace(" instead.", "]] instead.")
        return out
    
    alg = mtd.createAlgorithm(algo_name)
    
    out = ""
    out += "== Summary ==\n\n"
    out += alg._ProxyObject__obj.getWikiSummary().replace("\n", " ") + "\n\n"
    out += "== Properties ==\n\n"
    
    out += """{| border="1" cellpadding="5" cellspacing="0" 
!Order\n!Name\n!Direction\n!Type\n!Default\n!Description
|-\n"""

    # Do all the properties
    props = alg._ProxyObject__obj.getProperties()
    propnum = 1
    for prop in props:
        out += make_property_table_line(propnum, prop)
        propnum += 1
        
        
    # Close the table
    out += "|}\n\n"


    out += "== Description ==\n"
    out += "\n"
    desc = get_wiki_description(algo_name)
    if (desc == ""):
      out += "INSERT FULL DESCRIPTION HERE\n"
      print "Warning: missing wiki description for %s! Placeholder inserted instead." % algo_name
    else:
      out += desc + "\n"
    out += "\n"
    out += "[[Category:Algorithms]]\n"
    
    # All other categories
    categories = alg.categories()
    for categ in categories:
      out += "[[Category:" + categ + "]]\n"

    out +=  "{{AlgorithmLinks|" + algo_name + "}}\n"

    return out
Exemple #2
0
def validate_wiki(args, algos):
    """ Look for any missing wiki pages / inconsistencies """
    missing = []
    
    for algo in algos:
        print "\n================= %s ===================" % algo
        
        # Check wiki page and download contents
        page = site.Pages[algo]
        wiki = page.edit()
        lines = []
        if len(wiki) == 0:
            print "- Algorithm wiki page for %s is MISSING!" % algo
            missing.append(algo)
        else:
            lines = wiki.split('\n')
            
        source = find_algo_file(algo)
        if source=='':
            print "- Source file not found."

        # Validate the algorithm itself
        alg = mtd.createAlgorithm(algo)
        summary = alg._ProxyObject__obj.getWikiSummary()
        if len(summary) == 0: 
            print "- Summary is missing (in the code)."
            wikidoc = find_section_text(lines, "Summary", go_to_end=False, section2="")
            if args.show_missing: print wikidoc
            
#        desc = alg._ProxyObject__obj.getWikiDescription()
#        if len(desc) == 0: 
#            print "- Wiki Description is missing (in the code)."
#            desc = find_section_text(lines, "Description", True, "Introduction")
#            if args.show_missing: print desc
            
        #add_wiki_description(algo, desc)
            
        props = alg._ProxyObject__obj.getProperties()
        for prop in props:
            if len(prop.documentation) == 0:
                print "- Property %s has no documentation/tooltip (in the code)." % prop.name,
                wikidoc = find_property_doc(lines, prop.name)
                if len(wikidoc) > 0:
                    print "Found in wiki"
                    if args.show_missing: print "   \"%s\"" % wikidoc
                else:
                    print "Not found in wiki."
            
    print "\n\n"
    print "Algorithms with missing wiki page:\n", " ".join(missing) 
Exemple #3
0
def get_wiki_description(algo):
    source = find_algo_file(algo)
    if source == '': 
        alg = mtd.createAlgorithm(algo)
        return alg.getWikiDescription()
    else:
        f = open(source,'r')
        lines = f.read().split('\n')
        f.close()
        n = 0
        while not lines[n].startswith("/*WIKI*") and not lines[n].startswith('"""*WIKI*'):
            n += 1
        desc = ""
        n += 1
        while not lines[n].startswith("*WIKI*"):
            desc += lines[n] + "\n"
            n += 1
        return desc