]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/fireinfo.py
Migrate to libloc
[ipfire.org.git] / src / backend / fireinfo.py
index e5099599d0b67a417de01d7f421ed61b54284aea..d02d774f8201a75c7a2c24775cab91e8139ea6ee 100644 (file)
@@ -5,6 +5,7 @@ import iso3166
 import logging
 import re
 
+from . import countries
 from . import database
 from . import hwdata
 from . import util
@@ -325,7 +326,7 @@ class Device(Object):
                        "11" : N_("Signal processing controller"),
                        "ff" : N_("Unassigned class"),
                },
-               
+
                "usb" : {
                        "00" : N_("Unclassified"),
                        "01" : N_("Multimedia"),
@@ -481,7 +482,7 @@ class Profile(Object):
        def time_updated(self):
                return self.data.time_updated
 
-       def updated(self, profile_parser=None, location=None, when=None):
+       def updated(self, profile_parser=None, country_code=None, when=None):
                valid = self.settings.get_int("fireinfo_profile_days_valid", 14)
 
                self.db.execute("UPDATE fireinfo_profiles \
@@ -497,8 +498,8 @@ class Profile(Object):
                                profile_parser.processor_bogomips,
                        )
 
-               if location:
-                       self.set_location(location)
+               if country_code:
+                       self.set_country_code(country_code)
 
                self.log_profile_update()
 
@@ -549,7 +550,8 @@ class Profile(Object):
 
        # Location
 
-       def get_location(self):
+       @property
+       def location(self):
                if not hasattr(self, "_location"):
                        res = self.db.get("SELECT location FROM fireinfo_profiles_locations \
                                WHERE profile_id = %s", self.id)
@@ -561,22 +563,20 @@ class Profile(Object):
 
                return self._location
 
-       def set_location(self, location):
-               if self.location == location:
+       def set_country_code(self, country_code):
+               if self.location == country_code:
                        return
 
                self.db.execute("DELETE FROM fireinfo_profiles_locations \
                        WHERE profile_id = %s", self.id)
                self.db.execute("INSERT INTO fireinfo_profiles_locations(profile_id, location) \
-                       VALUES(%s, %s)", self.id, location)
+                       VALUES(%s, %s)", self.id, country_code)
 
-               self._location = location
-
-       location = property(get_location, set_location)
+               self._location = country_code
 
        @property
        def location_string(self):
-               return self.geoip.get_country_name(self.location)
+               return countries.get_name(self.location)
 
        # Devices
 
@@ -904,7 +904,7 @@ class Profile(Object):
                                self._kernel_id = None
 
                return self._kernel_id
-               
+
        def set_kernel_id(self, kernel_id):
                if self.kernel_id == kernel_id:
                        return
@@ -1727,7 +1727,7 @@ class Fireinfo(Object):
                else:
                        self.db.execute("COMMIT")
 
-       def _handle_profile(self, public_id, profile_blob, location=None, when=None):
+       def _handle_profile(self, public_id, profile_blob, country_code=None, when=None):
                private_id = profile_blob.get("private_id", None)
                assert private_id
 
@@ -1751,7 +1751,7 @@ class Fireinfo(Object):
                if profile:
                        # Check if the profile has changed. If so, update the data.
                        if profile_parser.equals(profile):
-                               profile.updated(profile_parser, location=location, when=when)
+                               profile.updated(profile_parser, country_code=country_code, when=when)
                                return
 
                        # If it does not match, we assume that it is expired and
@@ -1762,8 +1762,8 @@ class Fireinfo(Object):
                profile = self.fireinfo.create_profile(public_id, private_id, when=when)
                profile.parse(profile_parser)
 
-               if location:
-                       profile.set_location(location)
+               if country_code:
+                       profile.set_country_code(country_code)
 
                return profile