Commits

Ezio Melotti committed b6297f3

Collect the path/files affected by the patches and use them to build a json file.

Comments (3)

  1. Ezio Melotti author

    Can python-patch do anything about it? I've seen dates in a few different formats and also things like '(working copy)' that are not dates. There are also patches that contain spaces in the filename.

Files changed (2)

 ^\.locally
+^files.json$
 \.pyc$
 ~$
 from __future__ import print_function
 from datetime import datetime
 from sys import version_info
+from collections import defaultdict, OrderedDict
 
 START = datetime.now()
 
 from os import makedirs
 from os.path import abspath, exists, dirname
 import sys
+import json
 
 PY3K = sys.version_info >= (3, 0)
 if PY3K:
     cached = True
   return (filename, cached)
 
+def cleanpath(source, target):
+    # best-effort function to clean up the path
+    path = source
+    if not source or source == 'dev/null':
+        path = target
+    # some paths are followed by the date
+    path = path.split()[0]
+    if path.startswith(('a/', 'b/')):
+        path = path[2:]
+    if path.endswith('.orig'):
+        path = path[:-5]
+    parts = path.split('/')
+    if parts[0].startswith('Python-'):
+        parts = parts[1:]
+    path = '/'.join(parts)
+    return path
+
 issue_files = {}    # 'number' => []
 issue_patches = {}  # 'number' => []
 module_issues = {}
+python_files = defaultdict(set)  # 'path/file' => {(issuen, title), ...}
+
 for issuen in open_issues:
   issue = bpo.display('issue'+issuen, 'files', 'title')
   issue_files[issuen] = issue['files']
       issue_patches[issuen].append(path)
       # detect if there is a module for the patch path
       for entry in patchset.items:
+        path = cleanpath(entry.source, entry.target)
+        python_files[path].add((issuen, issue['title']))
         module = (stdlib.getmodname(entry.source) or
                   stdlib.getmodname(entry.target))
         if module:
 print('')
 for module, issues in module_issues.items():
   print('  %s: %d' % (module, len(issues)))
+print('Files affected by patches: %s' % len(python_files))
+
+# convert from a dict of (path, set(issues))
+# to an OrderedDict of (path, list(issues))
+data = OrderedDict((path, sorted(issues))
+                   for path,issues in sorted(python_files.items()))
+with open('files.json', 'w') as f:
+    json.dump(data, f)
+
 print('')
 print('Finished in ' + str(datetime.now() - START)[:-4])