Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Globus presentation and JupyterHub demo
- Loading branch information
Rick Wagner
committed
Aug 4, 2017
1 parent
4118cd3
commit 198bed0
Showing
2 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
296 changes: 296 additions & 0 deletions
296
8_globus_file_transfer/SDSCSummerInstituteJupyterHub.ipynb
This file contains 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,296 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import pickle\n", | ||
"import base64\n", | ||
"import os\n", | ||
"import glob\n", | ||
"import hashlib\n", | ||
"import globus_sdk" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Some variables\n", | ||
"transfer_client = None\n", | ||
"bookmarks = {}\n", | ||
"\n", | ||
"# Where to get data\n", | ||
"# Public shared data from Comet\n", | ||
"comet_share = 'Cat Pictures on Comet'\n", | ||
"comet_path = '/catpictures/'\n", | ||
"\n", | ||
"# Where to send data \n", | ||
"# Server running Jupyter kernel\n", | ||
"jh_demo = 'JupyterHub Demo'\n", | ||
"jh_path = '/home/rpwagner/demodata/'\n", | ||
"\n", | ||
"# Where to send results\n", | ||
"# My laptop running Globus Connect Personal\n", | ||
"my_laptop = 'RickMacBook'\n", | ||
"my_laptop_path = '/Users/rpwagner/tmp/demodata/'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"AQBZhjJXAAAAAAAFkWteZqH5KrTp4zReowUjzWCAqIbGVAUtmfvK4ewLQ27Sov3Yd1ntHzVBZiojxJpZmYeI\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Get the token from the notebook environment\n", | ||
"data = pickle.loads(base64.b64decode(os.getenv('GLOBUS_DATA')))\n", | ||
"print(data['tokens']['transfer.api.globus.org']['access_token'])\n", | ||
"transfer_token = data['tokens']['transfer.api.globus.org']['access_token']" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Tutorial 1 \n", | ||
" ddb59aef-6d04-11e5-ba46-22000b92c6ec \n", | ||
"\n", | ||
"RickMacBook \n", | ||
" 0062f30a-8ff0-11e6-b067-22000b92c261 \n", | ||
"\n", | ||
"Comet \n", | ||
" de463f97-6d04-11e5-ba46-22000b92c6ec \n", | ||
"\n", | ||
"JupyterHub Demo \n", | ||
" 985d6830-422d-11e7-bd35-22000b9a448b \n", | ||
"\n", | ||
"Cat Pictures on Comet \n", | ||
" 4950fae2-78d6-11e7-8bcb-22000b9923ef \n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Something that handles the token\n", | ||
"authorizer = globus_sdk.AccessTokenAuthorizer(transfer_token)\n", | ||
"\n", | ||
"# Something that can talk to Globus Transfer\n", | ||
"transfer_client = globus_sdk.TransferClient(authorizer=authorizer)\n", | ||
"\n", | ||
"# Grab my bookmarked endpooints\n", | ||
"bookmark_data = transfer_client.bookmark_list()['DATA']\n", | ||
"\n", | ||
"# Look at list of bookmarks\n", | ||
"for bookmark in bookmark_data:\n", | ||
" bookmarks[bookmark['name']] = bookmark['endpoint_id']\n", | ||
" print(bookmark['name'], '\\n ', bookmark['endpoint_id'], '\\n')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Chaton-corail.jpg\n", | ||
"kitty_gauss08-c.png\n", | ||
"kitty_gauss08.png\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# What's in that Comet share?\n", | ||
"ls_output = transfer_client.operation_ls(bookmarks[comet_share], path=comet_path)['DATA']\n", | ||
"for thing in ls_output:\n", | ||
" print(thing['name'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[]" | ||
] | ||
}, | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Look at local directory\n", | ||
"# Should be an empty directory\n", | ||
"glob.glob(jh_path + '/*')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Thing to hold list of things to tranfer\n", | ||
"# and source and destination endpoints\n", | ||
"tdata = globus_sdk.TransferData(transfer_client, \n", | ||
" bookmarks[comet_share],\n", | ||
" bookmarks[jh_demo])\n", | ||
"# Add a files or folder\n", | ||
"tdata.add_item(comet_path, jh_path, recursive=True)\n", | ||
"\n", | ||
"# Kick off transfer\n", | ||
"transfer_submission = transfer_client.submit_transfer(tdata)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 18, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"SUCCEEDED\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Neurotically check status (i.e., keep evaluating this cell)\n", | ||
"task = transfer_client.get_task(transfer_submission['task_id'])\n", | ||
"print(task['status'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 19, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"/home/rpwagner/demodata/kitty_gauss08-c.png\n", | ||
"/home/rpwagner/demodata/Chaton-corail.jpg\n", | ||
"/home/rpwagner/demodata/kitty_gauss08.png\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Look at local directory\n", | ||
"# Should NOT be an empty directory\n", | ||
"filenames = glob.glob(jh_path + '/*')\n", | ||
"for filename in filenames:\n", | ||
" print(filename)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"1daaf5a3d476c3a68612acf0084cfbc8\n", | ||
"a1de7d358906166449540d8ff53ae065\n", | ||
"a838d27bbb0fcbd97f9b04099ee9524c\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Pseudowork \n", | ||
"for filename in filenames:\n", | ||
" print(hashlib.md5(open(filename,'rb').read()).hexdigest())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Thing to hold list of things to tranfer\n", | ||
"# and source and destination endpoints\n", | ||
"tdata = globus_sdk.TransferData(transfer_client, \n", | ||
" bookmarks[jh_demo],\n", | ||
" bookmarks[my_laptop])\n", | ||
"# Add a files or folder\n", | ||
"tdata.add_item(jh_path, my_laptop_path, recursive=True)\n", | ||
"\n", | ||
"# Kick off transfer\n", | ||
"transfer_submission = transfer_client.submit_transfer(tdata)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 28, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"SUCCEEDED\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Neurotically check status (i.e., keep evaluating this cell)\n", | ||
"task = transfer_client.get_task(transfer_submission['task_id'])\n", | ||
"print(task['status'])" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.5.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |