From ee62fade7eac2a7ade21720d0272c3bc814c6ea8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Sun, 13 Sep 2020 11:14:44 +0200 Subject: [PATCH] collect.py: fix open for Python versions < 3.6 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- misc/collect.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/misc/collect.py b/misc/collect.py index 60d863c..d3c1f5a 100755 --- a/misc/collect.py +++ b/misc/collect.py @@ -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: -- 2.30.2