scripts/get-developers: correct type of patches argument
authorRahul Bedarkar <rahul.bedarkar@imgtec.com>
Wed, 21 Sep 2016 18:59:14 +0000 (00:29 +0530)
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Tue, 25 Oct 2016 10:43:27 +0000 (12:43 +0200)
Current type for 'patches' argument is str. It supposed to only
contain names of files.

If we specify FileType as type, then we don't need to open file ourself
and it allows script to read patch from standard input as well.

e.g.
$ git show -1 | ./support/scripts/get-developers -

Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
support/scripts/get-developers
support/scripts/getdeveloperlib.py

index 8b1891d9996c45431931eff64e95462109eaa153..83f1e5b9b260d163579862c51a7e14174b5ac04a 100755 (executable)
@@ -5,8 +5,8 @@ import getdeveloperlib
 
 def parse_args():
     parser = argparse.ArgumentParser()
-    parser.add_argument('patches', metavar='P', type=str, nargs='*',
-                        help='list of patches')
+    parser.add_argument('patches', metavar='P', type=argparse.FileType('r'), nargs='*',
+                        help='list of patches (use - to read patches from stdin)')
     parser.add_argument('-a', dest='architecture', action='store',
                         help='find developers in charge of this architecture')
     parser.add_argument('-p', dest='package', action='store',
index 7b390417fc50a08ff901e0c377c104d718b5c43d..65191073a3b1393ed511c19192d865cb5d32c333 100644 (file)
@@ -16,19 +16,18 @@ def analyze_patch(patch):
     removed by the patch."""
     files = set()
     infras = set()
-    with open(patch, "r") as f:
-        for line in f:
-            # If the patch is adding a package, find which infra it is
-            m = FIND_INFRA_IN_PATCH.match(line)
-            if m:
-                infras.add(m.group(2))
-            if not line.startswith("+++ "):
-                continue
-            line.strip()
-            fname = line[line.find("/") + 1 : ].strip()
-            if fname == "dev/null":
-                continue
-            files.add(fname)
+    for line in patch:
+        # If the patch is adding a package, find which infra it is
+        m = FIND_INFRA_IN_PATCH.match(line)
+        if m:
+            infras.add(m.group(2))
+        if not line.startswith("+++ "):
+            continue
+        line.strip()
+        fname = line[line.find("/") + 1 : ].strip()
+        if fname == "dev/null":
+            continue
+        files.add(fname)
     return (files, infras)
 
 FIND_INFRA_IN_MK = re.compile("^\$\(eval \$\((host-)?([^-]*)-package\)\)$")