Skip to content

Commit

Permalink
Revert "Merge branch 'feature/6147_format' into develop"
Browse files Browse the repository at this point in the history
This reverts commit f6d2ba8, reversing
changes made to e79bd4d.
  • Loading branch information
OwenArnold committed Mar 7, 2013
1 parent f6d2ba8 commit 804e126
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 203 deletions.
181 changes: 54 additions & 127 deletions Code/Mantid/Build/wiki_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import commands
import sys
import codecs
import re
import fnmatch
import wiki_tools
from wiki_tools import *
Expand All @@ -23,8 +22,6 @@

# Junit report generator.
reporter = WikiReporter()
# no version identier
noversion = -1

#======================================================================
def get_wiki_description(algo, version):
Expand Down Expand Up @@ -70,20 +67,34 @@ def make_group_header_line(group):
return "|colspan=6 align=center| \n|-\n"
else:
return "|colspan=6 align=center|'''%s'''\n|-\n" % group

#======================================================================
def create_property_default_string(prop):
""" Create a default string

Args:
default. The property default value.
#======================================================================
def make_property_table_line(propnum, p):
""" Make one line of the property table
Args:
propnum :: number of the prop
p :: Property object
Returns:
string to add to the wiki property table default section.
string to add to the wiki
"""
# Convert to int, then float, then any string

default = prop.getDefault
defaultstr = ""
out = ""
# The property number
out += "|" + str(propnum) + "\n"
# Name of the property
out += "|" + p.name + "\n"
# Direction
direction_string = ["Input", "Output", "InOut", "None"]
out += "|" + direction_string[p.direction] + "\n"
# Type (as string) wrap an IWorkspaceProperty in a link.
if isinstance(p, IWorkspaceProperty):
out += "|[[" + str(p.type) + "]]\n"
else:
out += "|" + str(p.type) + "\n"
# Default?
default = p.getDefault
# Convert to int, then float, then any string
try:
val = int(default)
if (val >= 2147483647):
Expand All @@ -107,48 +118,14 @@ def create_property_default_string(prop):
(defaultstr == "2147483647"):
defaultstr = "Optional"

if str(prop.type) == "boolean":
if str(p.type) == "boolean":
if defaultstr == "1": defaultstr = "True"
else: defaultstr = "False"
return defaultstr

#======================================================================
def make_property_table_line(propnum, p):
""" Make one line of the property table

Args:
propnum :: number of the prop
p :: Property object
Returns:
string to add to the wiki
"""

out = ""
# The property number
out += "|" + str(propnum) + "\n"
# Name of the property
out += "|" + p.name + "\n"
# Direction
InputDirection = "Intput"
OutputDirection = "Output"
InOutDirection = "InOut"
NoDirection = "None"
direction_string = [InputDirection, OutputDirection, InOutDirection, NoDirection]
out += "|" + direction_string[p.direction] + "\n"
# Type (as string) wrap an IWorkspaceProperty in a link.
if isinstance(p, IWorkspaceProperty):
out += "|[[" + str(p.type) + "]]\n"
else:
out += "|" + str(p.type) + "\n"

if (direction_string[p.direction] == OutputDirection) and (not isinstance(p, IWorkspaceProperty)):
out += "|\n" # Nothing to show under the default section for an output properties that are not workspace properties.
elif (p.isValid == ""): #Nothing was set, but it's still valid = NOT mandatory
defaultstr = create_property_default_string(p)
if (p.isValid == ""): #Nothing was set, but it's still valid = NOT mandatory
out += "| " + defaultstr + "\n"
else:
out += "|Mandatory\n"

# Documentation
out += "|" + p.documentation.replace("\n", "<br />") + "\n"
# End of table line
Expand All @@ -164,18 +141,17 @@ def make_wiki(algo_name, version, latest_version):
@param version :: version requested
@param latest_version :: the latest algorithm
"""
out = ""

# 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"
out = deprec
out = out.replace(". Use ", ". Use [[")
out = out.replace(" instead.", "]] instead.")
return out

out = ""
alg = mtd.createAlgorithm(algo_name, version)

if (latest_version > 1):
Expand All @@ -194,13 +170,6 @@ def make_wiki(algo_name, version, latest_version):

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

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'></anchor>" % (external_image, external_image)
out += "<br clear=all>\n\n"

out += "== Python Signature ==\n\n"
out += " " + create_function_signature(algo_name) + "\n\n"
out += "== Properties ==\n\n"

out += """{| border="1" cellpadding="5" cellspacing="0"
Expand Down Expand Up @@ -313,15 +282,7 @@ def make_redirect(from_page, to_page):
page = site.Pages[from_page]
contents = "#REDIRECT [[%s]]" % to_page
page.save(contents, summary = 'Bot: created redirect to the latest version.' )

#======================================================================
def page_exists(page):
# Determine if the wikipage exists or not.
revisions = page.revisions()
for rev in revisions:
return True
return False


#======================================================================
def last_page_editor(page):
#Get the last editor of the page.
Expand All @@ -333,51 +294,22 @@ def last_page_editor(page):
def wiki_maker_page(page):
"""
returns True if the wikimaker was the last editor.
determines if there is a bot comment, which implies that the wikimaker was used to create the page last.
"""
#Get the last editor of the page.
revisions = page.revisions()
for rev in revisions:
return re.search("^Bot", rev['comment'])

#======================================================================
def create_function_signature(algo):
"""
create the function signature for the algorithm.
"""
from mantid.simpleapi import _get_function_spec
import mantid.simpleapi
_alg = getattr(mantid.simpleapi, algo)
prototype = algo + _get_function_spec(_alg)

# Replace every nth column with a newline.
nth = 4
commacount = 0
prototype_reformated = ""
for char in prototype:
if char == ',':
commacount += 1
if (commacount % nth == 0):
prototype_reformated += ",\n "
else:
prototype_reformated += char
else:
prototype_reformated += char
prototype_reformated = prototype_reformated.replace(",[Version]", "")
return prototype_reformated
return ("WikiMaker" == last_page_editor(page))

#======================================================================
def do_algorithm(args, algo, version):
def do_algorithm(args, algo, version=-1):
""" Do the wiki page
@param algo :: the name of the algorithm, and it's version as a tuple"""
@param algo_tuple :: the name of the algorithm, and it's version as a tuple"""
global mtd
is_latest_version = True
latest_version = -1
# Find the latest version
latest_version = mtd.createAlgorithm(algo, noversion).version()
if (version == noversion):
version = latest_version
latest_version = mtd.createAlgorithm(algo, -1).version()
if (version == -1): version = latest_version

print "Latest version of %s is %d. You are making version %d." % (algo, latest_version, version)

# What should the name on the wiki page be?
wiki_page_name = algo
if latest_version > 1:
Expand All @@ -393,10 +325,6 @@ def do_algorithm(args, algo, version):

#Open the page with the name of the algo
page = site.Pages[wiki_page_name]
if not page_exists(page):
print "Error: Wiki Page wiki_page_name %s does not exist on the wiki." % wiki_page_name
reporter.addFailureNoPage(algo, wiki_page_name)
return

old_contents = page.edit() + "\n"

Expand All @@ -418,27 +346,26 @@ def do_algorithm(args, algo, version):
print

wiki_maker_edited_last = wiki_maker_page(page)
last_modifier = last_page_editor(page);

if not wiki_maker_edited_last:
print "The last edit was manual. Last edit NOT done by WIKIMAKER script."
print "The last editor was NOT the WIKIMAKER"
last_modifier = last_page_editor(page);
print "The last page editor was ", last_modifier
if not last_modifier == None:
# Report a failure test case
reporter.addFailureTestCase(algo, version, last_modifier, ''.join(diff_list))
else:
print "The last edit was automatic via a script. Last edit was done by WIKIMAKER script."
print "Last change by ", last_modifier

if args.dryrun:
print "Dry run of saving page to http://www.mantidproject.org/%s" % wiki_page_name
elif wiki_maker_edited_last or args.force or confirm("Do you want to replace the website wiki page?", True):
print "Saving page to http://www.mantidproject.org/%s" % wiki_page_name
page.save(new_contents, summary = 'Bot: replaced contents using the wiki_maker.py script.' )

if wiki_maker_edited_last or args.force or confirm("Do you want to replace the website wiki page?", True):
if not args.dryrun:
print "Saving page to http://www.mantidproject.org/%s" % wiki_page_name
page.save(new_contents, summary = 'Bot: replaced contents using the wiki_maker.py script.' )
else:
print "Dry run of saving page to http://www.mantidproject.org/%s" % wiki_page_name

saved_text = open(wiki_page_name+'.txt', 'w')
saved_text.write(new_contents)
saved_text.close()


#======================================================================
if __name__ == "__main__":

Expand Down Expand Up @@ -475,8 +402,8 @@ def do_algorithm(args, algo, version):
const=True, default=False,
help="Force overwriting the wiki page on the website if different (don't ask the user)")

parser.add_option('--alg-version', dest='algversion', default=noversion,
help='Algorithm version to create the wiki for. Latest version if absent.')
parser.add_option('--no-version-check', dest='no_version_check', action='store_true',
help='Do not perform version check on algorithm name.')

parser.add_option('--report', dest='wikimakerreport', default=False, action='store_const', const=True,
help="Record authors and corresponding algorithm wiki-pages that have not been generated with the wiki-maker")
Expand Down Expand Up @@ -522,7 +449,7 @@ def do_algorithm(args, algo, version):
do_algorithm(args, algo_tuple[0], algo_tuple[1][0])
else:
for algo in algos:
do_algorithm(args, algo, int(args.algversion))
do_algorithm(args, algo, -1)

if args.wikimakerreport:
junit_file = open('WikiMakerReport.xml', 'w')
Expand Down
70 changes: 55 additions & 15 deletions Code/Mantid/Build/wiki_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,75 @@ def getResults(self):
docEl.setAttribute('time',str(self._time_taken))
return self._doc.toxml()

def __addGenericFailure__(self, contents, algorithm):
def __failureMessage__(self, algorithm, version, last_editor, diff):
return "Algorithm %s Version %i last edited by %s is out of sync.\n\nDifferences are:\n\n%s" % (algorithm, version, last_editor, diff)

def addSuccessTestCase(self, algorithm):
elem = self._doc.createElement('testcase')
elem.setAttribute('classname', 'WikiMaker')
elem.setAttribute('name', algorithm)
self._failures.append(algorithm)
failEl = self._doc.createElement('failure')
failEl.appendChild(self._doc.createTextNode(contents))
elem.appendChild(failEl)
time_taken = 0
elem.setAttribute('time',str(time_taken))
elem.setAttribute('totalTime',str(time_taken))
self._doc.documentElement.appendChild(elem)

def addSuccessTestCase(self, algorithm):

def addFailureTestCase(self, algorithm, version, last_editor, diff):
elem = self._doc.createElement('testcase')
elem.setAttribute('classname', 'WikiMaker')
elem.setAttribute('name', algorithm)
self._failures.append(algorithm)
failEl = self._doc.createElement('failure')
failEl.appendChild(self._doc.createTextNode(self.__failureMessage__(algorithm, version, last_editor, diff)))
elem.appendChild(failEl)
time_taken = 0
elem.setAttribute('time',str(time_taken))
elem.setAttribute('totalTime',str(time_taken))
self._doc.documentElement.appendChild(elem)


def addFailureTestCase(self, algorithm, version, last_editor, diff):
contents = "Algorithm %s Version %i last edited by %s is out of sync.\n\nDifferences are:\n\n%s" % (algorithm, version, last_editor, diff)
self.__addGenericFailure__(contents, algorithm)





def addFailureNoPage(self, algorithm, expected_page):
contents = "Algorithm %s has no wiki page. Wiki page expected %s still needs creating." % (algorithm, expected_page)
self.__addGenericFailure__(contents, algorithm)

""" def dispatchResults(self, result):
''' This relies on the order and names of the items to give the correct output '''
test_name = result.name.split('.')
if len(test_name) > 1:
class_name = '.'.join(test_name[:-1])
name = test_name[-1]
else:
class_name = result.name
name = result.name
elem = self._doc.createElement('testcase')
elem.setAttribute('classname',"SystemTests." + class_name)
elem.setAttribute('name',name)
if result.status == 'skipped':
self._skipped.append(result)
skipEl = self._doc.createElement('skipped')
if len(result.output) > 0:
if "Missing required file" in result.output:
skipEl.setAttribute('message', "MissingRequiredFile")
else:
skipEl.setAttribute('message', result.output)
skipEl.appendChild(self._doc.createTextNode(result.output))
elem.appendChild(skipEl)
elif result.status != 'success':
self._failures.append(result)
failEl = self._doc.createElement('failure')
failEl.setAttribute('file',result.filename)
output = ''
if len(result.output) > 0:
output += result.output
if len(output) > 0:
failEl.appendChild(self._doc.createTextNode(output))
elem.appendChild(failEl)
time_taken = 0.0
for t in result.resultLogs():
if t[0] == 'iteration time_taken':
time_taken = float(t[1].split(' ')[1])
self._time_taken += time_taken
elem.setAttribute('time',str(time_taken))
elem.setAttribute('totalTime',str(time_taken))
self._doc.documentElement.appendChild(elem)
"""

2 changes: 1 addition & 1 deletion Code/Mantid/Framework/PythonAPI/mantidsimple.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def algorithm_wrapper(*args, **kwargs):
for p in mtd._getPropertyOrder(_algm_object):
prop = _algm_object.getProperty(p)
# Mandatory parameters are those for which the default value is not valid
if len(str(prop.isValid()))>0:
if len(str(prop.isValid))>0:
arg_list.append(p)
else:
# None is not quite accurate here, but we are reproducing the
Expand Down

0 comments on commit 804e126

Please sign in to comment.