confManager.py
Go to the documentation of this file.
00001 # MIT License
00002 #
00003 # Copyright (c) <2015> <Ikergune, Etxetar>
00004 #
00005 # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
00006 # (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
00007 # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
00008 # subject to the following conditions:
00009 #
00010 # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00011 #
00012 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00013 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
00014 # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00015 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00016 
00017 import os
00018 import json
00019 import copy
00020 import traceback
00021 
00022 from include.logger import Log
00023 from include.ros.rosConfigurator import RosConfigurator
00024 
00025 
00026 def getRobots(refresh=False, withJson=True):
00027     ## \brief Get robots managed by firos
00028     # \param Refresh the robot list
00029     # \param Merge the robots with the configurtation JSON
00030     try:
00031         robots = copy.deepcopy(RosConfigurator.systemTopics(refresh))
00032         if withJson:
00033             robots_json = getRobotsByJson()
00034             for robot_name in robots_json:
00035                 robot_name = str(robot_name)
00036                 if robot_name not in robots:
00037                     robots[robot_name] = {
00038                         "topics": {}
00039                     }
00040                 for topic_name in robots_json[robot_name]["topics"]:
00041                     topic = robots_json[robot_name]["topics"][topic_name]
00042 
00043                     robots[robot_name]["topics"][str(topic_name)] = {
00044                         "msg": str(topic["msg"]) if type(topic["msg"]) is str else topic["msg"],
00045                         "type": str(topic["type"])
00046                     }
00047         return robots
00048 
00049     except Exception as e:
00050         traceback.print_exc()
00051         Log("ERROR", e)
00052         return {}
00053 
00054 
00055 def getRobotsByJson():
00056     ## \brief Get robots in the JSON file
00057     try:
00058         current_path = os.path.dirname(os.path.abspath(__file__))
00059         json_path = current_path.replace("scripts/include", "config/robots.json")
00060         return json.load(open(json_path))
00061     except:
00062         return {}


firos
Author(s): IƱigo Gonzalez, igonzalez@ikergune.com
autogenerated on Thu Jun 6 2019 17:51:04