Changeset 257


Ignore:
Timestamp:
Jan 24, 2008, 5:20:30 PM (17 years ago)
Author:
ecprice
Message:

Do entire ACL update in a transaction, not for each machine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/cache_acls.py

    r256 r257  
    3434    connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen')
    3535   
    36     machines = Machine.select()
    37     for m in machines:
    38         people = set()
    39         people.update(expandLocker(m.owner))
    40         people.update(expandName(m.administrator))
    41         print '%s: %s' % (m.name, ' '.join(people))
    42         transaction = ctx.current.create_transaction()
    43         for a in m.acl:
    44             ctx.current.delete(a)
    45         for p in people:
    46             ma = MachineAccess(machine_id=m.machine_id, user=p)
    47             ctx.current.save(ma)
    48         ctx.current.flush()
     36    transaction = ctx.current.create_transaction()
     37
     38    print repr(ctx), repr(ctx.current), repr(transaction)
     39    # Remove existing machine access entries
     40    machine_access_table.delete()
     41    ctx.current.flush()
     42
     43    try:
     44        machines = Machine.select()
     45        for m in machines:
     46            people = set()
     47            people.update(expandLocker(m.owner))
     48            people.update(expandName(m.administrator))
     49            print '%s: %s' % (m.name, ' '.join(people))
     50            for p in people:
     51                ma = MachineAccess(machine_id=m.machine_id, user=p)
     52                ctx.current.save(ma)
     53            ctx.current.flush()
     54           
     55        # Atomically execute our changes
    4956        transaction.commit()
     57    except:
     58        # Failed! Rollback all the changes.
     59        transaction.rollback()
     60        raise
Note: See TracChangeset for help on using the changeset viewer.