import difflib
import sys
import os
input_file1 = '\\ dir\\ subdir\\ application.properties'
input_file2 = '\\ dir\\ application.properties'
output_file = str ( input_file2[ 6 :] )
def get_difference( output, input_1, input_2) :
with open ( os .getcwd ( ) + input_1, 'r' ) as hosts0:
with open ( os .getcwd ( ) + input_2, 'r' ) as hosts1:
diff = difflib .unified_diff (
hosts0.readlines ( ) ,
hosts1.readlines ( ) ,
fromfile= 'hosts0' ,
tofile= 'hosts1' ,
)
orig_stdout = sys .stdout
f = file ( output, 'w' )
sys .stdout = f
for line in diff:
print line[ 1 :] .rstrip ( "\n " )
sys .stdout = orig_stdout
f.close ( )
def delete_lines( filename) :
with open ( str ( filename) , 'r' ) as fin:
data = fin.read ( ) .splitlines ( True )
with open ( str ( filename) , 'w' ) as fout:
fout.writelines ( data[ 3 :] )
if __name__ == '__main__' :
get_difference( output_file, input_file1, input_file2)
delete_lines( output_file)
aW1wb3J0IGRpZmZsaWIKaW1wb3J0IHN5cwppbXBvcnQgb3MKCmlucHV0X2ZpbGUxID0gJ1xcZGlyXFxzdWJkaXJcXGFwcGxpY2F0aW9uLnByb3BlcnRpZXMnCmlucHV0X2ZpbGUyID0gJ1xcZGlyXFxhcHBsaWNhdGlvbi5wcm9wZXJ0aWVzJwoKb3V0cHV0X2ZpbGUgPSBzdHIoaW5wdXRfZmlsZTJbNjpdKQoKZGVmIGdldF9kaWZmZXJlbmNlKG91dHB1dCwgaW5wdXRfMSwgaW5wdXRfMik6CiAgICB3aXRoIG9wZW4ob3MuZ2V0Y3dkKCkgKyBpbnB1dF8xLCAncicpIGFzIGhvc3RzMDoKICAgICAgICB3aXRoIG9wZW4ob3MuZ2V0Y3dkKCkgKyBpbnB1dF8yLCAncicpIGFzIGhvc3RzMToKICAgICAgICAgICAgZGlmZiA9IGRpZmZsaWIudW5pZmllZF9kaWZmKAogICAgICAgICAgICAgICAgaG9zdHMwLnJlYWRsaW5lcygpLAogICAgICAgICAgICAgICAgaG9zdHMxLnJlYWRsaW5lcygpLAog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