collect.py: fix open for Python versions < 3.6
authorPetr Štetiar <ynezz@true.cz>
Sun, 13 Sep 2020 09:14:44 +0000 (11:14 +0200)
committerPetr Štetiar <ynezz@true.cz>
Sun, 13 Sep 2020 09:23:38 +0000 (11:23 +0200)
 The built-in open() function has been updated to accept os.PathLike
 objects, as have all relevant functions in the os and os.path modules,
 and most other functions and classes in the standard library.

Fixes following issue:

 File "misc/collect.py", line 260, in scan
   with open(ppath, "r", encoding='utf-8') as file:
 TypeError: invalid file: PosixPath('tests/profiles/snapshots/targets/ipq806x/generic/profiles.json')

Ref: https://docs.python.org/3/whatsnew/3.6.html
Signed-off-by: Petr Štetiar <ynezz@true.cz>
misc/collect.py

index 60d863c2f9240c15cdc040c1a6a41d67f999949e..d3c1f5a5b5ece382cead24a1b106ebfedddcc85e 100755 (executable)
@@ -86,11 +86,11 @@ def merge_profiles(profiles, download_url):
 
 def update_config(config_path, versions):
     content = ""
-    with open(config_path, "r") as file:
+    with open(str(config_path), "r") as file:
         content = file.read()
 
     content = re.sub("versions:[\\s]*{[^}]*}", "versions: {}".format(versions), content)
-    with open(config_path, "w+") as file:
+    with open(str(config_path), "w+") as file:
         file.write(content)
 
 
@@ -182,7 +182,7 @@ def scrape_wget(args):
 
             profiles = {}
             for ppath in Path(path).rglob("profiles.json"):
-                with open(ppath, "r") as file:
+                with open(str(ppath), "r") as file:
                     profiles[ppath] = file.read()
 
             if len(profiles) == 0:
@@ -216,7 +216,7 @@ def merge(args):
     profiles = {}
 
     def add_path(path):
-        with open(path, "r") as file:
+        with open(str(path), "r") as file:
             profiles[path] = file.read()
 
     for path in input_paths:
@@ -259,7 +259,7 @@ def scan(args):
 
         profiles = {}
         for ppath in Path(path).rglob("profiles.json"):
-            with open(ppath, "r", encoding="utf-8") as file:
+            with open(str(ppath), "r", encoding="utf-8") as file:
                 profiles[ppath] = file.read()
 
         if len(profiles) == 0: