| 
508
 | 
     1 
 | 
| 
 | 
     2 """
 | 
| 
509
 | 
     3 utilities to deal with patches
 | 
| 
 | 
     4 
 | 
| 
508
 | 
     5 http://k0s.org/blog/20100821174911
 | 
| 
509
 | 
     6 https://github.com/k0s/patchit/blob/develop/patchit.py
 | 
| 
508
 | 
     7 Tag -> hg
 | 
| 
 | 
     8 """
 | 
| 
 | 
     9 
 | 
| 
 | 
    10 # XXX stub
 | 
| 
 | 
    11 
 | 
| 
 | 
    12 import subprocess
 | 
| 
 | 
    13 import which
 | 
| 
 | 
    14 
 | 
| 
 | 
    15 def call(*args, **kwargs):
 | 
| 
 | 
    16     """"""
 | 
| 
 | 
    17     return subprocess.check_output(*args, **kwargs)
 | 
| 
 | 
    18 
 | 
| 
 | 
    19 class ExecuteCommands(object):
 | 
| 
 | 
    20 
 | 
| 
 | 
    21     def __init__(self, *commands, **kwargs):
 | 
| 
 | 
    22         self.commands = commands
 | 
| 
 | 
    23         self.kwargs = kwargs
 | 
| 
 | 
    24 
 | 
| 
 | 
    25     def __call__(self):
 | 
| 
 | 
    26         for command in self.commands:
 | 
| 
 | 
    27             yield call(command, **self.kwargs)
 | 
| 
 | 
    28 
 | 
| 
 | 
    29 class lsdiff(ExecuteCommands):
 | 
| 
 | 
    30     commands = ['lsdiff']
 | 
| 
 | 
    31     def __call__(self):
 | 
| 
 | 
    32         output = []
 | 
| 
 | 
    33         for retval in ExecuteCommands(self):
 | 
| 
 | 
    34             raise NotImplementedError
 | 
| 
 | 
    35 
 | 
| 
 | 
    36 def hg_root(directory=None):
 | 
| 
 | 
    37     directory = directory if directory else os.getcwd()
 | 
| 
 | 
    38 
 | 
| 
 | 
    39 # CLI
 | 
| 
 | 
    40 
 | 
| 
 | 
    41 def main(args=sys.argv[1:]):
 | 
| 
 | 
    42     parser = optparse.OptionParser()
 | 
| 
 | 
    43     options, args = parser.parse_args(args)
 | 
| 
 | 
    44 
 | 
| 
 | 
    45     # find the root
 | 
| 
 | 
    46     root = hg_root()
 | 
| 
 | 
    47 
 | 
| 
 | 
    48     # get the files
 | 
| 
 | 
    49     paths = lsdiff(root)
 | 
| 
 | 
    50 
 | 
| 
 | 
    51 if __name__ == '__main__':
 | 
| 
 | 
    52     main()
 |