Locked History Actions

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

Attachment 'install_toolshed_yaml.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             url = "FILL ME IN"
  46             response = requests.get(url)
  47             # The response from the toolshed should be something like the following list, which is valid JSON:
  48             # ["dc20f447c0e2", "250151b4d934"]
  49             # In this list, the last item is the most recent tool version
  50 
  51             # Now we need to POST to api/tool_shed_repositories with:
  52             # tool_shed_url, repository name, owner, changeset revision,
  53             # install_repository_dependencies (boolean) and
  54             # install_tool_dependencies (boolean)
  55 
  56             data = {}  # Fill this in too
  57 
  58             # Let's make the this request, you'll want to manually set the header with:
  59             headers = { 'Content-Type': 'application/json' }
  60             response = requests.post(url,
  61                                      data=json.dumps(data),
  62                                      headers=headers)
  63             #  Bonus points here for actually inspecting the response and
  64             #  printing something appropriate
  65             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.