Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Mounting Google Drive to JupyterLab\n",
- "\n",
- "# *You only need to authorize Google Drive permissions once. Otherwise, run the last line to mount your Google Drive*"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Select the first cell and execute the cell `(Shift+Enter)`. \n",
- "#### The output of the command will appear below the cell.\n",
- "\n",
- "Go to the provided link in a new browser tab and copy the verification code.\n",
- "\n",
- "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",
- "\n",
- "#### Steps\n",
- "\n",
- "1. Highlight and copy the URL to a new browser tab (`Cmd+C` on Mac, `Ctrl+C` on PC) \n",
- "2. Select your g.ucla.edu account, and click on \"Allow\" to reveal your verification code\n",
- "3. Copy the verification code, and paste it to the text field \"Enter verification code:\"."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "from google.colab import auth\n",
- "auth.authenticate_user()\n",
- "from oauth2client.client import GoogleCredentials\n",
- "creds = GoogleCredentials.get_application_default()\n",
- "import getpass"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Excute the 2nd cell `(Shift+Enter)`. \n",
- "\n",
- "Go to the provided link in a new browser tab and copy the API token. \n",
- "\n",
- "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",
- "\n",
- "#### Steps\n",
- "\n",
- "1. Highlight and copy the URL to a new browser tab (`Cmd+C` on Mac, `Ctrl+C` on PC) \n",
- "2. Select your g.ucla.edu account, and click on \"Allow\" to reveal your token.\n",
- "3. Copy the token, and paste it to the text field."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "!google-drive-ocamlfuse -headless -id {creds.client_id} -secret {creds.client_secret} < /dev/null 2>&1 | grep URL\n",
- "vcode = getpass.getpass()\n",
- "!echo {vcode} | google-drive-ocamlfuse -headless -id {creds.client_id} -secret {creds.client_secret}"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Mount your Google Drive\n",
- "- The following line creates a **gdrive** directory (folder) in your local instance's home directory."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "!mkdir -p ~/gdrive"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "- The command (`google-drive-ocamlfuse gdrive`) mounts your Google Drive onto your **gdrive** directory. \n",
- "\n",
- "- **Note:** Changes made to your gdrive directory are made directly to your Google Drive, and vice versa.\n",
- "\n",
- "- **This command needs to be run each time you login and start a new session in JupyterLab**"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "!google-drive-ocamlfuse ~/gdrive"
- ]
- }
- ],
- "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.6.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment