Beispiel #1
0
    def setupStation(self, config_dict):
        """Set up the weather station hardware."""

        stationType = config_dict['Station']['station_type']

        driver = get_driver_info()[stationType].get('module_name')

        logging.info("engine: Loading station type %s (%s)" % (stationType, driver))

        __import__(driver)
    
        try:
            driver_module = sys.modules[driver]
            loader_function = getattr(driver_module, 'loader')
            self.console = loader_function(config_dict)
        except Exception, ex:
            raise InitializationError(ex)
Beispiel #2
0
def prompt_for_driver():
    """Get the information about each driver, return as a dictionary."""

    info = get_driver_info()
    keys = sorted(info)
    dflt_idx = None
    print "Installed drivers include:"
    for i, d in enumerate(keys):
        print " %2d) %-15s %-25s %s" % (i, info[d].get('driver_name', '?'),
                                        "(%s)" % d, info[d].get('status', ''))
    msg = "choose a driver: "
    ans = None
    while ans is None:
        ans = raw_input(msg).strip()
        if not ans:
            ans = dflt_idx
        try:
            idx = int(ans)
            if not 0 <= idx < len(keys):
                ans = None
        except (ValueError, TypeError):
            ans = None
    return info[keys[idx]]