{ "cells": [ { "cell_type": "markdown", "id": "f4f3bc05-f53e-47d9-a133-6f93aee5ad60", "metadata": {}, "source": [ "# Polybox Synchronisation" ] }, { "cell_type": "markdown", "id": "72a3a32f-78a8-41d7-96c6-22c37c012913", "metadata": { "tags": [] }, "source": [ "#### This notebook can be used to perform a **one time** synchronisation with a folder of your personal [polybox.ethz.ch](https://polybox.ethz.ch/).\n", "\n", "To run the code of a cell, simply click into it and press `Shift`+`Enter` to exucte the content.\n", "\n", "```{caution}\n", "Be aware that this is a two-way synchronisation. This means that if you for example delete files within Jupyter or Polybox these files will also be deleted in the synced counterpart.\n", "```" ] }, { "cell_type": "markdown", "id": "93ecff4d-dbd4-4255-9b7c-f964c3b791d9", "metadata": { "tags": [] }, "source": [ "## Parameters" ] }, { "cell_type": "markdown", "id": "b5fecf88-bebd-4633-9612-5dfe3e5494b2", "metadata": { "tags": [] }, "source": [ "### User Name \n", "\n", "Either enter your default user name interactively with the `input()` command, or set it directly with double quotes in the code below (e.g. `user = \"myusername\"`)." ] }, { "cell_type": "code", "execution_count": null, "id": "62b2cb6c-5c7c-4f5b-8a95-a78df3a756e6", "metadata": { "tags": [] }, "outputs": [], "source": [ "user = input(\"Username: \")\n", "print(\"OK\")" ] }, { "cell_type": "markdown", "id": "8721a8ae-209e-4e7c-b6b9-c6cbd8ca242d", "metadata": { "tags": [] }, "source": [ "### Password\n", "We recommend to **not save the password** in an unencrypted notebook!" ] }, { "cell_type": "code", "execution_count": null, "id": "8a55764c-3518-4add-871d-d5220adfb7e1", "metadata": { "tags": [] }, "outputs": [], "source": [ "import getpass\n", "password = getpass.getpass(\"Password: \")\n", "print(\"OK\")" ] }, { "cell_type": "markdown", "id": "f442a395-34e1-4e31-bdfb-d88712181b93", "metadata": { "tags": [] }, "source": [ "### Local Jupyter Directory\n", "You may replace the `input()` function and assign your local jupyter directory to `jupyterdir` with a constant value (e.g.`jupyterdir = \"mydirectory\"`)." ] }, { "cell_type": "code", "execution_count": null, "id": "835dfc44-472f-4364-afe6-660b31d79c69", "metadata": { "tags": [] }, "outputs": [], "source": [ "import os\n", "jupyterdir = input(\"Path to local directory (start in your root directory without slash): \")\n", "jupyterpath = \"/home/jovyan/\"+ jupyterdir\n", "## makes code work from all locations\n", "os.chdir(jupyterpath)\n", "print(\"OK\")" ] }, { "cell_type": "markdown", "id": "db637b92-9868-4226-a5ec-f7491c1c5bc5", "metadata": {}, "source": [ "### Polybox Directory\n", "Directories shared with you are stored within `Shared/`. You may also set your source directory on polybox directly by assigning it to `polyboxpath`." ] }, { "cell_type": "code", "execution_count": null, "id": "eebaa8a6-6f69-44d3-84fc-50961b2ec5c4", "metadata": { "tags": [] }, "outputs": [], "source": [ "polyboxpath = input(\"Path on server (starts in root directory, no slash needed): \")\n", "print(\"OK\")" ] }, { "cell_type": "markdown", "id": "0bf634d7-58c9-4898-b2ed-841029452760", "metadata": { "tags": [] }, "source": [ "## Synchronisation\n", "Start the synchronisation between your Polybox and this JupyterLab by executing the following code:" ] }, { "cell_type": "code", "execution_count": null, "id": "a94c8246-6f0f-423a-906b-01b87536d8b3", "metadata": { "tags": [] }, "outputs": [], "source": [ "print(\"Initiating synchronisation...\")\n", "print(\"JupyterLab: /\" + jupyterdir, \" <-> Polybox: /\" + polyboxpath)\n", "#!owncloudcmd -s -u {user} -p {password} {source} https://polybox.ethz.ch {destination}\n", "!owncloudcmd -s --non-interactive -u $user -p $password $jupyterpath https://polybox.ethz.ch $polyboxpath && exit; echo \"Problem during sync (wrong password? incorrect path? read-only directory?)\"\n", "print(\"OK - Synchronisation complete.\")" ] }, { "cell_type": "code", "execution_count": null, "id": "cd8af085-6daa-46e8-a327-efffb4e26c35", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.8" }, "toc-autonumbering": false }, "nbformat": 4, "nbformat_minor": 5 }