Skip to content

Commit 214d59d

Browse files
authored
Merge pull request #27 from galaxyproject/wf_extend
Support directories full of workflows
2 parents f35de6a + dfba304 commit 214d59d

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

ephemeris/workflow_install.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,56 @@
11
#!/usr/bin/env python
22
import argparse
33
import json
4+
import os
5+
import sys
46

57
from bioblend import galaxy
68

79

10+
def import_workflow(gi, path):
11+
"""
12+
Given a connection to a Galaxy Instance (gi) and a path to a Galaxy workflow file,
13+
this function will import the worklfow into Galaxy.
14+
"""
15+
with open(path, 'r') as wf_file:
16+
import_uuid = json.load(wf_file).get('uuid')
17+
existing_uuids = [d.get('latest_workflow_uuid') for d in gi.workflows.get_workflows()]
18+
if import_uuid not in existing_uuids:
19+
gi.workflows.import_workflow_from_local_path(path)
20+
21+
822
def main():
923
"""
1024
This script uses bioblend to import .ga workflow files into a running instance of Galaxy
1125
"""
1226
parser = argparse.ArgumentParser()
13-
parser.add_argument("-w", "--workflow_path", help='Path to workflow file')
27+
parser.add_argument("-w", "--workflow_path",
28+
help='Path to a workflow file or a directory with multiple workflow files ending with ".ga"')
1429
parser.add_argument("-g", "--galaxy",
15-
dest="galaxy_url",
16-
help="Target Galaxy instance URL/IP address (required "
17-
"if not defined in the tools list file)",)
18-
parser.add_argument("-a", "--apikey",
30+
help="Target Galaxy instance URL/IP address.")
31+
parser.add_argument("-u", "--user",
32+
help="Galaxy user name")
33+
parser.add_argument("-p", "--password",
34+
help="Password for the Galaxy user")
35+
parser.add_argument("-a", "--api_key",
1936
dest="api_key",
20-
help="Galaxy admin user API key (required if not "
21-
"defined in the tools list file)",)
37+
help="Galaxy admin user API key (required if not defined in the tools list file)")
38+
2239
args = parser.parse_args()
2340

24-
gi = galaxy.GalaxyInstance(url=args.galaxy_url, key=args.api_key)
41+
if args.user and args.password:
42+
gi = galaxy.GalaxyInstance(url=args.galaxy, email=args.user, password=args.password)
43+
elif args.api_key:
44+
gi = galaxy.GalaxyInstance(url=args.galaxy, key=args.api_key)
45+
else:
46+
sys.exit('Please specify either a valid Galaxy username/password or an API key.')
2547

26-
with open(args.workflow_path, 'r') as wf_file:
27-
import_uuid = json.load(wf_file).get('uuid')
28-
existing_uuids = [d.get('latest_workflow_uuid') for d in gi.workflows.get_workflows()]
29-
if import_uuid not in existing_uuids:
30-
gi.workflows.import_workflow_from_local_path(args.workflow_path)
48+
if os.path.isdir(args.workflow_path):
49+
for file_path in os.listdir(args.workflow_path):
50+
if file_path.endswith('.ga'):
51+
import_workflow(gi, os.path.join(args.workflow_path, file_path))
52+
else:
53+
import_workflow(gi, args.workflow_path)
3154

3255

3356
if __name__ == '__main__':

0 commit comments

Comments
 (0)