Add close muxes script

We have a problem that muxes can be left open
on reboot, so that when we scan for devices they
are left open. Add this script as a mitigation until
we can come up with a better idea.

Change-Id: I74143bb0624188394ed67110813671ca68698806
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/scripts/CloseMuxes.py b/scripts/CloseMuxes.py
new file mode 100644
index 0000000..52d8403
--- /dev/null
+++ b/scripts/CloseMuxes.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+"""
+This script sets muxes back to default values so that
+during device parsing we are not left with an invisible
+mux before the mux has been added to device tree.
+
+If we find a better way to take care of this, we should
+remove this file.
+"""
+
+import os
+import json
+import subprocess
+
+
+CONFIGURATION_FILE = '/var/configuration/system.json'
+MUX_TYPES = ['PCA9543Mux', 'PCA9545Mux']
+
+if not os.path.isfile(CONFIGURATION_FILE):
+    print('No Configuration')
+    exit(0)
+
+configuration = json.load(open(CONFIGURATION_FILE))
+
+for _, entity in configuration.iteritems():
+    for exposed in entity.get('exposes', []):
+        if exposed.get('type', None) in MUX_TYPES:
+            bus = exposed.get('bus', False)
+            address = exposed.get('address', False)
+            if bus and address:
+                subprocess.call('i2cset -y -f {} {} 0'.format(bus, address),
+                                shell=True)