예제 #1
0
파일: op.py 프로젝트: yeyue910107/MR-Packer
    def merge(op1, op2, rule_type, op1_child, op2_child):
	#print op1, op1.id, op2, op2.id, rule_type
	new_op = Rule(rule_type).merge(op1, op2)
	if new_op is None:
	    return None
	#print "op2.parent:", op2, op2.id, op2.parent, op2.parent.id, op2.parent.child_list
	new_op.parent = op2.parent
	new_op.child_list.extend(op1.child_list)
	new_op.child_list.extend(op2.child_list)
	new_op.child_list.remove(op1)
	new_op.id.extend(op2.id)
	new_op.id.extend(op1.id)
	print "new_op:", new_op, new_op.id
	print "op2:", op2, op2.id
	if op1.pk_list is None or len(op1.pk_list) == 0:
	    new_op.pk_list = op2.pk_list
	else:
	    new_op.pk_list = op1.pk_list
	
	op1_child.extend(op1.child_list)
	op2_child.extend(op2.child_list)

	if new_op.parent is not None:
	    print "new_op.parent:", new_op.parent, new_op.parent.child_list, new_op.parent.id
	    op2_index = new_op.parent.child_list.index(op2)
	    new_op.parent.child_list[op2_index] = new_op
	for child in new_op.child_list:
	    child.parent = new_op

	return new_op