Skip to content

Commit

Permalink
refs #6709. Merge functionality.
Browse files Browse the repository at this point in the history
Works for both Debug and release builds. The usage section is also what was specified.
  • Loading branch information
OwenArnold committed Mar 18, 2013
1 parent b803194 commit 2a8a6de
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 197 deletions.
183 changes: 1 addition & 182 deletions Code/Mantid/Build/wiki_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,82 +14,7 @@
import platform

# Junit report generator.
reporter = WikiReporter()

#======================================================================
def get_wiki_description(algo, version):
tryUseDescriptionFromBinaries = True
return get_custom_wiki_section(algo, version, "*WIKI*", tryUseDescriptionFromBinaries)

#======================================================================
def get_wiki_usage(algo, version):
wiki_usage = get_custom_wiki_section(algo, version, "*WIKI_USAGE*")
if wiki_usage:
return (True, wiki_usage)
else:
wiki_no_sig_usage = get_custom_wiki_section(algo, version, "*WIKI_USAGE_NO_SIGNATURE*")
return (False, wiki_no_sig_usage)

#======================================================================
def get_custom_wiki_section(algo, version, tag, tryUseDescriptionFromBinaries=False):
""" Extract the text between the *WIKI* tags in the .cpp file
@param algo :: name of the algorithm
@param version :: version, -1 for latest
"""

global mtd

desc = ""
source = find_algo_file(algo, version)
if source == '' and tryUseDescriptionFromBinaries:
alg = mtd.createAlgorithm(algo, version)
print "Getting algorithm description from binaries."
return alg.getWikiDescription()
elif source == '' and not tryUseDescriptionFromBinaries:
print "Warning: Cannot find source for algorithm"
return desc
else:
f = open(source,'r')
lines = f.read().split('\n')
print lines
f.close()

print algo
try:
# Start and end location markers.
start_tag_cpp = "/" + tag
start_tag_python = '"""%s' % tag
end_tag_cpp = tag + "/"
end_tag_python = '%s"""' % tag

# Find the start and end lines for the wiki section in the source.
start_index = 0
end_index = 0
for line_index in range(0, len(lines)):
line = lines[line_index]
if line.lstrip().startswith(start_tag_cpp) or line.lstrip().startswith(start_tag_python):
start_index = line_index + 1
continue
if line.lstrip().startswith(end_tag_cpp) or line.lstrip().startswith(end_tag_python):
end_index = line_index
break

# Concatinate across the range.
for line_index in range(start_index, end_index):
desc += lines[line_index] + "\n"

if start_index == end_index:
print "No algorithm %s section in source." % tag
else:
print "Getting algorithm %s section from source." % tag

except IndexError:
print "No algorithm %s section in source." % tag
return desc



reporter = WikiReporter()

#======================================================================
def make_group_header_line(group):
Expand Down Expand Up @@ -184,112 +109,6 @@ def make_property_table_line(propnum, p):
out += "|-\n"
return out



#======================================================================
def make_wiki(algo_name, version, latest_version):
""" Return wiki text for a given algorithm
@param algo_name :: name of the algorithm (bare)
@param version :: version requested
@param latest_version :: the latest algorithm
"""

external_image = "http://download.mantidproject.org/algorithm_screenshots/ScreenShotImages/%s_dlg.png" % algo_name
out = "<anchor url='%s'><img width=400px align='right' src='%s' style='position:relative; z-index:1000;'></anchor>\n\n" % (external_image, external_image)

# Deprecated algorithms: Simply returnd the deprecation message
print "Creating... ", algo_name, version
deprec = mtd.algorithmDeprecationMessage(algo_name,version)
if len(deprec) != 0:
out = "== Deprecated ==\n\n"
deprecstr = deprec
deprecstr = deprecstr.replace(". Use ", ". Use [[")
deprecstr = deprecstr.replace(" instead.", "]] instead.")
out += deprecstr
out += "\n\n"

alg = mtd.createAlgorithm(algo_name, version)

if (latest_version > 1):
if (version < latest_version):
out += "Note: This page refers to version %d of %s. The latest version is %d - see [[%s v.%d]].\n\n" % (version, algo_name, latest_version, algo_name, latest_version)
else:
out += "Note: This page refers to version %d of %s. "% (version, algo_name)
if latest_version > 2:
out += "The documentation for older versions is available at: "
else:
out += "The documentation for the older version is available at: "
for v in xrange(1,latest_version):
out += "[[%s v.%d]] " % (algo_name, v)
out += "\n\n"


out += "== Summary ==\n\n"
out += alg._ProxyObject__obj.getWikiSummary().replace("\n", " ") + "\n\n"
# Fetch the custom usage wiki section.
include_signature, custom_usage = get_wiki_usage(algo_name, version)
out += "\n\n== Usage ==\n\n"
if include_signature:
out += " " + create_function_signature(alg, algo_name) + "\n\n"
out += "<br clear=all>\n\n"
out += custom_usage
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
last_group = ""
for prop in props:
group = prop.getGroup
if (group != last_group):
out += make_group_header_line(group)
last_group = group
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,version)
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:
n = categ.find("\\")
if (n>0):
# Category is "first\second"
first = categ[0:n]
second = categ[n+1:]
out += "[[Category:" + first + "]]\n"
out += "[[Category:" + second + "]]\n"
else:
out += "[[Category:" + categ + "]]\n"

# Point to the right source ffiles
if version > 1:
out += "{{AlgorithmLinks|%s%d}}\n" % (algo_name, version)
else:
out += "{{AlgorithmLinks|%s}}\n" % (algo_name)

return out





#======================================================================
Expand Down
77 changes: 62 additions & 15 deletions Code/Mantid/Build/wiki_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,80 @@ def add_wiki_description(algo, wikidesc):
f = codecs.open(source, encoding='utf-8', mode='w+')
f.write(text)
f.close()

#======================================================================
def get_wiki_description(algo, version):
tryUseDescriptionFromBinaries = True
return get_custom_wiki_section(algo, version, "*WIKI*", tryUseDescriptionFromBinaries)

#======================================================================
def get_wiki_usage(algo, version):
wiki_usage = get_custom_wiki_section(algo, version, "*WIKI_USAGE*")
if wiki_usage:
return (True, wiki_usage)
else:
wiki_no_sig_usage = get_custom_wiki_section(algo, version, "*WIKI_USAGE_NO_SIGNATURE*")
return (False, wiki_no_sig_usage)

#======================================================================
def get_custom_wiki_section(algo, version, tag, tryUseDescriptionFromBinaries=False):
""" Extract the text between the *WIKI* tags in the .cpp file
@param algo :: name of the algorithm
@param version :: version, -1 for latest
"""

desc = ""
source = find_algo_file(algo, version)
if source == '':
if source == '' and tryUseDescriptionFromBinaries:
from mantid.api import AlgorithmManager
alg = AlgorithmManager.createUnmanaged(algo, version)
print "Getting algorithm description from binaries."
return alg.getWikiDescription()
elif source == '' and not tryUseDescriptionFromBinaries:
print "Warning: Cannot find source for algorithm"
return desc
else:
f = open(source,'r')
lines = f.read().split('\n')
print lines
f.close()
n = 0
while not lines[n].lstrip().startswith("/*WIKI*") and not lines[n].lstrip().startswith('"""*WIKI*'):
n += 1
desc = ""
n += 1
while not lines[n].lstrip().startswith("*WIKI*"):
desc += lines[n] + "\n"
n += 1
print "Getting algorithm description from source."
return desc

print algo
try:
# Start and end location markers.
start_tag_cpp = "/" + tag
start_tag_python = '"""%s' % tag
end_tag_cpp = tag + "/"
end_tag_python = '%s"""' % tag

# Find the start and end lines for the wiki section in the source.
start_index = 0
end_index = 0
for line_index in range(0, len(lines)):
line = lines[line_index]
if line.lstrip().startswith(start_tag_cpp) or line.lstrip().startswith(start_tag_python):
start_index = line_index + 1
continue
if line.lstrip().startswith(end_tag_cpp) or line.lstrip().startswith(end_tag_python):
end_index = line_index
break

# Concatinate across the range.
for line_index in range(start_index, end_index):
desc += lines[line_index] + "\n"

if start_index == end_index:
print "No algorithm %s section in source." % tag
else:
print "Getting algorithm %s section from source." % tag

except IndexError:
print "No algorithm %s section in source." % tag
return desc



#======================================================================
def create_function_signature(alg, algo_name):
"""
Expand Down Expand Up @@ -520,14 +565,16 @@ def do_make_wiki(algo_name, version, latest_version):
for v in xrange(1,latest_version):
out += "[[%s v.%d]] " % (algo_name, v)
out += "\n\n"


out += "== Summary ==\n\n"
out += alg.getWikiSummary().replace("\n", " ") + "\n\n"

# Fetch the custom usage wiki section.
include_signature, custom_usage = get_wiki_usage(algo_name, version)
out += "\n\n== Usage ==\n\n"
out += " " + create_function_signature(alg, algo_name) + "\n\n"
if include_signature:
out += " " + create_function_signature(alg, algo_name) + "\n\n"
out += "<br clear=all>\n\n"
out += custom_usage
out += "== Properties ==\n\n"

out += """{| border="1" cellpadding="5" cellspacing="0"
Expand Down

0 comments on commit 2a8a6de

Please sign in to comment.