-
Notifications
You must be signed in to change notification settings - Fork 1
/
list-patch-file.py
37 lines (32 loc) · 996 Bytes
/
list-patch-file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os, sys, re
def patches_from_directory(dir=None):
directory_children = os.listdir(sys.path[0] if dir is None else dir)
patch_files = []
for path in directory_children:
if os.path.isfile(path) and path.endswith('.patch'):
patch_files.append(path)
elif os.path.isdir(path):
patch_files.extend(patches_from_directory(path))
return patch_files
def paths_from_patch_file(patch_file):
paths = []
with open(patch_file) as f:
lines = f.readlines()
for line in lines:
if line.startswith('diff '):
path = re.search('(?:--git a)(\S+)', line).group(1)
paths.append(path)
return paths
def paths_from_cwd():
paths = []
patch_files = patches_from_directory()
for patch_file in patch_files:
paths.extend(paths_from_patch_file(patch_file))
paths = list(set(paths))
paths.sort()
return paths
def main():
for index, path in enumerate(paths_from_cwd()):
print '%s: %s' % (index, path)
if __name__ == '__main__':
main()