annotate python/applyrealhard.py @ 564:047a53a8fbad

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