def _ask_user(self, question, node): """Print a problem and ask the user to fix it, print it or ignore it.""" while True: print() print(question) print() print("Would you like to:") print("p) Print more information.") print("s) Print source for the node in question. This could be large.") print("i) Ignore the problem. Allow other methods of mark resolution.") print("f) Stop and fix the problem.") ans = "" while ans not in ["p", "s", "i", "f"]: ans = input("Choose an option: ") print() if ans == "p": self._node_information(node) elif ans == "s": sourcewriter.printSource(node, prettywriter.PrettyWriter) elif ans == "i": return elif ans == "f": raise automarker.UserStop
def _print_block(self, statements, perm, disp, markings=False): """Print a block of statements in a particular permutation.""" if disp == "index": for i in perm: print(str(i) + " - ", end="") print() else: ord_stat = list(statements.ordered_children()) for i in perm: child = statements[ord_stat[i]] if disp == "type": print(str(i) + ": " + child.type(), end="") elif disp == "code": print() sourcewriter.printSource(child, prettywriter.PrettyWriter) if markings: complete_markings = reorder.Reorderer(CustomAST([child])).check_markings() if complete_markings: print(" - Completely marked") else: print(" - Not marked") if disp == "type" or markings: print() self._related_parsecmd.ast.augmented = True
def write_to_stdout(self, tree, writer, force): if not force: print("Are you sure you wish to print to stdout?..This could be big!") print("Use -f to confirm, otherwise add a filename argument.") return False sourcewriter.printSource(tree, writer)
def _create_branch(self, brancher, category, info, args): """Deal with a request for a branch type.""" method = getattr(brancher, category) #{ # "if-branch": brancher.if_branch, # "ifelse-branch": brancher.ifelse_branch, # "except-branch": brancher.except_branch, # "while-branch": brancher.while_branch, # }[category] status = method() if status == None: print("Cannot create this type of branch, not enough information in the brancher.") return if status == False: print("There is not enough information in the brancher to create a thorough transformation, but we can create the basic branch.") # Confirm if not all info if info == "check": return if not self._confirm("continue"): print("Branching cancelled.") return if info == "check": # Warnings done print("The brancher has enough information to perform the requested type of branch.") return self._related_explorecmd._ensure_node_sync() if self._related_explorecmd.ast_current == None: print("There is no AST to transform. Have you create one with the parse command?") return block = self._get_block() if block == None: print("This node does not represent a list of statements so we cannot perform any transformations.") return if info == True: result = method(block) else: try: start, end = info.split("-") except ValueError: try: containing = int(info) except ValueError: print("Invalid index for branching.") return else: result = method(block, containing) else: result = method(block, start, end) # We have a result! newnode, changed = result print() for i,node in enumerate(newnode): if i in changed: print("(+++++++++") printSource(newnode[node], PrettyWriter) if i in changed: print("+++++++++)") print() if self._confirm("Would you like to commit this change to the AST", wishto=False): self._set_block(newnode) return