Metadata-Version: 2.5
Name: tcp-serial
Version: 0.3.1
Summary: CLI tools for interacting with ser2net serial consoles over TCP
Author-email: XieChangqing <dian@duck.com>
License: MIT License
        
        Copyright (c) 2026 changqing_xie
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Environment :: Console
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# tcp-serial

CLI tools for interacting with ser2net serial consoles over TCP on Linux, macOS, and Windows.

## Features

- Monitor a serial console continuously, with optional timestamps, logging, and reconnects.
- Execute shell or U-Boot commands and return plain-text or JSON output.
- Send control keys and other byte sequences.
- Interrupt autoboot and enter a U-Boot prompt.
- Open an interactive terminal with escape-key handling.
- Connect directly to ser2net or through an SSH local-forwarding tunnel.
- Run on Linux, macOS, and Windows with no runtime Python dependencies.

## Requirements

- Python 3.9 or newer.
- A reachable ser2net TCP endpoint.
- The `ssh` executable when using SSH forwarding.

Current Windows releases normally include OpenSSH Client. If `ssh` is unavailable, install the OpenSSH Client optional feature. For interactive use on Windows, use Windows Terminal, PowerShell, or Command Prompt.

## Installation

Run without installing:

```bash
uvx tcp-serial --help
```

Install with `uv`:

```bash
uv tool install tcp-serial
```

Or install with `pipx`/`pip`:

```bash
pipx install tcp-serial
# or
python -m pip install tcp-serial
```

## Usage

```
tcp-serial COMMAND [options]
```

### Commands

#### `monitor` — continuously monitor serial console output

```bash
tcp-serial monitor --port 3000
tcp-serial monitor --ssh user@host --remote-port 3000 --reconnect --timestamp
```

#### `exec` — execute a command over the serial console

```bash
tcp-serial exec --port 3000 -- ls /tmp
tcp-serial exec --port 3000 --json -- uname -a
tcp-serial exec --ssh user@host --remote-port 3000 -- cat /proc/version
```

#### `send-key` — send key sequences

```bash
tcp-serial send-key --port 3000 --key $'\x03'
tcp-serial send-key --port 3000 --key $'\r' --key $'\n' --interval 0.1
```

PowerShell example for sending `Ctrl+C`:

```powershell
tcp-serial send-key --port 3000 --key "$([char]3)"
```

#### `uboot` — interrupt autoboot and enter the U-Boot prompt

```bash
tcp-serial uboot --port 3000 --from-shell
tcp-serial uboot --port 3000 --manual-reboot
```

#### `interact` — open an interactive serial terminal

```bash
tcp-serial interact --port 3000
tcp-serial interact --ssh user@host --remote-port 3000 --log-file console.log
```

The default escape prefix is `Ctrl+A`. Press `Ctrl+A`, then `Ctrl+X` to exit, or press `Ctrl+A` twice to send a literal `Ctrl+A`.

Run command-specific help to see all available options:

```bash
tcp-serial COMMAND --help
```

## Connection Options

All commands share these connection options:

| Option | Description |
|--------|-------------|
| `--host` | ser2net host (default: `127.0.0.1`) |
| `--port` | ser2net TCP port |
| `--ssh` | SSH target for remote forwarding, e.g. `user@host` |
| `--remote-port` | ser2net TCP port on the SSH server |
| `--remote-host` | ser2net host as seen from the SSH server |
| `--ssh-arg` | extra argument passed to ssh (repeatable) |
| `--encoding` | text encoding (default: `utf-8`) |
| `--mode` | console mode: `shell` or `uboot` |
| `--connect-timeout` | max seconds to wait for connection (default: `5.0`) |

Use exactly one of `--port` (direct) or `--ssh` + `--remote-port` (SSH forwarding).

## Environment Variables

| Variable | Description |
|----------|-------------|
| `TCP_SERIAL_SSH` | SSH target; overridden by `--ssh` |
| `TCP_SERIAL_REMOTE_PORT` | Remote port; overridden by `--remote-port` |

## Building from Source

Install `uv`, clone the repository, and run:

```bash
./build.sh
```

The script runs the test suite, removes old files from `dist/`, builds both distributions, and validates their metadata:

```text
dist/tcp_serial-0.3.0.tar.gz
dist/tcp_serial-0.3.0-py3-none-any.whl
```

Before publishing, verify installation in a clean environment:

```bash
uv run --isolated --with dist/tcp_serial-0.3.0-py3-none-any.whl tcp-serial --help
```

## License

MIT
