askrobots / dbbasic-cli
Public
Make a complete, running app (a CRM, a shop, a blog) with one command, such as dbbasic crm.
ports.py · 1.6 KB · 54 lines
| 1 | """List ports used by DBBasic services""" |
| 2 | |
| 3 | import socket |
| 4 | import typer |
| 5 | from rich.console import Console |
| 6 | from rich.table import Table |
| 7 | |
| 8 | from .config import SERVICES |
| 9 | |
| 10 | console = Console() |
| 11 | |
| 12 | def check_port(port): |
| 13 | """Check if port is in use""" |
| 14 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 15 | result = sock.connect_ex(('localhost', port)) |
| 16 | sock.close() |
| 17 | return result == 0 |
| 18 | |
| 19 | def ports(): |
| 20 | """List ports used by DBBasic services""" |
| 21 | |
| 22 | table = Table(title="DBBasic Port Usage") |
| 23 | table.add_column("Service", style="cyan") |
| 24 | table.add_column("Port", style="magenta") |
| 25 | table.add_column("Status", style="bold") |
| 26 | table.add_column("URL", style="blue") |
| 27 | |
| 28 | for svc_name, svc in SERVICES.items(): |
| 29 | port_in_use = check_port(svc['port']) |
| 30 | status = "✅ Active" if port_in_use else "⚪ Available" |
| 31 | color = "green" if port_in_use else "dim" |
| 32 | |
| 33 | table.add_row( |
| 34 | svc['name'], |
| 35 | str(svc['port']), |
| 36 | f"[{color}]{status}[/{color}]", |
| 37 | svc['url'] |
| 38 | ) |
| 39 | |
| 40 | console.print(table) |
| 41 | |
| 42 | # Check for conflicts on common ports |
| 43 | console.print("\n[bold]Checking for port conflicts...[/bold]") |
| 44 | conflicts = [] |
| 45 | |
| 46 | for port in [3000, 3001, 5000, 5001, 8000, 8001, 8080, 8888]: |
| 47 | if port not in [s['port'] for s in SERVICES.values()]: |
| 48 | if check_port(port): |
| 49 | conflicts.append(port) |
| 50 | |
| 51 | if conflicts: |
| 52 | console.print(f"[yellow]⚠️ Other services detected on ports: {', '.join(map(str, conflicts))}[/yellow]") |
| 53 | else: |
| 54 | console.print("[green]✅ No port conflicts detected[/green]") |