view python/sortdiff.py @ 631:d87a17e1abac

-> http://k0s.org/hg/TextShaper/rev/e6f680d25d63
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 00:49:18 -0800
parents 84a865a880a8
children
line wrap: on
line source

#!/usr/bin/env python

import optparse
import os
import sys

def main(args=sys.argv[1:]):

    usage = '%prog [options]'
    parser = optparse.OptionParser(usage=usage, description=__doc__)
    options, args = parser.parse_args(args)

    lines = sys.stdin.readlines()
    diff = {'+': set(),
            '-': set()}
    for line in lines:
        for key, value in diff.items():
            if line.startswith(key):
                value.add(line[1:].strip())

    added = diff['+'].difference(diff['-'])
    minus = diff['-'].difference(diff['+'])

    print '+++'
    for line in sorted(added):
        print line
    print '---'
    for line in sorted(minus):
        print line

if __name__ == '__main__':
    main()