-# load options
-config = loadConfigFile(os.getenv('HOME') + '/.dsl.conf')
-if len(config['internalConnector']) != 1:
- raise Exception("You must specify exactly one internal connector")
-if len(config['externalConnectors']) < 1:
- raise Exception("You must specify at least one external connector")
-# use options
-internalConnector = config['internalConnector'][0]
-externalConnectors = config['externalConnectors']
-connectors = getXrandrInformation()
-usedExternalConnector = findAvailableConnector(externalConnectors, connectors) # *the* external connector which is actually used
+# the main function
+def main():
+ # load connectors and options
+ connectors = getXrandrInformation()
+ 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 connectors:
+ raise Exception("Connector %s does not exist, there is an error in your config file." % internalConnector)
+ else:
+ # auto-config
+ internalConnector = findAvailableConnector(commonInternalConnectorNames)
+ 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 connectors:
+ raise Exception("Connector %s does not exist, there is an error in your config file." % internalConnector)
+ else:
+ externalConnectors = connectors.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.")