RAPP Platform  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Classes Namespaces Files Functions Variables Macros
geolocator_factory.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- encode: utf-8 -*-
3 
4 #Copyright 2015 RAPP
5 
6 #Licensed under the Apache License, Version 2.0 (the "License");
7 #you may not use this file except in compliance with the License.
8 #You may obtain a copy of the License at
9 
10  #http://www.apache.org/licenses/LICENSE-2.0
11 
12 #Unless required by applicable law or agreed to in writing, software
13 #distributed under the License is distributed on an "AS IS" BASIS,
14 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #See the License for the specific language governing permissions and
16 #limitations under the License.
17 
18 # Authors: Aris Thallas
19 # contact: aris.thallas@{iti.gr, gmail.com}
20 
21 from rapp_geolocator.ip_api_locator import IpAPILocator
22 
23 from rapp_utilities import RappUtilities
24 from rapp_exceptions import RappError
25 
26 
27 ## @class IPLocatorFactory
28 # @brief Creates and returns the class of the geolocator requested.
29 # Implements a factory pattern.
30 class GeolocatorFactory(object):
31 
32  ## @brief Select proper geolocator according to request
33  #
34  # @param geolocator [string] The name of the geolocator
35  #
36  # @return res
37  # [rapp_geolocator.rapp_geolocator.GeolocatorBase]
38  # The geolocator
39  #
40  # @exceptions RappError Wrong geolocator provided by user
41  def select_geolocator(self, geolocator=''):
42 
43  # Set google as a default geolocator
44  if geolocator == '':
45  geolocator = 'ip-api'
46 
47  if geolocator == 'ip-api':
48  RappUtilities.rapp_print('Creating ip-api locator', 'DEBUG')
49  return IpAPILocator()
50  else:
51  RappUtilities.rapp_print('Wrong ip locator provided', 'ERROR')
52  raise RappError('Wrong ip locator provided')
def select_geolocator
Select proper geolocator according to request.