{ "cells": [ { "cell_type": "code", "execution_count": 65, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T22:46:32.518166Z", "start_time": "2022-06-07T22:46:26.102914Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: s3pathlib in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.0.10)\n", "Requirement already satisfied: pathlib-mate>=1.0.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from s3pathlib) (1.0.3)\n", "Requirement already satisfied: boto-session-manager>=0.0.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from s3pathlib) (0.0.4)\n", "Requirement already satisfied: boto3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from boto-session-manager>=0.0.2->s3pathlib) (1.16.59)\n", "Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pathlib-mate>=1.0.1->s3pathlib) (1.15.0)\n", "Requirement already satisfied: autopep8 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pathlib-mate>=1.0.1->s3pathlib) (1.5.4)\n", "Requirement already satisfied: atomicwrites in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pathlib-mate>=1.0.1->s3pathlib) (1.4.0)\n", "Requirement already satisfied: pycodestyle>=2.6.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from autopep8->pathlib-mate>=1.0.1->s3pathlib) (2.6.0)\n", "Requirement already satisfied: toml in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from autopep8->pathlib-mate>=1.0.1->s3pathlib) (0.10.2)\n", "Requirement already satisfied: botocore<1.20.0,>=1.19.59 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from boto3->boto-session-manager>=0.0.2->s3pathlib) (1.19.63)\n", "Requirement already satisfied: s3transfer<0.4.0,>=0.3.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from boto3->boto-session-manager>=0.0.2->s3pathlib) (0.3.7)\n", "Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from boto3->boto-session-manager>=0.0.2->s3pathlib) (0.10.0)\n", "Requirement already satisfied: urllib3<1.27,>=1.25.4 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from botocore<1.20.0,>=1.19.59->boto3->boto-session-manager>=0.0.2->s3pathlib) (1.26.2)\n", "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from botocore<1.20.0,>=1.19.59->boto3->boto-session-manager>=0.0.2->s3pathlib) (2.8.1)\n", "\u001b[33mWARNING: You are using pip version 21.3.1; however, version 22.1.2 is available.\n", "You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install --upgrade pip' command.\u001b[0m\n" ] } ], "source": [ "!pip3 install s3pathlib" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T19:29:21.686021Z", "start_time": "2022-06-07T19:29:20.759098Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[33mWARNING: Skipping fsxpathlib as it is not installed.\u001b[0m\r\n" ] } ], "source": [ "!pip3 uninstall fsxpathlib -y" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T19:30:14.709335Z", "start_time": "2022-06-07T19:30:04.415666Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Processing /Users/cheyaohu/WorkDocs/Open_Source/fsxpathlib-project/dist/fsxpathlib-0.0.1-py2.py3-none-any.whl\n", "Collecting pathlib-mate>=1.0.3\n", " Using cached pathlib_mate-1.0.3-py2.py3-none-any.whl (120 kB)\n", "Collecting s3pathlib>=1.0.10\n", " Using cached s3pathlib-1.0.10-py2.py3-none-any.whl (66 kB)\n", "Collecting boto-session-manager>=0.0.2\n", " Using cached boto_session_manager-0.0.4-py2.py3-none-any.whl (20 kB)\n", "Collecting smart-open>=5.2.1\n", " Using cached smart_open-6.0.0-py3-none-any.whl (58 kB)\n", "Collecting loguru>=0.6.0\n", " Using cached loguru-0.6.0-py3-none-any.whl (58 kB)\n", "Requirement already satisfied: boto3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from fsxpathlib==0.0.1) (1.16.59)\n", "Requirement already satisfied: smbprotocol in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from fsxpathlib==0.0.1) (1.9.0)\n", "Requirement already satisfied: autopep8 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pathlib-mate>=1.0.3->fsxpathlib==0.0.1) (1.5.4)\n", "Requirement already satisfied: atomicwrites in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pathlib-mate>=1.0.3->fsxpathlib==0.0.1) (1.4.0)\n", "Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pathlib-mate>=1.0.3->fsxpathlib==0.0.1) (1.15.0)\n", "Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from boto3->fsxpathlib==0.0.1) (0.10.0)\n", "Requirement already satisfied: s3transfer<0.4.0,>=0.3.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from boto3->fsxpathlib==0.0.1) (0.3.7)\n", "Requirement already satisfied: botocore<1.20.0,>=1.19.59 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from boto3->fsxpathlib==0.0.1) (1.19.63)\n", "Requirement already satisfied: cryptography>=2.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from smbprotocol->fsxpathlib==0.0.1) (3.2.1)\n", "Requirement already satisfied: pyspnego in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from smbprotocol->fsxpathlib==0.0.1) (0.3.1)\n", "Requirement already satisfied: urllib3<1.27,>=1.25.4 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from botocore<1.20.0,>=1.19.59->boto3->fsxpathlib==0.0.1) (1.26.2)\n", "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from botocore<1.20.0,>=1.19.59->boto3->fsxpathlib==0.0.1) (2.8.1)\n", "Requirement already satisfied: cffi!=1.11.3,>=1.8 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from cryptography>=2.0->smbprotocol->fsxpathlib==0.0.1) (1.14.3)\n", "Requirement already satisfied: pycodestyle>=2.6.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from autopep8->pathlib-mate>=1.0.3->fsxpathlib==0.0.1) (2.6.0)\n", "Requirement already satisfied: toml in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from autopep8->pathlib-mate>=1.0.3->fsxpathlib==0.0.1) (0.10.2)\n", "Requirement already satisfied: pycparser in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.0->smbprotocol->fsxpathlib==0.0.1) (2.20)\n", "Installing collected packages: pathlib-mate, boto-session-manager, smart-open, s3pathlib, loguru, fsxpathlib\n", " Attempting uninstall: pathlib-mate\n", " Found existing installation: pathlib-mate 1.0.2\n", " Uninstalling pathlib-mate-1.0.2:\n", " Successfully uninstalled pathlib-mate-1.0.2\n", " Attempting uninstall: smart-open\n", " Found existing installation: smart-open 3.0.0\n", " Uninstalling smart-open-3.0.0:\n", " Successfully uninstalled smart-open-3.0.0\n", " Attempting uninstall: s3pathlib\n", " Found existing installation: s3pathlib 1.0.1\n", " Uninstalling s3pathlib-1.0.1:\n", " Successfully uninstalled s3pathlib-1.0.1\n", "Successfully installed boto-session-manager-0.0.4 fsxpathlib-0.0.1 loguru-0.6.0 pathlib-mate-1.0.3 s3pathlib-1.0.10 smart-open-6.0.0\n", "\u001b[33mWARNING: You are using pip version 21.3.1; however, version 22.1.2 is available.\n", "You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m pip install --upgrade pip' command.\u001b[0m\n" ] } ], "source": [ "!pip3 install ../dist/fsxpathlib-0.0.1-py2.py3-none-any.whl" ] }, { "cell_type": "code", "execution_count": 66, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T22:46:40.027669Z", "start_time": "2022-06-07T22:46:40.023742Z" } }, "outputs": [], "source": [ "import getpass\n", "from s3pathlib import S3Path\n", "from fsxpathlib import FSxClient\n", "from fsxpathlib import FsxPath\n", "from pathlib_mate import Path\n", "import os" ] }, { "cell_type": "code", "execution_count": 82, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:13:55.079118Z", "start_time": "2022-06-07T23:13:49.601080Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "What is the password for accessing FSx?········\n", "Connect to the FSx server successfully\n" ] } ], "source": [ "password = getpass.getpass(prompt='What is the password for accessing FSx?')\n", "fsx = FSxClient(fsx_file_system_id='fs-054a31b0ff86de2b0',\n", " ad_username='admin',\n", " ad_password=password)\n", "if fsx:\n", " print(\"Connect to the FSx server successfully\")" ] }, { "cell_type": "code", "execution_count": 77, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:12:51.623161Z", "start_time": "2022-06-07T23:11:51.506352Z" } }, "outputs": [], "source": [ "fsx_sess = fsx.create_session()" ] }, { "cell_type": "code", "execution_count": 83, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:14:01.947924Z", "start_time": "2022-06-07T23:14:01.945376Z" } }, "outputs": [], "source": [ "p = FsxPath(fsx.server, \"share\", \"test\", \"input.csv\")" ] }, { "cell_type": "code", "execution_count": 75, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:11:07.148211Z", "start_time": "2022-06-07T23:11:07.145188Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "amznfsx3sh9aujr.corp.fsxvpc.com\\share\\test\\input.csv\n" ] } ], "source": [ "print(p.abspath)" ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:14:04.413292Z", "start_time": "2022-06-07T23:14:04.379273Z" } }, "outputs": [], "source": [ "p.remove_if_exists()" ] }, { "cell_type": "code", "execution_count": 79, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:13:22.362485Z", "start_time": "2022-06-07T23:13:22.339807Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.exists()" ] }, { "cell_type": "code", "execution_count": 85, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:14:16.573128Z", "start_time": "2022-06-07T23:14:16.570362Z" } }, "outputs": [], "source": [ "p = FsxPath(fsx.server, \"share\", \"test\", \"new.csv\")" ] }, { "cell_type": "code", "execution_count": 86, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:14:24.185926Z", "start_time": "2022-06-07T23:14:24.123696Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "copy from /Users/cheyaohu/WorkDocs/Open_Source/fsxpathlib-project/examples/input.csv to amznfsx3sh9aujr.corp.fsxvpc.com\\share\\test\\new.csv\n", " done\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.copy_from(Path('./input.csv'))" ] }, { "cell_type": "code", "execution_count": 87, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:14:26.931843Z", "start_time": "2022-06-07T23:14:26.850505Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "copy from amznfsx3sh9aujr.corp.fsxvpc.com\\share\\test\\new.csv to /Users/cheyaohu/WorkDocs/Open_Source/fsxpathlib-project/examples/new.csv\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.copy_to(Path('./new.csv'))" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T23:14:38.011115Z", "start_time": "2022-06-07T23:14:38.008260Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "file_exists = os.path.exists('new.csv')\n", "\n", "print(file_exists)" ] }, { "cell_type": "code", "execution_count": 68, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T22:48:24.137222Z", "start_time": "2022-06-07T22:48:24.070807Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "name, id\n", "ivan, 1\n", "chen, 2\n" ] } ], "source": [ "print(p.read_text())" ] }, { "cell_type": "code", "execution_count": 71, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T22:52:23.805184Z", "start_time": "2022-06-07T22:52:23.802825Z" } }, "outputs": [], "source": [ "s3path_prefix = S3Path(\n", " \"fsx-cheyaohu\",\n", " \"demo\",\n", " \"input.csv\")" ] }, { "cell_type": "code", "execution_count": 72, "metadata": { "ExecuteTime": { "end_time": "2022-06-07T22:52:25.593264Z", "start_time": "2022-06-07T22:52:25.093228Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "copy from amznfsx3sh9aujr.corp.fsxvpc.com\\share\\test\\new.csv to s3://fsx-cheyaohu/demo/input.csv\n", " done\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p.copy_to(s3path_prefix)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7.7" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }