|
106 | 106 | "outputs": [], |
107 | 107 | "source": [ |
108 | 108 | "#| export\n", |
109 | | - "def _mk_auth_req(url:str, method:str='get', **kwargs):\n", |
110 | | - " r = getattr(_get_client(PLASH_CONFIG_HOME), method)(url, **kwargs)\n", |
| 109 | + "def _mk_auth_req(url:str, method:str='get', timeout=300., **kwargs):\n", |
| 110 | + " r = getattr(_get_client(PLASH_CONFIG_HOME), method)(url, timeout=timeout, **kwargs)\n", |
111 | 111 | " if r.status_code == 200: return r\n", |
112 | 112 | " else: print(f'Failure: {r.headers[\"X-Plash-Error\"]}')" |
113 | 113 | ] |
|
406 | 406 | " plash_app.write_text(f'export PLASH_APP_NAME={name}')\n", |
407 | 407 | " \n", |
408 | 408 | " tarz, _ = create_tar_archive(path, force_data)\n", |
409 | | - " r = _mk_auth_req(_endpoint(rt=\"/upload\"), \"post\", files={'file': tarz}, timeout=300.0, \n", |
| 409 | + " r = _mk_auth_req(_endpoint(rt=\"/upload\"), \"post\", files={'file': tarz},\n", |
410 | 410 | " data={'name': name, 'force_data': force_data})\n", |
411 | 411 | " if r:\n", |
412 | 412 | " print('✅ Upload complete! Your app is currently being built.')\n", |
|
434 | 434 | "usage: plash_deploy [-h] [--path PATH] [--name NAME] [--force_data]\n", |
435 | 435 | "\n", |
436 | 436 | "Deploys app to production. By default, this command erases all files in your app which are not in data/. Then uploads\n", |
437 | | - "all files and folders, except paths starting with '.' and except the local data/ directory. If `--force data` is used,\n", |
| 437 | + "all files and folders, except paths starting with `.` and except the local data/ directory. If `--force_data` is used,\n", |
438 | 438 | "then it erases all files in production. Then it uploads all files and folders, including `data/`, except paths starting\n", |
439 | | - "with '.'.\n", |
| 439 | + "with `.`.\n", |
440 | 440 | "\n", |
441 | 441 | "options:\n", |
442 | 442 | " -h, --help show this help message and exit\n", |
|
739 | 739 | "plash_logs --help" |
740 | 740 | ] |
741 | 741 | }, |
| 742 | + { |
| 743 | + "cell_type": "code", |
| 744 | + "execution_count": null, |
| 745 | + "id": "b8959fc4", |
| 746 | + "metadata": {}, |
| 747 | + "outputs": [], |
| 748 | + "source": [ |
| 749 | + "#| hide\n", |
| 750 | + "import tempfile\n", |
| 751 | + "temp_dir = tempfile.TemporaryDirectory()\n", |
| 752 | + "td = Path(temp_dir.name)" |
| 753 | + ] |
| 754 | + }, |
| 755 | + { |
| 756 | + "cell_type": "code", |
| 757 | + "execution_count": null, |
| 758 | + "id": "f8441125", |
| 759 | + "metadata": {}, |
| 760 | + "outputs": [], |
| 761 | + "source": [ |
| 762 | + "#| export\n", |
| 763 | + "@patch\n", |
| 764 | + "def _is_dir_empty(self:Path): return next(self.iterdir(), None) is None" |
| 765 | + ] |
| 766 | + }, |
| 767 | + { |
| 768 | + "cell_type": "code", |
| 769 | + "execution_count": null, |
| 770 | + "id": "c18149e1", |
| 771 | + "metadata": {}, |
| 772 | + "outputs": [], |
| 773 | + "source": [ |
| 774 | + "#| hide\n", |
| 775 | + "test_eq(td.is_dir_empty(), True)\n", |
| 776 | + "(td/'.temp').write_text('Hello, world!')\n", |
| 777 | + "test_eq(d.is_dir_empty(), False)" |
| 778 | + ] |
| 779 | + }, |
| 780 | + { |
| 781 | + "cell_type": "code", |
| 782 | + "execution_count": null, |
| 783 | + "id": "e54db8a2", |
| 784 | + "metadata": {}, |
| 785 | + "outputs": [], |
| 786 | + "source": [ |
| 787 | + "#| hide\n", |
| 788 | + "temp_dir.cleanup()" |
| 789 | + ] |
| 790 | + }, |
742 | 791 | { |
743 | 792 | "cell_type": "code", |
744 | 793 | "execution_count": null, |
|
754 | 803 | " save_path:Path=Path(\"./download/\")): # Save path (optional)\n", |
755 | 804 | " 'Download your deployed app'\n", |
756 | 805 | " if not name: name = _get_app_name(path)\n", |
757 | | - " try: save_path.mkdir(exist_ok=False)\n", |
758 | | - " except: print(f\"ERROR: Save path ({save_path}) already exists. Please rename or delete this folder to avoid accidental overwrites.\")\n", |
759 | | - " else:\n", |
760 | | - " if r := _mk_auth_req(_endpoint(rt=f'/download?name={name}')):\n", |
761 | | - " file_bytes = io.BytesIO(r.content)\n", |
762 | | - " with tarfile.open(fileobj=file_bytes, mode=\"r:gz\") as tar: tar.extractall(path=save_path)\n", |
763 | | - " print(f\"Downloaded your app to: {save_path}\") " |
| 806 | + " save_path.mkdir(exist_ok=True)\n", |
| 807 | + " if not save_path._is_dir_empty(): return print(f'ERROR: Save path ({save_path}) is not empty.')\n", |
| 808 | + " if r := _mk_auth_req(_endpoint(rt=f'/download?name={name}')):\n", |
| 809 | + " with tarfile.open(fileobj=io.BytesIO(r.content), mode=\"r:gz\") as tar: tar.extractall(path=save_path)\n", |
| 810 | + " print(f\"Downloaded your app to: {save_path}\") " |
764 | 811 | ] |
765 | 812 | }, |
766 | 813 | { |
|
0 commit comments