Locked History Actions

attachment:run_as.dataset_upload.py of Events/GCC2014/TrainingDay/API

Attachment 'run_as.dataset_upload.py'

Download

   1 #!/usr/bin/env python
   2 
   3 import sys
   4 import os
   5 import json
   6 import output
   7 import requests
   8 
   9 BASE_URL = 'http://localhost:8080'
  10 
  11 # -----------------------------------------------------------------------------
  12 def upload_file_as_another_user( user_id, history_id, filepath, **kwargs ):
  13     full_url = BASE_URL + '/api/tools'
  14 
  15     inputs = {
  16         'files_0|type'  : 'upload_dataset',
  17         'ajax_upload'   : u'true',
  18         'files_0|NAME'  : os.path.basename( filepath ),
  19         'dbkey'         : '?',
  20         'file_type'     : 'auto',
  21     }
  22     data = {
  23         'key'           : open( '.api-key' ).readline().strip(),
  24         'tool_id'       : 'upload1',
  25         'history_id'    : history_id,
  26         'inputs'        : json.dumps( inputs ),
  27         
  28         # by sending the additional param 'run_as', (and if we have api_allow_run_as set to our email),
  29         #   we can tell Galaxy to upload a file as another user
  30         'run_as'        : user_id
  31     }
  32 
  33     response = None
  34     with open( filepath, 'rb' ) as file_to_upload:
  35         files = { 'files_0|file_data' : file_to_upload }
  36         response = requests.post( full_url, data=data, files=files )
  37     return response
  38 
  39 
  40 # -----------------------------------------------------------------------------
  41 if __name__ == '__main__':
  42 
  43     run_as_email, history_id, filepath = sys.argv[1:4]
  44     response = upload_file( user_id, history_id, filepath )
  45     output.output_response( response )

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.