[untitled]1 points·by telui·7 mesi fa·0 comments1 commentsPost comment[–]telui·7 mesi fareply*`system` – Tiny OS Utils for Isolated Cmds & Info*```python import shlex, os, uuid, psutil, requests from ipaddress import ip_address from typing import Optional ```*Globals* - `id = uuid.uuid4()` → session UUID - `uid = str(id)` → temp dir `./{uid}/` - `parts = psutil.disk_partitions()` - `usage = psutil.disk_usage("./")`---### `run(cmd: str = "True")` Executes `cmd` in isolated `./{uid}/cache.sh`, auto-cleans. Uses `shlex.quote()` → injection-safe. ```python run("ls -la") ```---### `getoutput(label: str = "True") -> str` Runs `label`, captures *stdout+stderr* → `output.txt`, returns stripped string. ```python getoutput("uname -a") # "Linux …" ```---### `py(cmd: str)` Writes `cmd` to `cache.py`, runs via `python`. Prefer native Python. ```python py("print(42)") ```---### `install(manager: str, pkg: str)` `sudo {manager} install {pkg}` – *needs passwordless sudo*. ```python install("apt", "vim") ```---### `ip() -> ipaddress.ip_address` Public IP via `https://ifconfig.me`. ```python ip() # IPv4Address('203.0.113.42') ```---*Lifecycle* 1. `mkdir ./uid/` 2. Write → exec → capture (if any) 3. `rm -rf ./uid/`*Deps* `pip install psutil requests`> *UUID-isolated, zero persistent state, sudo-aware.* Use responsibly. > by eotter-beep – Python 3.6+
```python import shlex, os, uuid, psutil, requests from ipaddress import ip_address from typing import Optional ```
*Globals* - `id = uuid.uuid4()` → session UUID - `uid = str(id)` → temp dir `./{uid}/` - `parts = psutil.disk_partitions()` - `usage = psutil.disk_usage("./")`
---
### `run(cmd: str = "True")` Executes `cmd` in isolated `./{uid}/cache.sh`, auto-cleans. Uses `shlex.quote()` → injection-safe. ```python run("ls -la") ```
---
### `getoutput(label: str = "True") -> str` Runs `label`, captures *stdout+stderr* → `output.txt`, returns stripped string. ```python getoutput("uname -a") # "Linux …" ```
---
### `py(cmd: str)` Writes `cmd` to `cache.py`, runs via `python`. Prefer native Python. ```python py("print(42)") ```
---
### `install(manager: str, pkg: str)` `sudo {manager} install {pkg}` – *needs passwordless sudo*. ```python install("apt", "vim") ```
---
### `ip() -> ipaddress.ip_address` Public IP via `https://ifconfig.me`. ```python ip() # IPv4Address('203.0.113.42') ```
---
*Lifecycle* 1. `mkdir ./uid/` 2. Write → exec → capture (if any) 3. `rm -rf ./uid/`
*Deps* `pip install psutil requests`
> *UUID-isolated, zero persistent state, sudo-aware.* Use responsibly. > by eotter-beep – Python 3.6+