コード例 #1
0
ファイル: allocate.py プロジェクト: Python3pkg/DeviceHub
def materialize_owners(devices_id):
    """Re-computes 'owners' for the given devices and components."""
    # First let's erase all owners
    DeviceDomain.update_many_raw({'_id': {
        '$in': devices_id
    }}, {'$set': {
        'owners': []
    }})
    # Then let's execute again the materialize hooks for Allocate/Deallocate
    query = {
        '$or': [{
            '@type': 'devices:Allocate'
        }, {
            '@type': 'devices:Deallocate'
        }],
        'devices': {
            '$in': devices_id
        }
    }
    order_by = {'_created': pymongo.ASCENDING}
    for event in DeviceEventDomain.get({
            '$query': query,
            '$orderby': order_by
    }):
        if event['@type'] == 'devices:Allocate':
            materialize_actual_owners_add([event])
        else:
            modified = materialize_actual_owners_remove([event])
            if modified == 0:  # This Remove does nothing and should be erased
                DeviceEventDomain.delete({'_id': event['_id']})
コード例 #2
0
 def execute(self, database):
     DeviceDomain.update_many_raw({}, {'$set': {'events': []}})
     for event in DeviceEventDomain.get({
             '$query': {},
             '$orderby': {
                 '_created': pymongo.ASCENDING
             }
     }):
         MaterializeEvents.materialize_events(
             Naming.resource(event['@type']), [event])
コード例 #3
0
 def re_materialize_events():
     DeviceDomain.update_many_raw({}, {'$set': {'events': []}})
     for event in DeviceEventDomain.get({
             '$query': {},
             '$orderby': {
                 '_created': pymongo.ASCENDING
             }
     }):
         MaterializeEvents.materialize_events(
             Naming.resource(event['@type']), [event])
     print('Events re-materialized.')
コード例 #4
0
ファイル: allocate.py プロジェクト: eReuse/DeviceHub
def materialize_owners(devices_id):
    """Re-computes 'owners' for the given devices and components."""
    # First let's erase all owners
    DeviceDomain.update_many_raw({'_id': {'$in': devices_id}}, {'$set': {'owners': []}})
    # Then let's execute again the materialize hooks for Allocate/Deallocate
    query = {'$or': [{'@type': 'devices:Allocate'}, {'@type': 'devices:Deallocate'}], 'devices': {'$in': devices_id}}
    order_by = {'_created': pymongo.ASCENDING}
    for event in DeviceEventDomain.get({'$query': query, '$orderby': order_by}):
        if event['@type'] == 'devices:Allocate':
            materialize_actual_owners_add([event])
        else:
            modified = materialize_actual_owners_remove([event])
            if modified == 0:  # This Remove does nothing and should be erased
                DeviceEventDomain.delete({'_id': event['_id']})
コード例 #5
0
 def re_materialize_events():
     DeviceDomain.update_many_raw({}, {'$set': {'events': []}})
     for event in DeviceEventDomain.get({'$query': {}, '$orderby': {'_created': pymongo.ASCENDING}}):
         MaterializeEvents.materialize_events(Naming.resource(event['@type']), [event])
     print('Events re-materialized.')