]> git.ipfire.org Git - location/libloc.git/commitdiff
importer: When storing country codes, make the code more straight-forward
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 4 Mar 2024 09:52:38 +0000 (09:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 4 Mar 2024 09:52:38 +0000 (09:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/location-importer.in

index 9b83f3fcf244f6e6e9096c6981138c1abe65ff4c..7a811e998bb73ea177975ca244cd949f2c0d1f16 100644 (file)
@@ -1099,28 +1099,23 @@ class CLI(object):
                                inetnum[key] = [ipaddress.ip_network(val, strict=False)]
 
                        elif key == "country":
-                               val = val.upper()
-
-                               # Catch RIR data objects with more than one country code...
-                               if not key in inetnum:
-                                       inetnum[key] = []
-                               else:
-                                       if val in inetnum.get("country"):
-                                               # ... but keep this list distinct...
-                                               continue
+                               cc = val.upper()
 
                                # Ignore certain country codes
-                               if val in IGNORED_COUNTRIES:
-                                       log.debug("Ignoring country code '%s'" % val)
+                               if cc in IGNORED_COUNTRIES:
+                                       log.debug("Ignoring country code '%s'" % cc)
                                        continue
 
                                # Translate country codes
                                try:
-                                       val = TRANSLATED_COUNTRIES[val]
+                                       cc = TRANSLATED_COUNTRIES[cc]
                                except KeyError:
                                        pass
 
-                               inetnum[key].append(val)
+                               try:
+                                       inetnum[key].append(cc)
+                               except KeyError:
+                                       inetnum[key] = [cc]
 
                        # Parse the geofeed attribute
                        elif key == "geofeed":