Guest User

Untitled

a guest
Apr 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# Mounting Google Drive to JupyterLab\n",
  8. "\n",
  9. "# *You only need to authorize Google Drive permissions once. Otherwise, run the last line to mount your Google Drive*"
  10. ]
  11. },
  12. {
  13. "cell_type": "markdown",
  14. "metadata": {},
  15. "source": [
  16. "### Select the first cell and execute the cell `(Shift+Enter)`. \n",
  17. "#### The output of the command will appear below the cell.\n",
  18. "\n",
  19. "Go to the provided link in a new browser tab and copy the verification code.\n",
  20. "\n",
  21. "This allows Google Cloud to access information in your Google account, if you have multiple Google accounts be sure to select your g.ucla.edu account:\n",
  22. "\n",
  23. "#### Steps\n",
  24. "\n",
  25. "1. Highlight and copy the URL to a new browser tab (`Cmd+C` on Mac, `Ctrl+C` on PC) \n",
  26. "2. Select your g.ucla.edu account, and click on \"Allow\" to reveal your verification code\n",
  27. "3. Copy the verification code, and paste it to the text field \"Enter verification code:\"."
  28. ]
  29. },
  30. {
  31. "cell_type": "code",
  32. "execution_count": null,
  33. "metadata": {},
  34. "outputs": [],
  35. "source": [
  36. "from google.colab import auth\n",
  37. "auth.authenticate_user()\n",
  38. "from oauth2client.client import GoogleCredentials\n",
  39. "creds = GoogleCredentials.get_application_default()\n",
  40. "import getpass"
  41. ]
  42. },
  43. {
  44. "cell_type": "markdown",
  45. "metadata": {},
  46. "source": [
  47. "### Excute the 2nd cell `(Shift+Enter)`. \n",
  48. "\n",
  49. "Go to the provided link in a new browser tab and copy the API token. \n",
  50. "\n",
  51. "This allows Google Cloud access to your Google Drive, and is passed on to Google Drive OCamlFUSE to mount your files onto your local instance.\n",
  52. "\n",
  53. "#### Steps\n",
  54. "\n",
  55. "1. Highlight and copy the URL to a new browser tab (`Cmd+C` on Mac, `Ctrl+C` on PC) \n",
  56. "2. Select your g.ucla.edu account, and click on \"Allow\" to reveal your token.\n",
  57. "3. Copy the token, and paste it to the text field."
  58. ]
  59. },
  60. {
  61. "cell_type": "code",
  62. "execution_count": null,
  63. "metadata": {},
  64. "outputs": [],
  65. "source": [
  66. "!google-drive-ocamlfuse -headless -id {creds.client_id} -secret {creds.client_secret} < /dev/null 2>&1 | grep URL\n",
  67. "vcode = getpass.getpass()\n",
  68. "!echo {vcode} | google-drive-ocamlfuse -headless -id {creds.client_id} -secret {creds.client_secret}"
  69. ]
  70. },
  71. {
  72. "cell_type": "markdown",
  73. "metadata": {},
  74. "source": [
  75. "### Mount your Google Drive\n",
  76. "- The following line creates a **gdrive** directory (folder) in your local instance's home directory."
  77. ]
  78. },
  79. {
  80. "cell_type": "code",
  81. "execution_count": null,
  82. "metadata": {},
  83. "outputs": [],
  84. "source": [
  85. "!mkdir -p ~/gdrive"
  86. ]
  87. },
  88. {
  89. "cell_type": "markdown",
  90. "metadata": {},
  91. "source": [
  92. "- The command (`google-drive-ocamlfuse gdrive`) mounts your Google Drive onto your **gdrive** directory. \n",
  93. "\n",
  94. "- **Note:** Changes made to your gdrive directory are made directly to your Google Drive, and vice versa.\n",
  95. "\n",
  96. "- **This command needs to be run each time you login and start a new session in JupyterLab**"
  97. ]
  98. },
  99. {
  100. "cell_type": "code",
  101. "execution_count": 1,
  102. "metadata": {},
  103. "outputs": [],
  104. "source": [
  105. "!google-drive-ocamlfuse ~/gdrive"
  106. ]
  107. }
  108. ],
  109. "metadata": {
  110. "kernelspec": {
  111. "display_name": "Python 3",
  112. "language": "python",
  113. "name": "python3"
  114. },
  115. "language_info": {
  116. "codemirror_mode": {
  117. "name": "ipython",
  118. "version": 3
  119. },
  120. "file_extension": ".py",
  121. "mimetype": "text/x-python",
  122. "name": "python",
  123. "nbconvert_exporter": "python",
  124. "pygments_lexer": "ipython3",
  125. "version": "3.6.5"
  126. }
  127. },
  128. "nbformat": 4,
  129. "nbformat_minor": 2
  130. }
Add Comment
Please, Sign In to add comment