Created
June 23, 2011 20:51
-
-
Save mrdaemon/1043602 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Shitty validator for xmerge's sorts. | |
Rather simplisitic and naive. | |
Then again, I am not a real programmer :( | |
""" | |
__author__ = "Alexandre Gauthier <[email protected]>" | |
__copyright__ = "Copyright (c) 2011-2012" | |
__license__ = "BSD" | |
__version__ = "0.1-prototype" | |
import argparse | |
import collections | |
import sys | |
def uniquify(iterable): | |
""" Generator to make duplicate list members unique """ | |
for item, count in collections.Counter(iterable).items(): | |
if count > 1: | |
for i in range(count): | |
suffix = "!" * i | |
#print "DEBUG: duplicate line in source set, suffix: %s " % \ | |
# (suffix) | |
yield ''.join((item, suffix)) | |
else: | |
yield item | |
def _init_args(): | |
""" Initialize the arguments parser and return a parser instance """ | |
parser = argparse.ArgumentParser(description="Validate xsort output") | |
parser.add_argument('-i', metavar="original-input-file", required=True, | |
type=argparse.FileType('rt')) | |
parser.add_argument('-o', metavar="processed-output-file", required=True, | |
type=argparse.FileType('rt')) | |
return parser | |
def main(): | |
""" Program entry point """ | |
print "xsort analysis program v %s " % (__version__) | |
print __author__ | |
print "%s\n" % (__copyright__) | |
parser = _init_args() | |
params = None | |
try: | |
params = parser.parse_args() | |
except IOError, e: | |
parser.error(str(e)) | |
sys.exit(1) | |
# Sum up parameters | |
print "ORIGINAL:", params.i | |
print "SORTED: %s\n" % params.o | |
print "Processing files. This may take forever." | |
result = set(uniquify(params.i)).symmetric_difference(uniquify(params.o)) | |
rsize = len(result) | |
print "RESULT:", | |
if rsize == 0: | |
print "The files are equivalent in content." | |
else: | |
print "FILES DIFFER! %s alien entries in either file." % (rsize) | |
print "-------------------- ENTRIES: ----------------------" | |
for entry in result: | |
print entry | |
print "Done." | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment