| 
519
 | 
     1 #!/usr/bin/env python
 | 
| 
 | 
     2 
 | 
| 
 | 
     3 # XXX STUB
 | 
| 
 | 
     4 
 | 
| 
 | 
     5 """
 | 
| 
 | 
     6 http://code.google.com/p/python-patch/
 | 
| 
 | 
     7 """
 | 
| 
 | 
     8 
 | 
| 
 | 
     9 import difflib
 | 
| 
 | 
    10 import optparse
 | 
| 
 | 
    11 import os
 | 
| 
 | 
    12 import subprocess
 | 
| 
 | 
    13 import sys
 | 
| 
 | 
    14 from which import which
 | 
| 
 | 
    15 
 | 
| 
 | 
    16 here = os.path.dirname(os.path.realpath(__file__))
 | 
| 
 | 
    17 
 | 
| 
 | 
    18 wiggle = which('wiggle')
 | 
| 
 | 
    19 
 | 
| 
 | 
    20 def find(directory, pattern):
 | 
| 
 | 
    21     # TODO: -> python
 | 
| 
520
 | 
    22     return [i for i in subprocess.check_output(['find', directory, '-iname', pattern]).splitlines() if i.strip()]
 | 
| 
 | 
    23 
 | 
| 
519
 | 
    24 def rejects(directory):
 | 
| 
 | 
    25     """all rejects in directory"""
 | 
| 
 | 
    26     # TODO: not call out to find
 | 
| 
520
 | 
    27     return find(directory, '*.rej')
 | 
| 
519
 | 
    28 
 | 
| 
 | 
    29 def main(args=sys.argv[1:]):
 | 
| 
 | 
    30 
 | 
| 
521
 | 
    31     # parse command line args
 | 
| 
519
 | 
    32     usage = '%prog [options]'
 | 
| 
 | 
    33     parser = optparse.OptionParser(usage=usage, description=__doc__)
 | 
| 
 | 
    34     parser.add_option('-d', '--directory', default=os.getcwd())
 | 
| 
 | 
    35     options, args = parser.parse_args(args)
 | 
| 
 | 
    36 
 | 
| 
521
 | 
    37     # sanity check
 | 
| 
 | 
    38     if not wiggle:
 | 
| 
 | 
    39         parser.error("Need wiggle")
 | 
| 
 | 
    40 
 | 
| 
520
 | 
    41     # get rejects
 | 
| 
 | 
    42     rej = rejects(options.directory)
 | 
| 
 | 
    43     if not rej:
 | 
| 
 | 
    44         parser.error("No rejects")
 | 
| 
 | 
    45     print 'rej:\n%s\n' % '\n'.join([' %s' % r for r in rej])
 | 
| 
 | 
    46 
 | 
| 
521
 | 
    47     # get the originals
 | 
| 
 | 
    48     orig = []
 | 
| 
520
 | 
    49     for r in rej:
 | 
| 
 | 
    50         # find the corresponding file
 | 
| 
521
 | 
    51         o = r.rsplit('.rej')[0]
 | 
| 
 | 
    52         if not os.path.exists(o):
 | 
| 
 | 
    53             parser.error("%s not found")
 | 
| 
 | 
    54         orig.append(o)
 | 
| 
 | 
    55 
 | 
| 
 | 
    56     # try to wiggle them
 | 
| 
519
 | 
    57 
 | 
| 
 | 
    58 if __name__ == '__main__':
 | 
| 
 | 
    59     main()
 |