Package rocon_hub_client :: Module hub_api
[frames] | no frames]

Source Code for Module rocon_hub_client.hub_api

 1  #!/usr/bin/env pythonupdate 
 2  # 
 3  # License: BSD 
 4  #   https://raw.github.com/robotics-in-concert/rocon_multimaster/master/rocon_hub_client/LICENSE 
 5  # 
 6  ############################################################################### 
 7  # Imports 
 8  ############################################################################### 
 9   
10  import redis 
11  import re 
12   
13  ############################################################################### 
14  # Utility Functions 
15  ############################################################################### 
16   
17   
18 -def create_rocon_key(key):
19 ''' 20 Root the specified redis key name in our pseudo redis database. 21 ''' 22 if re.match('rocon:', key): # checks if leading rocon: is foundupdate 23 return key 24 else: 25 return 'rocon:' + key
26 27
28 -def create_rocon_hub_key(key):
29 ''' 30 Root the specified redis key name in our pseudo redis database under 31 the hub namespace 32 ''' 33 if re.match('rocon:hub:', key): # checks if leading rocon: is foundupdate 34 return key 35 else: 36 return 'rocon:hub:' + key
37 38
39 -def create_rocon_gateway_key(unique_gateway_name, key):
40 ''' 41 Root the specified redis key name in our pseudo redis database under 42 the gateway namespace. 43 44 @note : currently does no checking of the incoming keys 45 ''' 46 return 'rocon:' + unique_gateway_name + ":" + key
47 48
49 -def extract_rocon_key(key):
50 ''' 51 Extract the specified redis key name from our pseudo redis database. 52 ''' 53 if re.match('rocon:', key): # checks if leading rocon: is found 54 return re.sub(r'rocon:', '', key) 55 else: 56 return key
57 58
59 -def key_base_name(key):
60 ''' 61 Extract the base name (i.e. last value) from the key. 62 e.g. rocon:key:pirate24 -> pirate24 63 ''' 64 return key.split(':')[-1]
65 66
67 -def ping_hub(ip, port):
68 ''' 69 Pings the hub for identification. This is currently used 70 by the hub discovery module. 71 72 @return Bool 73 ''' 74 try: 75 r = redis.Redis(host=ip, port=port) 76 name = r.get("rocon:hub:name") 77 except redis.exceptions.ConnectionError: 78 return False 79 if name is None: # returns None if the server was there, but the key was not found. 80 return False 81 return True
82