Skip to content

Commit

Permalink
Do a partial migration and save that result. Refs #6328
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Feb 25, 2013
1 parent 11942a0 commit bc39639
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/lib1to2/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def translate(self, orig_code):
tree = astbuilder.parse(translated)
tree = api_call_replace.apply_to_ast(tree)

return astbuilder.regenerate(tree)
return astbuilder.regenerate(tree), api_call_replace.errors
12 changes: 10 additions & 2 deletions Code/Mantid/scripts/lib1to2/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ def migrate(self):
input_as_str = input_file.read()
input_file.close()

converted_str = self.grammar.translate(input_as_str)
converted_str, errors = self.grammar.translate(input_as_str)

output_file = open(self.filename, 'w')
filename = self.filename
if len(errors) > 0:
filename = self.filename + ".partial"
errors.append("Partial translation stored in '%s'" % filename)

output_file = open(filename, 'w')
output_file.write(converted_str)
output_file.close()

if len(errors) > 0:
raise RuntimeError("\n".join(errors))

outcome = MigrationStatus(MigrationStatus.Migrated)
return Report(self.filename, outcome)

Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/scripts/lib1to2/rules/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

class Rules(object):

errors = []

def apply_to_ast(self, tree):
"""
Apply the transformation to the AST
Expand Down
7 changes: 3 additions & 4 deletions Code/Mantid/scripts/lib1to2/rules/simpleapireplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SimpleAPIFunctionCallReplace(rules.Rules):

func_regex = __FUNCTION_CALL_REGEX__
current_line = None

def __init__(self):
rules.Rules.__init__(self)

Expand Down Expand Up @@ -64,15 +64,14 @@ def apply_to_node(self, name, parent):
"""
# Two steps:
# First - transform to all keywords
# Second - remove output properties from list and put on lhs
nchildren = len(parent.children)
no_lhs = True
if nchildren == 2:
# Child 0 = whole function call
fn_call_node = parent.children[0]
no_lhs = True
elif nchildren == 3:
raise RuntimeError("Unable to handle assignment from algorithm call")
self.errors.append("Unable to handle assignment for '%s' algorithm call" % (name))

# Get the argument list node: child 1 = arglist parent node then child 1 = arg list
arglist_node = fn_call_node.children[1].children[1]
Expand Down Expand Up @@ -324,7 +323,7 @@ def find_parent_nodes(self, tree):
return self._nodes

def visit_node(self, node):
if node.type == syms.power:
if node.type == syms.power and hasattr(node, "value"):
fn_name = node.children[0].value
if _is_mantid_algorithm(fn_name):
# Make sure we get the whole expression including any assignment
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/scripts/lib1to2/rules/stringreplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
(re.compile("\.getSampleDetails"), ".getRun"),
(re.compile("mtd\.settings"), "config"),
(re.compile("mtd\.getConfigProperty"), "config.getString"),
(re.compile("mtd\.workspaceExists"), "mtd.doesExist"),
(re.compile("(mtd|mantid).sendLogMessage"), "logger.notice")
]

Expand Down

0 comments on commit bc39639

Please sign in to comment.