Пример #1
0
    def purge_group(group_name_or_id, proceed=True):

        # fetch group object
        group_obj = Group.get_group_name_id(group_name_or_id, get_obj=True)

        if not group_obj:
            raise Exception('Expects either group "name" or "_id". Got invalid argument or that group does not exists.')

        group_id = group_obj._id

        # get all the objects belonging to this group
        all_nodes_under_gr = node_collection.find({'group_set': {'$in': [group_id]}})

        # separate nodes belongs to one and more groups
        only_group_nodes_cnt = all_nodes_under_gr.clone().where("this.group_set.length == 1").count()
        multi_group_nodes_cnt = all_nodes_under_gr.clone().where("this.group_set.length > 1").count()

        print "Group:", group_obj.name, "(", group_obj.altnames, ") contains:\n",\
            "\t- unique (belongs to this group only) : ", only_group_nodes_cnt, \
            "\n\t- shared (belongs to other groups too): ", multi_group_nodes_cnt, \
            "\n\t============================================", \
            "\n\t- total: ", all_nodes_under_gr.count()

        if not proceed:
            print "\nDo you want to purge group and all unique nodes(belongs to this group only) under it?"
            print 'Enter Y/y to proceed else N/n to reject group deletion:'
            to_proceed = raw_input()
            proceed = True if (to_proceed in ['y', 'Y']) else False

        if proceed:
            print "\nProceeding further for purging of group and unique resources/nodes under it..."
            from gnowsys_ndf.ndf.views.methods import delete_node

            grp_res = node_collection.find({ '$and': [ {'group_set':{'$size':1}}, {'group_set': {'$all': [ObjectId(group_id)]}} ] })
            print "\n Total (unique) resources to be purge: ", grp_res.count()

            for each in grp_res:
                del_status, del_status_msg = delete_node(node_id=each._id, deletion_type=1 )
                # print del_status, del_status_msg
                if not del_status:
                    print "*"*80
                    print "\n Error node: _id: ", each._id, " , name: ", each.name, " type: ", each.member_of_names_list
                    print "*"*80

            print "\n Purging group: "
            del_status, del_status_msg = delete_node(node_id=group_id, deletion_type=1)
            print del_status, del_status_msg

            # poping group_id from each of shared nodes under group
            all_nodes_under_gr.rewind()
            print "\n Total (shared) resources to be free from this group: ", all_nodes_under_gr.count()
            for each_shared_node in all_nodes_under_gr:
                if group_id in each_shared_node.group_set:
                    each_shared_node.group_set.remove(group_id)
                    each_shared_node.save()

            return True

        print "\nAborting group deletion."
        return True
Пример #2
0
def delete_user_artifacts(user_ids_list):
    user_ids_list = map(int, user_ids_list)
    all_nodes = node_collection.find({'_type': 'GSystem', 'created_by': {'$in': user_ids_list}, 'group_set': {'$in': UNIT_IDS}}),
    print "\nArtifacts: ", all_nodes.count()
    for each_node in all_nodes:
        print ".",
        log_file.write("deleting the artifact node {0} created by {1}".format(each_node._id,each_node.created_by))
        delete_node(node=each_node,collection_name=node_collection,deletion_type=1)
Пример #3
0
def delete_res(del_cur):

    for each in del_cur:
        # print "\n=== deleted: ===\n", each.name , "---", each.member_of_names_list
        del_status, del_status_msg = delete_node(node_id=each._id,
                                                 deletion_type=1)
        # print "\n---------\n",del_status, "--", del_status_msg
        if not del_status:
            print "*" * 80
            print "\n Error node: _id: ", each._id, " , name: ", each.name, " type: ", each.member_of_names_list
            print "*" * 80
Пример #4
0
 def validate_deletion(node_id,force_deletion=False):
     try:
         node_obj = Node.get_node_by_id(node_id)
         if node_obj:
             if force_deletion:
                 print "\n Force Deletion on: ", node_obj._id
                 node_obj.delete()
             else:
                 del_status, del_status_msg = delete_node(node_id=node_obj._id, deletion_type=1)
                 validate_deletion(node_id,force_deletion=True)
     except Exception as validate_deletion_err:
         print "\n Error occurred.", str(validate_deletion_err)
Пример #5
0
def delete_res(del_cur):

    for each in del_cur:
        # print "\n=== deleted: ===\n", each.name , "---", each.member_of_names_list
        del_status, del_status_msg = delete_node(
            node_id=each._id,
            deletion_type=1
        )
        # print "\n---------\n",del_status, "--", del_status_msg
        if not del_status:
            print "*"*80
            print "\n Error node: _id: ", each._id, " , name: ", each.name, " type: ", each.member_of_names_list
            print "*"*80
Пример #6
0
 def validate_deletion(node_id, force_deletion=False):
     try:
         node_obj = Node.get_node_by_id(node_id)
         if node_obj:
             if force_deletion:
                 print "\n Force Deletion on: ", node_obj._id
                 node_obj.delete()
             else:
                 del_status, del_status_msg = delete_node(
                     node_id=node_obj._id, deletion_type=1)
                 validate_deletion(node_id, force_deletion=True)
     except Exception as validate_deletion_err:
         print "\n Error occurred.", str(validate_deletion_err)
Пример #7
0
 def _group_deletion(group_id):
     try:
         group_obj = Group.get_group_name_id(group_id, get_obj=True)
         if group_obj:
             Group.purge_group(group_id, proceed=proceed_flag)
             validate_deletion(group_id)
         else:
             node_obj = Node.get_node_by_id(group_id)
             # If the ObjectId entered is not of a Group
             if node_obj:
                 if node_obj.collection_set:
                     for each_obj_id in node_obj.collection_set:
                         _group_deletion(each_obj_id)
                 del_status, del_status_msg = delete_node(node_id=node_obj._id, deletion_type=1)
                 validate_deletion(node_obj._id)
     except Exception as group_del_err:
         print "\n Error occurred.", str(group_del_err)
Пример #8
0
 def _group_deletion(group_id):
     try:
         group_obj = Group.get_group_name_id(group_id, get_obj=True)
         if group_obj:
             Group.purge_group(group_id, proceed=proceed_flag)
             validate_deletion(group_id)
         else:
             node_obj = Node.get_node_by_id(group_id)
             # If the ObjectId entered is not of a Group
             if node_obj:
                 if node_obj.collection_set:
                     for each_obj_id in node_obj.collection_set:
                         _group_deletion(each_obj_id)
                 del_status, del_status_msg = delete_node(
                     node_id=node_obj._id, deletion_type=1)
                 validate_deletion(node_obj._id)
     except Exception as group_del_err:
         print "\n Error occurred.", str(group_del_err)
Пример #9
0
    def purge_group(group_name_or_id, proceed=True):

        # fetch group object
        group_obj = Group.get_group_name_id(group_name_or_id, get_obj=True)

        if not group_obj:
            raise Exception(
                'Expects either group "name" or "_id". Got invalid argument or that group does not exists.'
            )

        group_id = group_obj._id

        # get all the objects belonging to this group
        all_nodes_under_gr = node_collection.find(
            {'group_set': {
                '$in': [group_id]
            }})

        # separate nodes belongs to one and more groups
        only_group_nodes_cnt = all_nodes_under_gr.clone().where(
            "this.group_set.length == 1").count()
        multi_group_nodes_cnt = all_nodes_under_gr.clone().where(
            "this.group_set.length > 1").count()

        print "Group:", group_obj.name, "(", group_obj.altnames, ") contains:\n",\
            "\t- unique (belongs to this group only) : ", only_group_nodes_cnt, \
            "\n\t- shared (belongs to other groups too): ", multi_group_nodes_cnt, \
            "\n\t============================================", \
            "\n\t- total: ", all_nodes_under_gr.count()

        if not proceed:
            print "\nDo you want to purge group and all unique nodes(belongs to this group only) under it?"
            print 'Enter Y/y to proceed else N/n to reject group deletion:'
            to_proceed = raw_input()
            proceed = True if (to_proceed in ['y', 'Y']) else False

        if proceed:
            print "\nProceeding further for purging of group and unique resources/nodes under it..."
            from gnowsys_ndf.ndf.views.methods import delete_node

            grp_res = node_collection.find({
                '$and': [{
                    'group_set': {
                        '$size': 1
                    }
                }, {
                    'group_set': {
                        '$all': [ObjectId(group_id)]
                    }
                }]
            })
            print "\n Total (unique) resources to be purge: ", grp_res.count()

            for each in grp_res:
                del_status, del_status_msg = delete_node(node_id=each._id,
                                                         deletion_type=1)
                # print del_status, del_status_msg
                if not del_status:
                    print "*" * 80
                    print "\n Error node: _id: ", each._id, " , name: ", each.name, " type: ", each.member_of_names_list
                    print "*" * 80

            print "\n Purging group: "
            del_status, del_status_msg = delete_node(node_id=group_id,
                                                     deletion_type=1)
            print del_status, del_status_msg

            # poping group_id from each of shared nodes under group
            all_nodes_under_gr.rewind()
            print "\n Total (shared) resources to be free from this group: ", all_nodes_under_gr.count(
            )
            for each_shared_node in all_nodes_under_gr:
                if group_id in each_shared_node.group_set:
                    each_shared_node.group_set.remove(group_id)
                    each_shared_node.save()

            return True

        print "\nAborting group deletion."
        return True
Пример #10
0
        del_status, del_status_msg = delete_node(
            node_id=each._id,
            deletion_type=1
        )
        # print "\n---------\n",del_status, "--", del_status_msg
        if not del_status:
            print "*"*80
            print "\n Error node: _id: ", each._id, " , name: ", each.name, " type: ", each.member_of_names_list
            print "*"*80


for group_obj in group_cur:
    confirmation = raw_input("Delete group: "+ str(group_obj.name)+ ". Enter (y/Y) to continue or (n) to skip this group: ")
    if confirmation == 'Y' or confirmation == 'y':
        # Fetch all nodes that have ONLY group_obj _id in its group_set.

        # grp_res = node_collection.find({'group_set':{'$size':1}, 'group_set': group_obj._id})
        grp_res = node_collection.find({ '$and': [ {'group_set':{'$size':1}}, {'group_set': {'$all': [ObjectId(group_obj._id)]}} ] })

        print "\n Total resources to be deleted", grp_res.count()
        # Delete all objects of the cursor grp_res

        delete_res(grp_res)
        print "\n Deleting group: "
        del_status, del_status_msg = delete_node(
            node_id=group_obj._id,
            deletion_type=1
        )
    else:
        continue
Пример #11
0
for group_obj in group_cur:
    confirmation = raw_input(
        "Delete group: " + str(group_obj.name) +
        ". Enter (y/Y) to continue or (n) to skip this group: ")
    if confirmation == 'Y' or confirmation == 'y':
        # Fetch all nodes that have ONLY group_obj _id in its group_set.

        # grp_res = node_collection.find({'group_set':{'$size':1}, 'group_set': group_obj._id})
        grp_res = node_collection.find({
            '$and': [{
                'group_set': {
                    '$size': 1
                }
            }, {
                'group_set': {
                    '$all': [ObjectId(group_obj._id)]
                }
            }]
        })

        print "\n Total resources to be deleted", grp_res.count()
        # Delete all objects of the cursor grp_res

        delete_res(grp_res)
        print "\n Deleting group: "
        del_status, del_status_msg = delete_node(node_id=group_obj._id,
                                                 deletion_type=1)
    else:
        continue
Пример #12
0
from gnowsys_ndf.ndf.models import node_collection
from gnowsys_ndf.ndf.views.methods import delete_node

# to find duplicate Author instances:
ag = node_collection.collection.aggregate([{'$match': {'_type': 'Author'}}, {'$group': {'_id': {'created_by': '$created_by',  }, 'objs': {'$push': '$$CURRENT'}, 'count': {'$sum': 1} }}, {'$match': {'count': {'$gt': 1}}},  ])

# aggregate all Author objects in a list
j = [x for sl in (i.get('objs') for i in ag['result']) for x in sl]
auth_dec = {}

# create a dict to have a list of ids to keep and delete to make decision:
for i in j:
    try:
        if i['created_at'] < auth_dec[i['created_by']]['old'].keys()[0]:
            auth_dec[i['created_by']]['new'].extends(auth_dec[i['created_by']]['old'])
            auth_dec[i['created_by']]['old'] = {i['created_at']: i['_id']}
        else:
            auth_dec[i['created_by']]['new'][i['created_at']] = i['_id']
    except:
        auth_dec[i['created_by']] = {'old': {i['created_at']: i['_id']}, 'new': {} }

# delete new instances:
for each_node_to_del_id in ([ sl for x in (i['new'].values() for i in auth_dec.values()) for sl in x ]):
    delete_node(each_node_to_del, deletion_type=1)

# Pending:
# - check for grelation `profile_pic` and other to take decision of which object to keep
Пример #13
0
from gnowsys_ndf.ndf.models import node_collection
from gnowsys_ndf.ndf.views.methods import delete_node

# to find duplicate Author instances:
ag = node_collection.collection.aggregate([{'$match': {'_type': 'Author'}}, {'$group': {'_id': {'created_by': '$created_by',  }, 'objs': {'$push': '$$CURRENT'}, 'count': {'$sum': 1} }}, {'$match': {'count': {'$gt': 1}}},  ])

# aggregate all Author objects in a list
j = [x for sl in (i.get('objs') for i in ag['result']) for x in sl]
auth_dec = {}

# create a dict to have a list of ids to keep and delete to make decision:
for i in j:
    try:
        if i['created_at'] < auth_dec[i['created_by']]['old'].keys()[0]:
            auth_dec[i['created_by']]['new'].extends(auth_dec[i['created_by']]['old'])
            auth_dec[i['created_by']]['old'] = {i['created_at']: i['_id']}
        else:
            auth_dec[i['created_by']]['new'][i['created_at']] = i['_id']
    except:
        auth_dec[i['created_by']] = {'old': {i['created_at']: i['_id']}, 'new': {} }

# delete new instances:
for each_node_to_del_id in ([ sl for x in (i['new'].values() for i in auth_dec.values()) for sl in x ]):
    delete_node(each_node_to_del_id, deletion_type=1)

# Pending:
# - check for grelation `profile_pic` and other to take decision of which object to keep
Пример #14
0
from gnowsys_ndf.ndf.models import *
from gnowsys_ndf.ndf.views.methods import delete_node

video_js_test_named_files = node_collection.find({
    'name': {
        '$regex': 'video-js-test',
        '$options': 'i'
    },
    '_type': 'GSystem'
})

asset_gst = node_collection.one({'_type': 'GSystemType', 'name': 'Asset'})
asset_cur = node_collection.find({'member_of': asset_gst._id})

for e in asset_cur:
    d, dd = delete_node(node_id=e._id, deletion_type=1)
    print d

for e in video_js_test_named_files:
    d, dd = delete_node(node_id=e._id, deletion_type=1)
    print d
from gnowsys_ndf.ndf.models import *
from gnowsys_ndf.ndf.views.methods import delete_node 

video_js_test_named_files = node_collection.find({'name': {'$regex': 'video-js-test', '$options': 'i'}, '_type': 'GSystem'})

asset_gst = node_collection.one({'_type': 'GSystemType', 'name': 'Asset'})
asset_cur = node_collection.find({'member_of': asset_gst._id})

for e in asset_cur:
	d,dd = delete_node(node_id=e._id, deletion_type=1)
	print d

for e in video_js_test_named_files:
	d,dd = delete_node(node_id=e._id, deletion_type=1)
	print d