def _generate_path_between_rules(old_rules, new_rules):
 old_by_chain = _get_rules_by_chain(old_rules)
 new_by_chain = _get_rules_by_chain(new_rules)
 (old_chains, new_chains) = (set(old_by_chain.keys()), set(new_by_chain.keys()))
 statements = [(':%s - [0:0]' % c) for c in sorted((new_chains - old_chains))]
 sg_chains = []
 other_chains = []
 for chain in sorted((old_chains | new_chains)):
  if ('-sg-' in chain):
   sg_chains.append(chain)
  else:
   other_chains.append(chain)
 for chain in (other_chains + sg_chains):
  statements += _generate_chain_diff_iptables_commands(chain, old_by_chain[chain], new_by_chain[chain])
 for chain in sorted((old_chains - new_chains)):
  statements += [('-X %s' % chain)]
 return statements

def _generate_path_between_rules ( old_rules , new_rules ) : old_by_chain = _get_rules_by_chain ( old_rules ) new_by_chain = _get_rules_by_chain ( new_rules ) ( old_chains , new_chains ) = ( set ( old_by_chain . keys ( ) ) , set ( new_by_chain . keys ( ) ) ) statements = [ ( ':%s - [0:0]' % c ) for c in sorted ( ( new_chains - old_chains ) ) ] sg_chains = [ ] other_chains = [ ] for chain in sorted ( ( old_chains | new_chains ) ) : if ( '-sg-' in chain ) : sg_chains . append ( chain ) else : other_chains . append ( chain ) for chain in ( other_chains + sg_chains ) : statements += _generate_chain_diff_iptables_commands ( chain , old_by_chain [ chain ] , new_by_chain [ chain ] ) for chain in sorted ( ( old_chains - new_chains ) ) : statements += [ ( '-X %s' % chain ) ] return statements
generates iptables commands to get from old_rules to new_rules .