Advertisement
Guest User

Size change of unified diff

a guest
Jun 9th, 2011
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import fileinput
  2.  
  3. def is_diff_line(line):
  4.     return (line.startswith('-') and not line.startswith('--- ')) or \
  5.         (line.startswith('+') and not line.startswith('+++ '))
  6.  
  7. filename = None
  8. f = fileinput.input()
  9. try:
  10.     for line in f:
  11.         if f.isfirstline():
  12.             if filename:
  13.                 print filename,": size changed by", size_diff, "bytes."
  14.  
  15.             size_diff = 0
  16.             filename = f.filename()
  17.  
  18.         if is_diff_line(line):
  19.             if line[0] == '-':
  20.                 size_diff -= len(line[1:])
  21.             else:
  22.                 size_diff += len(line[1:])
  23.  
  24.     if filename:
  25.         print filename,": size changed by", size_diff, "bytes."
  26.  
  27. finally:
  28.     f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement