[gnome-shell] cldr2json: Do not overwrite existing files



commit da673639cac6d05cc588630465e7b994b529546f
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Mar 27 16:33:48 2020 +0100

    cldr2json: Do not overwrite existing files
    
    We had various requests to improve existing OSK layouts, but
    haven't accepted them so far as any changes would be overridden
    when regenerating the layouts.
    
    However as the upstream layouts at http://www.unicode.org are
    extremely slow to update(*), we shouldn't block all improvements.
    
    So instead of letting the update script override all existing
    layouts, just make it import new layouts.
    
    (*) not their fault, as the android layouts are a downstream to Google
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1136

 data/cldr2json/cldr2json.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/data/cldr2json/cldr2json.py b/data/cldr2json/cldr2json.py
index 7d6d71792d..49a3809cdc 100755
--- a/data/cldr2json/cldr2json.py
+++ b/data/cldr2json/cldr2json.py
@@ -165,8 +165,12 @@ def convert_file(source_file, destination_path):
         return False
     destination_file = os.path.join(destination_path, xkb_name + ".json")
 
-    with open(destination_file, 'w', encoding="utf-8") as dest_fd:
-        json.dump(root, dest_fd, ensure_ascii=False, indent=2, sort_keys=True)
+    try:
+        with open(destination_file, 'x', encoding="utf-8") as dest_fd:
+            json.dump(root, dest_fd, ensure_ascii=False, indent=2, sort_keys=True)
+    except FileExistsError as e:
+        logging.info("File %s exists, not updating", destination_file)
+        return False
 
     logging.debug("written %s", destination_file)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]