Example #1
1
def import_shares():
    admin = User.objects.get(username='******')
    select = """SELECT 
                    sp.description,
                    sp.random_dir,
                    sp.submitted,
                    p.description as pdescription,
                    p.project_title as ptitle,
                    g.db_group, 
                    t.type as type, 
                    t.description as type_description 
                FROM sub_project sp join project p on sp.project_id = p.project_id join type t on sp.type_id = t.type_id join db_group g on g.group_id = p.group_id"""
    subprojects = dictfetchall(select)
    for sp in subprojects:
        share_id = '00000%s'%sp['random_dir']
        try:
            share = Share.objects.get(id=share_id)
            share.delete()
        except:
            pass
        share = Share(id=share_id)
        share.name = ('%s: %s- %s, %s'%(sp['db_group'],sp['ptitle'],sp['type'],sp['submitted']))[:99]
        print 'Creating %s'%share.name[:99]
        share.notes = "Project Description:%s\nSubproject Description:%s"%(sp['pdescription'],sp['description'])
        share.owner=admin
        share.created = sp['submitted']
        share.save()
        tag = Tag.objects.get_or_create(name=sp['db_group'])[0]
        share.tags.add(tag)
        share.save()
Example #2
0
def import_permissions():
    admin = User.objects.get(username='******')
    select = """SELECT  random_dir, login, permission FROM
    (
    SELECT sub_project_id, login, user.user_id, lastname, firstname, permission FROM all_user_group_permission, project, sub_project, user WHERE sub_project.project_id = project.project_id AND all_user_group_permission.group_id = project.group_id AND all_user_group_permission.user_id = user.user_id
    UNION
    SELECT sub_project_id, login, user.user_id, lastname, firstname, permission FROM all_user_sub_project_permission, user WHERE source LIKE 'project' AND all_user_sub_project_permission.user_id = user.user_id
    UNION
    SELECT sub_project_id, login, user.user_id, lastname, firstname, permission FROM all_user_sub_project_permission, user WHERE  source LIKE 'sub_project' AND all_user_sub_project_permission.user_id = user.user_id
    ) as X join sub_project sp on X.sub_project_id = sp.sub_project_id
    GROUP BY random_dir,login,permission
    ORDER BY random_dir,lastname, user_id, permission"""

    perms = dictfetchall(select)
    perm_map = {
        'administer': 'admin',
        'view-project': 'view_share_files',
        'view-files': 'download_share_files',
        'upload-files': 'write_to_share',
        'delete-files': 'delete_share_files'
    }
    for p in perms:
        share_id = '00000%s' % p['random_dir']
        print 'treating share %s' % share_id
        share = Share.objects.get(id=share_id)
        user = User.objects.get(email=p['login'])
        assign_perm(perm_map[p['permission']], user, share)
Example #3
0
def import_shares():
    admin = User.objects.get(username='******')
    select = """SELECT 
                    sp.description,
                    sp.random_dir,
                    sp.submitted,
                    p.description as pdescription,
                    p.project_title as ptitle,
                    g.db_group, 
                    t.type as type, 
                    t.description as type_description 
                FROM sub_project sp join project p on sp.project_id = p.project_id join type t on sp.type_id = t.type_id join db_group g on g.group_id = p.group_id"""
    subprojects = dictfetchall(select)
    for sp in subprojects:
        share_id = '00000%s' % sp['random_dir']
        try:
            share = Share.objects.get(id=share_id)
            share.delete()
        except:
            pass
        share = Share(id=share_id)
        share.name = (
            '%s: %s- %s, %s' %
            (sp['db_group'], sp['ptitle'], sp['type'], sp['submitted']))[:99]
        print 'Creating %s' % share.name[:99]
        share.notes = "Project Description:%s\nSubproject Description:%s" % (
            sp['pdescription'], sp['description'])
        share.owner = admin
        share.created = sp['submitted']
        share.save()
        tag = Tag.objects.get_or_create(name=sp['db_group'])[0]
        share.tags.add(tag)
        share.save()
Example #4
0
def get_table_rows(conn, table, limit=None, offset=None, order=None):
    try:
        with conn.cursor() as c:
            c.execute(query_gen.get_table_rows_query(table, limit, offset))
            return db.dictfetchall(c)
    except (query_gen.QueryGenError, psycopg2.DataError, psycopg2.IntegrityError), e:
        raise_bad_request(str(e))
Example #5
0
def get_table_query_row_count(conn, table, filters, limit=None, offset=None, order=None):
    try:
        with conn.cursor() as c:
            query, params = query_gen.get_filtered_rows_query(table, filters, limit, offset, order)
            c.execute(query_gen.get_row_count_query(query), params)
            return db.dictfetchall(c)[0]
    except (query_gen.QueryGenError, psycopg2.DataError, psycopg2.IntegrityError), e:
        raise_bad_request(str(e))
Example #6
0
def get_function_rows(conn, function, args, limit=None, offset=None, order=None):
    try:
        with conn.cursor() as c:
            query, _args = query_gen.get_function_query(function, args, limit, offset, order)
            c.execute(query, _args)
            return db.dictfetchall(c)
    except (query_gen.QueryGenError, psycopg2.DataError, psycopg2.IntegrityError), e:
        raise_bad_request(str(e))
Example #7
0
def insert_table_row(conn, table, obj):
    try:
        params = [obj[x] for x in obj]
        with conn.cursor() as c:
            c.execute(query_gen.insert_table_row_query(table, obj), params)
            rows = db.dictfetchall(c)
            if len(rows) > 0:
                return rows            
    except (query_gen.QueryGenError, psycopg2.DataError, psycopg2.IntegrityError), e:
        raise_bad_request(str(e))
Example #8
0
def insert_table_rows(conn, table, objs):
    try:
        copy_stmt, insert_buffer = query_gen.insert_table_rows_query(table, objs)
        with conn.cursor() as c:
            c.copy_expert(copy_stmt, insert_buffer)
            rows = db.dictfetchall(c)
            if len(rows) > 0:
                return rows              
    except (query_gen.QueryGenError, psycopg2.DataError, psycopg2.IntegrityError), e:
        raise_bad_request(str(e))
Example #9
0
def get_table_row(conn, table, pk):
    try:
        with conn.cursor() as c:
            c.execute(query_gen.get_table_row_query(schema.PKS, table, pk), [pk])
            rows = db.dictfetchall(c)
            if len(rows) > 0:
                return rows
        return None
    except (query_gen.QueryGenError, psycopg2.DataError, psycopg2.IntegrityError), e:
        raise_bad_request(str(e))
Example #10
0
def update_creation_date():
    select = "SELECT random_dir, submitted FROM sub_project"
    subprojects = dictfetchall(select)
    for sp in subprojects:
        share_id = '00000%s' % sp['random_dir']
        try:
            share = Share.objects.get(id=share_id)
            share.created = sp['submitted']
            share.save()
        except:
            pass
Example #11
0
def update_table_row(conn, table, pk, obj):
    try:
        query = query_gen.update_table_row_query(schema.PKS, table, obj)
        params = [obj[x] for x in obj] + [pk]
        with conn.cursor() as c:
            c.execute(query, params)
            rows = db.dictfetchall(c)
            if len(rows) > 0:
                return rows            
    except (query_gen.QueryGenError, psycopg2.DataError, psycopg2.IntegrityError), e:
        raise_bad_request(str(e))
Example #12
0
def update_creation_date():
    select = "SELECT random_dir, submitted FROM sub_project"
    subprojects = dictfetchall(select)
    for sp in subprojects:
        share_id = '00000%s'%sp['random_dir']
        try:
            share = Share.objects.get(id=share_id)
            share.created = sp['submitted']
            share.save()
        except:
            pass
Example #13
0
def create_symlinks():
    import os
    #     file = '/home/adam/bioshare_symlinks'
    select = 'SELECT target, random_dir FROM sub_project'
    results = dictfetchall(select)
    base = '/data/bioshare/'
    link_directory = '/data/bioshare_files/files'
    os.chdir(link_directory)
    for line in results:
        try:
            link = '00000%s' % line['random_dir']
            target = base + line['target']
            print '%s -> %s' % (link, target)
            os.symlink(target, link)
            print 'success'
        except Exception, e:
            print str(e)
Example #14
0
def create_symlinks():
    import os
#     file = '/home/adam/bioshare_symlinks'
    select = 'SELECT target, random_dir FROM sub_project'
    results = dictfetchall(select)
    base = '/data/bioshare/'
    link_directory = '/data/bioshare_files/files'
    os.chdir(link_directory)
    for line in results:
        try:
            link = '00000%s'%line['random_dir']
            target= base+line['target']
            print '%s -> %s'%(link,target)
            os.symlink(target,link)
            print 'success'
        except Exception, e:
            print str(e)
Example #15
0
def import_users():
    group = Group.objects.get_or_create(name='old_accounts')[0]
    print group
    users = dictfetchall('select * from user')
    for user in users:
        try:
            User.objects.get(email=user['login'])
            print 'User with email %s exists' % user['login']
        except:
            try:
                print 'Creating user %s' % user['login']
                u = User(username=user['login'],email=user['login'],first_name=user['firstname'],last_name=user['lastname'])
    #             u.set_password(password)
                u.save()
                u.groups.add(group)
                u.save()
            except:
                print 'Failed creating user %s' % user['login']
Example #16
0
def import_users():
    group = Group.objects.get_or_create(name='old_accounts')[0]
    print group
    users = dictfetchall('select * from user')
    for user in users:
        try:
            User.objects.get(email=user['login'])
            print 'User with email %s exists' % user['login']
        except:
            try:
                print 'Creating user %s' % user['login']
                u = User(username=user['login'],
                         email=user['login'],
                         first_name=user['firstname'],
                         last_name=user['lastname'])
                #             u.set_password(password)
                u.save()
                u.groups.add(group)
                u.save()
            except:
                print 'Failed creating user %s' % user['login']
Example #17
0
def import_permissions():
    admin = User.objects.get(username='******')
    select = """SELECT  random_dir, login, permission FROM
    (
    SELECT sub_project_id, login, user.user_id, lastname, firstname, permission FROM all_user_group_permission, project, sub_project, user WHERE sub_project.project_id = project.project_id AND all_user_group_permission.group_id = project.group_id AND all_user_group_permission.user_id = user.user_id
    UNION
    SELECT sub_project_id, login, user.user_id, lastname, firstname, permission FROM all_user_sub_project_permission, user WHERE source LIKE 'project' AND all_user_sub_project_permission.user_id = user.user_id
    UNION
    SELECT sub_project_id, login, user.user_id, lastname, firstname, permission FROM all_user_sub_project_permission, user WHERE  source LIKE 'sub_project' AND all_user_sub_project_permission.user_id = user.user_id
    ) as X join sub_project sp on X.sub_project_id = sp.sub_project_id
    GROUP BY random_dir,login,permission
    ORDER BY random_dir,lastname, user_id, permission"""
    
    perms = dictfetchall(select)
    perm_map = {'administer':'admin','view-project':'view_share_files','view-files':'download_share_files','upload-files':'write_to_share','delete-files':'delete_share_files'}
    for p in perms:
        share_id = '00000%s'%p['random_dir']
        print 'treating share %s' % share_id
        share = Share.objects.get(id=share_id)
        user = User.objects.get(email=p['login'])
        assign_perm(perm_map[p['permission']],user,share)