|
190 | 190 | " while time()-start < timeout:\n", |
191 | 191 | " resp = client.get(url).raise_for_status()\n", |
192 | 192 | " if resp.text.strip(): return dict(client.cookies)\n", |
193 | | - " sleep(interval)\n", |
194 | | - " " |
| 193 | + " sleep(interval)" |
195 | 194 | ] |
196 | 195 | }, |
197 | 196 | { |
|
213 | 212 | " return print(PLASH_CONFIG_HOME.read_json().get(\"session_\", \"\"), end='')\n", |
214 | 213 | " if token:\n", |
215 | 214 | " PLASH_CONFIG_HOME.write_text(json.dumps({\"session_\": token.strip()}))\n", |
216 | | - " return print(f\"Token saved to {PLASH_CONFIG_HOME}\")\n", |
| 215 | + " return f\"Token saved to {PLASH_CONFIG_HOME}\"\n", |
217 | 216 | " paircode = secrets.token_urlsafe(16)\n", |
218 | 217 | " login_url = httpx.get(_endpoint(rt=f\"/cli_login?paircode={paircode}\")).text\n", |
219 | 218 | " print(f\"Opening browser for authentication:\\n{login_url}\\n\")\n", |
|
222 | 221 | " cookies = _poll_cookies(paircode)\n", |
223 | 222 | " if cookies:\n", |
224 | 223 | " PLASH_CONFIG_HOME.write_text(json.dumps(cookies))\n", |
225 | | - " print(f\"Authentication successful! Config saved to {PLASH_CONFIG_HOME}\")\n", |
226 | | - " else: print(\"Authentication timed out.\")" |
| 224 | + " return f\"Authentication successful! Config saved to {PLASH_CONFIG_HOME}\"\n", |
| 225 | + " else: return \"Authentication timed out.\"" |
227 | 226 | ] |
228 | 227 | }, |
229 | 228 | { |
|
284 | 283 | "#| export\n", |
285 | 284 | "pat = r'(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\\s(?P<content>(^#(| .*)$\\s)+)^# ///$'\n", |
286 | 285 | "\n", |
287 | | - "def _deps(script: bytes | str) -> dict | None:\n", |
| 286 | + "def _deps(script: bytes | str):\n", |
288 | 287 | " 'Get the dependencies from the script. From: https://peps.python.org/pep-0723/'\n", |
289 | 288 | " name = 'script'\n", |
290 | 289 | " if isinstance(script, bytes): script = script.decode('utf-8')\n", |
|
418 | 417 | " r = _mk_auth_req(_endpoint(rt=\"/upload\"), \"post\", files={'file': tarz},\n", |
419 | 418 | " data={'name': name, 'force_data': force_data})\n", |
420 | 419 | " if r:\n", |
421 | | - " print('✅ Upload complete! Your app is currently being built.')\n", |
422 | | - " print(f'It will be live at {name if \".\" in name else _endpoint(sub=name)}')" |
| 420 | + " return ('✅ Upload complete! Your app is currently being built.\\n' +\n", |
| 421 | + " f'It will be live at {name if \".\" in name else _endpoint(sub=name)}')\n", |
| 422 | + " else: return 'Unknown failure'" |
423 | 423 | ] |
424 | 424 | }, |
425 | 425 | { |
|
794 | 794 | " text = ''\n", |
795 | 795 | " while True:\n", |
796 | 796 | " try:\n", |
797 | | - " if r := _mk_auth_req(_endpoint(rt=f\"/logs?name={name}&mode={mode}\")):\n", |
798 | | - " print(r.text[len(text):], end='') # Only print updates\n", |
799 | | - " text = r.text\n", |
800 | | - " if mode == 'build' and 'Build End Time:' in r.text: break\n", |
801 | | - " sleep(1)\n", |
| 797 | + " r = _mk_auth_req(_endpoint(rt=f\"/logs?name={name}&mode={mode}\"))\n", |
| 798 | + " print(r.text[len(text):], end='') # Only print updates\n", |
| 799 | + " text = r.text\n", |
| 800 | + " if mode == 'build' and 'Build End Time:' in r.text: return\n", |
| 801 | + " sleep(1)\n", |
802 | 802 | " except KeyboardInterrupt: return \"\\nExiting\"\n", |
803 | 803 | " if r := _mk_auth_req(_endpoint(rt=f\"/logs?name={name}&mode={mode}\")): return r.text" |
804 | 804 | ] |
|
925 | 925 | " save_path.mkdir(exist_ok=True)\n", |
926 | 926 | " if not save_path._is_dir_empty(): return print(f'ERROR: Save path ({save_path}) is not empty.')\n", |
927 | 927 | " if r := _mk_auth_req(_endpoint(rt=f'/download?name={name}')):\n", |
928 | | - " with tarfile.open(fileobj=io.BytesIO(r.content), mode=\"r:gz\") as tar: tar.extractall(path=save_path)\n", |
| 928 | + " with tarfile.open(fileobj=io.BytesIO(r.content), mode=\"r:gz\") as tar: tar.extractall(path=save_path, filter='data')\n", |
929 | 929 | " print(f\"Downloaded your app to: {save_path}\") " |
930 | 930 | ] |
931 | 931 | }, |
|
1000 | 1000 | " if r:\n", |
1001 | 1001 | " apps = r.json()\n", |
1002 | 1002 | " if not apps: return \"You don't have any deployed Plash apps.\"\n", |
1003 | | - " if verbose: [print(f\"{a['running']} {a['name']}\") for a in apps]\n", |
1004 | | - " else: [print(a['name']) for a in apps]" |
| 1003 | + " if verbose: return [(f\"{a['running']} {a['name']}\") for a in apps]\n", |
| 1004 | + " else: return [(a['name']) for a in apps]" |
1005 | 1005 | ] |
1006 | 1006 | }, |
1007 | 1007 | { |
|
1066 | 1066 | ] |
1067 | 1067 | } |
1068 | 1068 | ], |
1069 | | - "metadata": { |
1070 | | - "solveit_dialog_mode": "learning", |
1071 | | - "solveit_ver": 2 |
1072 | | - }, |
| 1069 | + "metadata": {}, |
1073 | 1070 | "nbformat": 4, |
1074 | 1071 | "nbformat_minor": 5 |
1075 | 1072 | } |
0 commit comments