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
engine_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_news_explorer.google_news_engine import GoogleNewsEngine
22 from rapp_news_explorer.event_registry_engine import EventRegistryEngine
23 
24 from rapp_utilities import RappUtilities
25 from rapp_exceptions import RappError
26 
27 
28 ## @class EngineFactory
29 # @brief Creates and returns the class of the news engine requested.
30 # Implements a factory pattern.
31 class EngineFactory(object):
32 
33  ## @brief Select proper news engine according to request
34  #
35  # @param engine [string] The name of the news engine
36  #
37  # @return res
38  # [rapp_news_explorer.rapp_news_explorer.NewsEngine]
39  # The news engine
40  #
41  # @exceptions RappError Wrong news engine provided by user
42  def select_news_engine(self, engine):
43 
44  # Set google as a default news engine
45  if engine == '':
46  RappUtilities.rapp_print('No search engine provided. Falling ' +
47  'back to default (Google News)',
48  'DEBUG')
49  engine = 'event_registry'
50 
51  if engine == 'google':
52  RappUtilities.rapp_print('Creating Google News engine', 'DEBUG')
53  return GoogleNewsEngine()
54  elif engine == 'event_registry':
55  RappUtilities.rapp_print('Creating Envents Registry engine',
56  'DEBUG')
57  return EventRegistryEngine()
58  else:
59  RappUtilities.rapp_print('Wrong news engine provided', 'ERROR')
60  raise RappError('Wrong news engine provided')
def select_news_engine
Select proper news engine according to request.
Creates and returns the class of the news engine requested.