Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Jinja2
galaxy-tool-util>=20.9.1
galaxy-util>=20.9.0
pysam
rich
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_var(var_name):
setup-data-libraries=ephemeris.setup_data_libraries:main
galaxy-wait=ephemeris.sleep:main
install_tool_deps=ephemeris.install_tool_deps:main
set_library_permissions=ephemeris.set_library_permissions:main
'''
PACKAGE_DATA = {
# Be sure to update MANIFEST.in for source dist.
Expand Down
83 changes: 83 additions & 0 deletions src/ephemeris/set_library_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python
'''Tool to set permissions for all datasets of a given Galaxy Data Library'''

import argparse
import logging as log
from bioblend import galaxy
import sys, time, os
from rich.progress import Progress
from .common_parser import get_common_args
# Print iterations progress


def get_datasets(gi, library_id) -> [str]:
objects = gi.libraries.show_dataset(library_id=library_id, dataset_id='')
datasets = []
for index in range(len(objects)):
if objects[index]['type'] == 'file':
datasets.append(objects[index]['id'])
if datasets == []:
sys.exit("No datasets in library!")
else:
return datasets

def set_permissions(gi, library_id, role_ids):
log.info("Your library_id is " + library_id + "\n")
log.info("Your roles are: %s", " ".join(role_ids))
Comment thread
mira-miracoli marked this conversation as resolved.
Outdated
datasets = get_datasets(gi, library_id)
total = len(datasets)
est = total*3/60
# Give User time to abort
log.info('\nSuccess! %d datasets found. Processing can take up to %f min', total, est)
t = 5
with Progress() as progress:
task_countdown = progress.add_task("[red]Starting in 5 seconds...", total=total)
t = 5
while t:
time.sleep(1)
t -= 1
progress.update(task_countdown, advance=1)
# Process datasets
task = progress.add_task("[green]Processing datasets...", total=total)
for current in range(total):
log.debug('Processing dataset %d of %d, ID=%s', current, total, datasets[current])
rows, columns = os.popen('stty size', 'r').read().split()
gi.libraries.set_dataset_permissions(dataset_id=datasets[current], access_in=role_ids, modify_in=role_ids, manage_in=role_ids)
progress.update(task, advance=1)

def _parser():
'''Constructs the parser object'''
parent = get_common_args()
parser = argparse.ArgumentParser(
parents=[parent],
description='Populate the Galaxy data library with data.'
)
parser.add_argument('--library', help="Specify the data library ID")
parser.add_argument('--roles', help="Specify a list of comma separated role IDs")
return parser

def main():
print("\nThis command script uses bioblend galaxyAPI to set ALL permissions of ALL datasets")
print("in given library to given roles. Be careful and cancel with Crtl+C if unsure.\n")
args = _parser().parse_args()
if args.user and args.password:
gi = galaxy.GalaxyInstance(url=args.galaxy, email=args.user, password=args.password)
elif args.api_key:
gi = galaxy.GalaxyInstance(url=args.galaxy, key=args.api_key)
else:
sys.exit('Please specify either a valid Galaxy username/password or an API key.')

if args.verbose:
log.basicConfig(level=log.DEBUG)
else:
log.basicConfig(level=log.INFO)

if args.roles and args.library:
args.roles = [r.strip() for r in args.roles.split(",")]
else:
sys.exit("Specify library ID (--library myLibraryID) and (list of) role(s) (--roles roleId1,roleId2)")
set_permissions(gi, library_id=args.library, role_ids=args.roles)


if __name__ == '__main__':
main()