-
Notifications
You must be signed in to change notification settings - Fork 42
Set Library Permissions #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mvdbeek
merged 16 commits into
galaxyproject:master
from
mira-miracoli:set-library-permissions
Nov 30, 2022
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c8a8c69
added file
mira-miracoli 5b7214d
Update src/ephemeris/set_library_permissions.py
mira-miracoli 169006e
changed progress bar to rich
mira-miracoli 84ea2f6
added user input (y/n)
mira-miracoli fd1bf17
added silent and yes options
mira-miracoli 595fff0
fixed arguments
mira-miracoli ca6c5ce
fixed linting
mira-miracoli 578e15d
Update src/ephemeris/set_library_permissions.py
mira-miracoli 2aed9d3
Update src/ephemeris/set_library_permissions.py
mira-miracoli 16b31e0
Update src/ephemeris/set_library_permissions.py
mira-miracoli 9d549fb
Update src/ephemeris/set_library_permissions.py
mira-miracoli b6de16c
changed imports
mira-miracoli 18770db
sorted import
mira-miracoli 67a3d84
abcdefg...
mira-miracoli 867cf97
Drop 3.6 support
hexylena 2538e3b
add requires, more recent versions that work
hexylena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ Jinja2 | |
| galaxy-tool-util>=20.9.1 | ||
| galaxy-util>=20.9.0 | ||
| pysam | ||
| rich | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
| 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() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.