Index: /trunk/web/cache_acls.py
===================================================================
--- /trunk/web/cache_acls.py	(revision 256)
+++ /trunk/web/cache_acls.py	(revision 257)
@@ -34,16 +34,27 @@
     connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen')
     
-    machines = Machine.select()
-    for m in machines:
-        people = set()
-        people.update(expandLocker(m.owner))
-        people.update(expandName(m.administrator))
-        print '%s: %s' % (m.name, ' '.join(people))
-        transaction = ctx.current.create_transaction()
-        for a in m.acl:
-            ctx.current.delete(a)
-        for p in people:
-            ma = MachineAccess(machine_id=m.machine_id, user=p)
-            ctx.current.save(ma)
-        ctx.current.flush()
+    transaction = ctx.current.create_transaction()
+
+    print repr(ctx), repr(ctx.current), repr(transaction)
+    # Remove existing machine access entries
+    machine_access_table.delete()
+    ctx.current.flush()
+
+    try:
+        machines = Machine.select()
+        for m in machines:
+            people = set()
+            people.update(expandLocker(m.owner))
+            people.update(expandName(m.administrator))
+            print '%s: %s' % (m.name, ' '.join(people))
+            for p in people:
+                ma = MachineAccess(machine_id=m.machine_id, user=p)
+                ctx.current.save(ma)
+            ctx.current.flush()
+            
+        # Atomically execute our changes
         transaction.commit()
+    except:
+        # Failed! Rollback all the changes.
+        transaction.rollback()
+        raise
