misc/collect.py: move file check into update_conf v3.0.3
authorMoritz Warning <moritzwarning@web.de>
Mon, 28 Sep 2020 09:26:04 +0000 (11:26 +0200)
committerPetr Štetiar <ynezz@true.cz>
Wed, 7 Oct 2020 19:35:53 +0000 (21:35 +0200)
This makes the usage behavior more consistent across different call sites.

misc/collect.py

index 0b2968d3f05dd1f16dc6b47243eb208cbba1329f..95a1c3914c3275710ea4f6ab7089a64fa829ba81 100755 (executable)
@@ -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())):