Commit feb0f465 authored by Grant, Josh's avatar Grant, Josh
Browse files

add in [system] extra for system related command wrappers

parent 6ce87988
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
try:
    import psutil
except ImportError:
    import loguru
    loguru.logger.error("psutil not installed, please install pygarden with the 'system' extra")
+22 −0
Original line number Diff line number Diff line
import psutil


def get_used_ports():
    """
    Get the ports that are currently in use on the system.
    """
    used_ports = set()

    for conn in psutil.net_connections(kind='inet'):
        if conn.laddr:
            used_ports.add(conn.laddr.port)

    return sorted(used_ports)


if __name__ == "__main__":
    from pygarden.logz import create_logger
    l = create_logger()
    used_ports = get_used_ports()
    l.info("Used ports:")
    l.info("\n".join(map(str, used_ports)) if used_ports else "No ports in use")
+4 −0
Original line number Diff line number Diff line
@@ -63,6 +63,9 @@ cli = [
minio = [
    "minio~=7.1.0"
]
system = [
    "psutil~=6.1.1",
]
all = [
    "psycopg2-binary==2.9.9",
    "pymssql==2.2.11",
@@ -79,6 +82,7 @@ all = [
    "rich==13.7.1",
    "click==8.0.3",
    "minio~=7.1.0",
    "psutil~=6.1.1",
]
dev = [
    "ruff==0.5.4",