-# Return a (internalConnector, externalConnectors) pair: The name of the internal connector, and a list of external connectors.
-# Use the config file at ~/.dsl.conf and fall back to auto-detection
-def classifyConnectors(allConnectors):
- config = loadConfigFile(os.getenv('HOME') + '/.dsl.conf')
- # find internal connector
- if 'internalConnector' in config:
- if len(config['internalConnector']) != 1:
- raise Exception("You must specify exactly one internal connector.")
- internalConnector = config['internalConnector'][0]
- if not internalConnector in allConnectors:
- raise Exception("Connector %s does not exist, there is an error in your config file." % internalConnector)
- else:
- # auto-config
- internalConnector = findAvailableConnector(commonInternalConnectorNames, allConnectors)
- if internalConnector is None:
- raise Exception("Could not automatically find internal connector, please use ~/.dsl.conf to specify it manually.")
- # all the rest is external then, obviously - unless the user wants to do that manually
- if 'externalConnectors' in config:
- externalConnectors = config['externalConnectors']
- for connector in externalConnectors:
- if not connector in allConnectors:
- raise Exception("Connector %s does not exist, there is an error in your config file." % connector)
- if connector == internalConnector:
- raise Exception("%s is both internal and external, that doesn't make sense." % connector)
- else:
- externalConnectors = list(allConnectors.keys())
- externalConnectors.remove(internalConnector)
- if not externalConnectors:
- raise Exception("No external connector found - either your config is wrong, or your machine has only one connector.")
- # done!
- return (internalConnector, externalConnectors)