From: Moritz Warning Date: Mon, 28 Sep 2020 09:26:04 +0000 (+0200) Subject: misc/collect.py: move file check into update_conf X-Git-Tag: v3.0.3 X-Git-Url: http://git.openwrt.org/project/luci.git;master?a=commitdiff_plain;h=a6e144a6ba02597f0ae91d1492d6bfc26063a7e4;p=web%2Ffirmware-selector-openwrt-org.git misc/collect.py: move file check into update_conf This makes the usage behavior more consistent across different call sites. --- 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())):