Only update the differences (and actually work).
authorEric Price <ecprice@mit.edu>
Fri, 25 Jan 2008 02:32:42 +0000 (21:32 -0500)
committerEric Price <ecprice@mit.edu>
Fri, 25 Jan 2008 02:32:42 +0000 (21:32 -0500)
svn path=/trunk/web/; revision=260

cache_acls.py

index e0094e8..ca0b7c9 100644 (file)
@@ -35,11 +35,6 @@ if __name__ == '__main__':
     
     transaction = ctx.current.create_transaction()
 
     
     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:
     try:
         machines = Machine.select()
         for m in machines:
@@ -47,7 +42,11 @@ if __name__ == '__main__':
             people.update(expandLocker(m.owner))
             people.update(expandName(m.administrator))
             print '%s: %s' % (m.name, ' '.join(people))
             people.update(expandLocker(m.owner))
             people.update(expandName(m.administrator))
             print '%s: %s' % (m.name, ' '.join(people))
-            for p in people:
+            old_people = set(a.user for a in m.acl)
+            for removed in old_people - people:
+                ma = [x for x in m.acl if x.user == removed][0]
+                ctx.current.delete(ma)
+            for p in people - old_people:
                 ma = MachineAccess(machine_id=m.machine_id, user=p)
                 ctx.current.save(ma)
             ctx.current.flush()
                 ma = MachineAccess(machine_id=m.machine_id, user=p)
                 ctx.current.save(ma)
             ctx.current.flush()