Пример #1
0
 def responder():
     result = rospy.wait_for_message(
         topic['feedback']['topic'],
         dynamic_import(topic['feedback']['type']))
     result = get_attribute(result, topic['feedback']['field'])
     return topic['feedback'].get(
         'success', result) == result or re.match(
             str(topic['feedback']['success']), str(result)) is not None
Пример #2
0
def load_loader(name, locations):
    """
    Load a specific loader searching locations (a dictionary) in order.

    locations - list of paths to search, using "." as path separator

    Returns None if the lookup fails.
    """
    for location in locations:
        try:
            full = location + "." + name
            return dynamic_import(full)
        except ImportError, e:
            pass
Пример #3
0
 def __init__(self, robot_move_strategy, topics):
     # type: (ExploreMoveStrategy, List[dict]) -> None
     self.robot_move_strategy = robot_move_strategy
     self.topic_identifiers = lmap(lambda topic: topic['identifier'],
                                   topics)
     self.topics_values = lmap(lambda topic: topic['explore'], topics)
     self.continue_enabled = all(
         map(lambda topic: topic['explore'].get('continue', False), topics))
     self.publishers_types = lmap(
         lambda topic: dynamic_import(topic['type']), topics)
     self.publishers = lmap(
         lambda topic: rospy.Publisher(topic[1]['identifier'],
                                       self.publishers_types[topic[0]],
                                       queue_size=1), enumerate(topics))
     self.responders = lmap(lambda topic: self.get_responder(topic), topics)
Пример #4
0
def find(locations):
    """
    Returns a list of (location, path, loaders) for each location in
    locations. locations is expected to be in PYTHONPATH and be in
    module-name form (eg. "a.b.c").
    """
    loaders = []
    for location in locations:
        files = []
        path = "NOT FOUND: make sure location contains __init__.py"
        try:
            mod = dynamic_import(location)
            path = mod.__path__[0]
        except (ImportError, AttributeError, IndexError), e:
            pass
        else:
            # Only select "simple looking" python files
            regex = re.compile("^([A-Za-z]\\w+)\\.py$")
            files = [m.group(1) for m in 
                     (regex.match(f) for f in os.listdir(path))
                     if m]

        loaders.append((location, path, files))