annotate python/applyrealhard.py @ 520:3281b9fe4433

wip
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 20 Sep 2013 08:43:59 -0700
parents 8b990efa4648
children c4432bd3cb9b
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
8b990efa4648 python/applyrealhard.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 usage = '%prog [options]'
8b990efa4648 python/applyrealhard.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 parser = optparse.OptionParser(usage=usage, description=__doc__)
8b990efa4648 python/applyrealhard.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 parser.add_option('-d', '--directory', default=os.getcwd())
8b990efa4648 python/applyrealhard.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 options, args = parser.parse_args(args)
8b990efa4648 python/applyrealhard.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35
520
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
36 # get rejects
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
37 rej = rejects(options.directory)
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
38 if not rej:
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
39 parser.error("No rejects")
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
40 print 'rej:\n%s\n' % '\n'.join([' %s' % r for r in rej])
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
41
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
42 for r in rej:
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
43 # find the corresponding file
Jeff Hammel <jhammel@mozilla.com>
parents: 519
diff changeset
44 pass
519
8b990efa4648 python/applyrealhard.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45
8b990efa4648 python/applyrealhard.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 if __name__ == '__main__':
8b990efa4648 python/applyrealhard.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 main()