Logging even more details
[theonering] / src / location.py
index a77d0c7..32b5823 100644 (file)
@@ -3,9 +3,10 @@ import logging
 import telepathy
 
 import util.misc as misc_utils
 import telepathy
 
 import util.misc as misc_utils
+import handle
 
 
 
 
-_moduleLogger = logging.getLogger('location')
+_moduleLogger = logging.getLogger(__name__)
 
 
 #class LocationMixin(tp.ConnectionInterfaceLocation):
 
 
 #class LocationMixin(tp.ConnectionInterfaceLocation):
@@ -27,14 +28,22 @@ class LocationMixin(object):
                """
                @returns {Contact: {Location Type: Location}}
                """
                """
                @returns {Contact: {Location Type: Location}}
                """
-               raise telepathy.errors.NotImplemented("Yet")
+               contactLocation = (
+                       (contact, self._get_location(contact))
+                       for contact in contacts
+               )
+               return dict(
+                       (contact, location)
+                       for (contact, location) in contactLocation
+                       if location
+               )
 
        @misc_utils.log_exception(_moduleLogger)
        def RequestLocation(self, contact):
                """
                @returns {Location Type: Location}
                """
 
        @misc_utils.log_exception(_moduleLogger)
        def RequestLocation(self, contact):
                """
                @returns {Location Type: Location}
                """
-               raise telepathy.errors.NotImplemented("Yet")
+               return self._get_location(contact)
 
        @misc_utils.log_exception(_moduleLogger)
        def SetLocation(self, location):
 
        @misc_utils.log_exception(_moduleLogger)
        def SetLocation(self, location):
@@ -42,3 +51,20 @@ class LocationMixin(object):
                Since presence is based off of phone numbers, not allowing the client to change it
                """
                raise telepathy.errors.PermissionDenied()
                Since presence is based off of phone numbers, not allowing the client to change it
                """
                raise telepathy.errors.PermissionDenied()
+
+       def _get_location(self, contact):
+               h = self.get_handle_by_id(telepathy.HANDLE_TYPE_CONTACT, contact)
+               if isinstance(h, handle.ConnectionHandle):
+                       number = self.session.backend.get_callback_number()
+               else:
+                       number = h.phoneNumber
+
+               rawData = self.session.location.request_location(number)
+               if rawData is None:
+                       return {}
+
+               data = {
+                       "country": rawData["country"],
+                       "city": rawData["city"],
+                       "region": rawData["region"],
+               }