Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import os
00018 import json
00019 import urllib2
00020 import netifaces
00021
00022
00023 def setConfiguration():
00024 try:
00025 current_path = os.path.dirname(os.path.abspath(__file__))
00026 json_path = current_path.replace("scripts/include", "config/config.json")
00027 data = json.load(open(json_path))
00028 return data[data["environment"]]
00029 except:
00030 return {}
00031
00032 configured = False
00033
00034 if not configured:
00035 configured = True
00036 configData = setConfiguration()
00037 INTERFACE = configData["interface"] if "interface" in configData else "public"
00038 LOGLEVEL = configData["log_level"] if "log_level" in configData else "INFO"
00039
00040
00041 SERVER_PORT = configData["server"]["port"]
00042 if("index" in configData["contextbroker"]):
00043 INDEX_CONTEXTBROKER = {
00044 "ADDRESS": configData["contextbroker"]["index"]["address"],
00045 "PORT": configData["contextbroker"]["index"]["port"],
00046 }
00047
00048 DATA_CONTEXTBROKER = {
00049 "ADDRESS": configData["contextbroker"]["data"]["address"],
00050 "PORT": configData["contextbroker"]["data"]["port"],
00051 }
00052 else:
00053 INDEX_CONTEXTBROKER = {
00054 "ADDRESS": configData["contextbroker"]["address"],
00055 "PORT": configData["contextbroker"]["port"],
00056 }
00057
00058 DATA_CONTEXTBROKER = {
00059 "ADDRESS": configData["contextbroker"]["address"],
00060 "PORT": configData["contextbroker"]["port"],
00061 }
00062
00063
00064 THROTTLING = configData["contextbroker"]["subscription"]["throttling"]
00065 SUBSCRIPTION_LENGTH = configData["contextbroker"]["subscription"]["subscription_length"]
00066 SUBSCRIPTION_REFRESH_DELAY = configData["contextbroker"]["subscription"]["subscription_refresh_delay"]
00067
00068 SEPARATOR_CHAR = "%27"
00069
00070
00071 NODE_NAME = "firos"
00072 DEFAULT_CONTEXT_TYPE = "ROBOT"
00073 DEFAULT_QUEUE_SIZE = 10
00074
00075 if INTERFACE == "public":
00076 IP = urllib2.urlopen('http://ip.42.pl/raw').read()
00077 else:
00078 netifaces.ifaddresses(INTERFACE)
00079 IP = netifaces.ifaddresses(INTERFACE)[2][0]['addr']
00080
00081 if "map_server_port" in configData:
00082 MAP_SERVER_PORT = configData["map_server_port"]
00083 else:
00084 MAP_SERVER_PORT = None
00085
00086 if "rosbridge_port" in configData:
00087 ROSBRIDGE_PORT = configData["rosbridge_port"]
00088 else:
00089 ROSBRIDGE_PORT = 9090