Locked History Actions

attachment:install_toolshed_yaml_COMPLETE.py of Events/GCC2014/TrainingDay/API

Attachment 'install_toolshed_yaml_COMPLETE.py'

Download

   1 #!/usr/bin/env python
   2 #
   3 # quick and dirty script to install repositories from the toolshed at their
   4 # newest installable revisions.
   5 #
   6 # Sample invocation:   python install_toolshed_yaml.py tools.yaml MASTERLOCK http://localhost:8080
   7 # yaml format is:
   8 #
   9 # <shed>:
  10 #   <owner>:
  11 #   - <repo>
  12 #   - <repo>
  13 #
  14 # e.g.:
  15 #
  16 # toolshed.g2.bx.psu.edu:
  17 #   devteam:
  18 #   - bam_to_sam
  19 #   - ctd_batch
  20 #
  21 
  22 
  23 import sys
  24 import json
  25 import yaml
  26 import requests
  27 
  28 BASE_GALAXY_URL = 'http://localhost:8080'
  29 
  30 try:
  31     yamldata = yaml.load( open( sys.argv[1] ) )
  32     key = sys.argv[2]
  33 except:
  34     print >>sys.stderr, 'usage: %s <repos yaml> <galaxy api key> <galaxy url>' % sys.argv[0]
  35     raise
  36 
  37 for shed, owners in yamldata.items():
  38     for owner, names in owners.items():
  39         for name in names:
  40             print "Handling repository %s:%s:%s" % (shed, name, owner)
  41             # Get the latest installable revision of this repository directly
  42             # from the toolshed.  This call is a GET to something like:
  43             # GET https://toolshed.g2.bx.psu.edu/api/repositories/get_ordered_installable_revisions
  44             # with GET args 'name' and 'owner'
  45 
  46             url = 'https://%s/api/repositories/get_ordered_installable_revisions?name=%s&owner=%s' % ( shed, name, owner )
  47             response = requests.get(url)
  48             # The response from the toolshed should be something like the following list, which is valid JSON:
  49             # ["dc20f447c0e2", "250151b4d934"]
  50             # In this list, the last item is the most recent tool version
  51             rev = response.json()[-1]
  52             data = {'key': key,
  53                     'tool_shed_url': 'https://%s' % shed,
  54                     'name': name,
  55                     'owner': owner,
  56                     'changeset_revision': str(rev),
  57                     'install_repository_dependencies': True,
  58                     'install_tool_dependencies': True }
  59             url = '%s/api/tool_shed_repositories/new/install_repository_revision?key=%s' % ( BASE_GALAXY_URL, key )
  60             headers = { 'Content-Type': 'application/json' }
  61             response = requests.post(url,
  62                                      data=json.dumps(data),
  63                                      headers=headers)
  64             #  Bonus points here for actually inspecting the response and
  65             #  printing something appropriate
  66             print response.text

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2014-07-20 20:52:44, 281.3 KB) [[attachment:The Galaxy API (GCC2014 TD API).pdf]]
  • [get | view] (2014-07-01 14:55:36, 8.2 KB) [[attachment:api-scripts.completed.tar.gz]]
  • [get | view] (2014-07-01 14:55:22, 8.4 KB) [[attachment:api-scripts.exercises.tar.gz]]
  • [get | view] (2014-07-01 15:06:45, 0.6 KB) [[attachment:disk_usage_and_job_report.py]]
  • [get | view] (2014-07-01 15:07:52, 2.2 KB) [[attachment:install_toolshed_yaml.py]]
  • [get | view] (2014-07-01 15:08:02, 2.3 KB) [[attachment:install_toolshed_yaml_COMPLETE.py]]
  • [get | view] (2014-07-01 15:07:02, 1.4 KB) [[attachment:run_as.dataset_upload.py]]
  • [get | view] (2014-07-01 15:08:22, 2.8 KB) [[attachment:scaffold_user.py]]
  • [get | view] (2014-07-01 15:07:30, 0.1 KB) [[attachment:tools.yaml]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.