[docs]defcolumn_diff(a,b,width=130):cmd_str='diff -y {}{} -W {}'.format(a,b,width)try:res=run(cmd_str.split(),stdout=subprocess.PIPE,stderr=subprocess.STDOUT)exceptCalledProcessErrorase:return'Error in generating file diff: {}'.format(e)returnres.stdout.decode('utf-8')
[docs]defunified_diff(a,b,as_string=False):""" Generates a unified diff of two files: ``a`` and ``b``. The files must be passed in as absolute paths. """try:withio.open(a,'r')asf1:withio.open(b,'r')asf2:diff=difflib.unified_diff(f1.readlines(),f2.readlines(),fromfile=f1.name,tofile=f2.name,)except(OSError,IOError)ase:raiseOasisException("Exception raised in 'unified_diff'",e)ifas_string:return''.join(diff)returndiff