Created
March 8, 2016 21:18
-
-
Save kcuzner/061919b5b4b5dddfe91e to your computer and use it in GitHub Desktop.
Getting a property based on the hostname
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# Demonstration for host to use the hostname to determine which property of the | |
# Field is "mine" | |
import socket | |
from geometry_msgs.msg import Pose2D | |
from bh_vision.msg import Field | |
hosts = {'BECKHAM': '1', | |
'HOWARD': '2'} | |
def get_pose(field): | |
hostname = socket.gethostname() | |
hasProp = 'hasHome' + hosts[hostname] | |
if getattr(field, hasProp, False): | |
poseProp = 'home' + hosts[hostname] | |
return getattr(field, poseProp) | |
return None | |
def test(): | |
field = Field() | |
field.hasHome1 = True | |
field.home1 = Pose2D(1, 2, 3) | |
field.hasHome2 = False | |
print get_pose(field) # this returns either the pose for the current machine or None | |
if __name__ == '__main__': | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment