From: Petr Štetiar Date: Sun, 13 Sep 2020 09:14:44 +0000 (+0200) Subject: collect.py: fix open for Python versions < 3.6 X-Git-Tag: v3.0.0~14 X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=ee62fade7eac2a7ade21720d0272c3bc814c6ea8;p=web%2Ffirmware-selector-openwrt-org.git collect.py: fix open for Python versions < 3.6 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 --- 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: