From a6e144a6ba02597f0ae91d1492d6bfc26063a7e4 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Mon, 28 Sep 2020 11:26:04 +0200 Subject: [PATCH] misc/collect.py: move file check into update_conf This makes the usage behavior more consistent across different call sites. --- misc/collect.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/misc/collect.py b/misc/collect.py index 0b2968d..95a1c39 100755 --- a/misc/collect.py +++ b/misc/collect.py @@ -120,13 +120,19 @@ def merge_profiles(profiles, download_url): def update_config(www_path, versions): config_path = "{}/config.js".format(www_path) - content = "" - with open(str(config_path), "r", encoding="utf-8") as file: - content = file.read() - content = re.sub("versions:[\\s]*{[^}]*}", "versions: {}".format(versions), content) - with open(str(config_path), "w+") as file: - file.write(content) + if os.path.isfile(config_path): + content = "" + with open(str(config_path), "r", encoding="utf-8") as file: + content = file.read() + + content = re.sub( + "versions:[\\s]*{[^}]*}", "versions: {}".format(versions), content + ) + with open(str(config_path), "w+") as file: + file.write(content) + else: + sys.stderr.write("Warning: File not found: {}\n".format(config_path)) """ @@ -159,10 +165,6 @@ def scrape(args): ) return profiles - if not os.path.isfile(config_path): - print("file not found: {}".format(config_path)) - exit(1) - # fetch release URLs with urllib.request.urlopen(url) as infile: for path in re.findall(r"href=[\"']?([^'\" >]+)", str(infile.read())): -- 2.30.2