annotate python/patchutils.py @ 545:9cf7d5cc9c2b

fix some egregious errors
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 31 Oct 2013 17:55:05 -0700
parents cb8484ae2643
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
508
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 """
509
cb8484ae2643 python/patchutils.py
Jeff Hammel <jhammel@mozilla.com>
parents: 508
diff changeset
3 utilities to deal with patches
cb8484ae2643 python/patchutils.py
Jeff Hammel <jhammel@mozilla.com>
parents: 508
diff changeset
4
508
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 http://k0s.org/blog/20100821174911
509
cb8484ae2643 python/patchutils.py
Jeff Hammel <jhammel@mozilla.com>
parents: 508
diff changeset
6 https://github.com/k0s/patchit/blob/develop/patchit.py
508
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 Tag -> hg
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 """
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 # XXX stub
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 import subprocess
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 import which
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 def call(*args, **kwargs):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 """"""
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 return subprocess.check_output(*args, **kwargs)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 class ExecuteCommands(object):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 def __init__(self, *commands, **kwargs):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 self.commands = commands
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23 self.kwargs = kwargs
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 def __call__(self):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 for command in self.commands:
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 yield call(command, **self.kwargs)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 class lsdiff(ExecuteCommands):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 commands = ['lsdiff']
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 def __call__(self):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 output = []
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 for retval in ExecuteCommands(self):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 raise NotImplementedError
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 def hg_root(directory=None):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 directory = directory if directory else os.getcwd()
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 # CLI
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 def main(args=sys.argv[1:]):
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 parser = optparse.OptionParser()
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 options, args = parser.parse_args(args)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 # find the root
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 root = hg_root()
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 # get the files
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 paths = lsdiff(root)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51 if __name__ == '__main__':
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52 main()