import sys import bowler from fissix.fixer_util import Attr, Call, Name def rewriteUsingBase_addEditWorkflowComment( node: bowler.LN, capture: bowler.Capture, filename: bowler.Filename, ) -> None: args, = capture['function_arguments'] comment = args.children[4].clone() comment.children[0].prefix = '' call = Call(Name("Base_addEditWorkflowComment"), [comment]) attr = Attr(args.children[0].clone(), call) attr[0].prefix = node.prefix node.replace(attr) def isUsingEditAction( node: bowler.LN, capture: bowler.Capture, filename: bowler.Filename, ) -> bool: args = capture['function_arguments'] return args \ and len(args[0].children) >= 2 \ and args[0].children[2].type == bowler.TOKEN.STRING \ and args[0].children[2].value in ("'edit_action'", '"edit_action"') # usage: # pip install bowler # python (this script.py) folder_to_refactor bowler\ .Query(sys.argv[1], python_version=2)\ .select_method('doActionFor')\ .filter(isUsingEditAction)\ .modify(rewriteUsingBase_addEditWorkflowComment)\ .idiff()