Commit dec4787e authored by vertighel's avatar vertighel
Browse files

PIPython and github VmbPy now in pyproject

parent 4a4a4b0b
Loading
Loading
Loading
Loading
Loading
+86 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
System utility to check for Vimba X installation and trigger the install script.
"""

# System modules
import os
import sys
import subprocess
from pathlib import Path

def is_vimbax_installed():
    """
    Check if Vimba X drivers are already present on the system.
    
    Returns
    -------
    bool
        True if Vimba X is detected, False otherwise.
    """

    # 1. Check for the standard Vimba X environment variable
    if "VIMBA_X_HOME" in os.environ:
        return True

    # 2. Check for common installation directories in /opt
    opt_path = Path("/opt")
    if opt_path.exists():
        vimbax_dirs = list(opt_path.glob("VimbaX_*"))
        if vimbax_dirs:
            return True

    # 3. Check if the shared library is registered in the system
    try:
        # ldconfig -p lists all known libraries
        res = subprocess.run(["ldconfig", "-p"], capture_output=True, text=True)
        if "VmbC" in res.stdout:
            return True
    except Exception:
        pass

    return False


def main():
    """
    Main logic for noctua-install-system command.
    """

    print("--- Noctua System Dependency Check ---")

    if is_vimbax_installed():
        print("[OK] Vimba X drivers detected.")
        print("[OK] No further action is required. Everything looks good.")
        sys.exit(0)

    print("[INFO] Vimba X drivers not found.")
    print("[INFO] Preparing to launch the system installation script...")

    # Locate the bash script relative to this file
    # Path: noctua/utils/install_vimba_x.py -> noctua/utils -> noctua -> root
    root_dir = Path(__file__).parent.parent.parent
    script_path = root_dir / "scripts" / "install_vimba_x.sh"

    if not script_path.exists():
        print(f"[ERROR] System installation script not found at: {script_path}")
        print("Please ensure you are running this from the project directory.")
        sys.exit(1)

    print(f"[INFO] Executing: sudo {script_path}")
    
    try:
        # Execute the bash script with sudo
        subprocess.run(["sudo", str(script_path)], check=True)
    except subprocess.CalledProcessError:
        print("\n[ERROR] The installation process was aborted or failed.")
        sys.exit(1)
    except KeyboardInterrupt:
        print("\n[INFO] Installation cancelled by user.")
        sys.exit(1)


if __name__ == "__main__":
    main()
+4 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "noctua"
version = "0.2.0"
version = "0.3.0"
authors = [
    { name="Davide Ricci", email="davide.ricci@inaf.it" },
]
@@ -39,6 +39,8 @@ dependencies = [
    "uvicorn",
    "httpx", # Suggested for async calls to devices

    "PIPython", # for PI - Physik Instrumente controllers
    "vmbpy @ git+https://github.com/alliedvision/VmbPy.git",
]

[project.urls]
@@ -48,6 +50,7 @@ dependencies = [
[project.scripts]
noctua-sequencer = "noctua.sequencer:cli"
noctua-api = "noctua.app:run"
noctua-install-system = "noctua.utils.install_vimba_x:main"

[tool.setuptools.packages.find]
where = ["."]  # list of folders that contain the packages (["."] by default)
+67 −0
Original line number Diff line number Diff line
#!/bin/bash

# Configuration
VIMBA_URL="https://www.alliedvision.com/en/support/software-downloads/vimba-x-sdk/"
VIMBA_TGZ="VimbaX_Setup-Linux-x86_64.tar.gz"

# Check if script is running as root
if [ "$EUID" -ne 0 ]; then 
  echo "ERROR: Please run this script with sudo:"
  echo "sudo ./scripts/install_vimbax.sh"
  exit 1
fi

echo "--- VIMBA X SYSTEM INSTALLATION ---"

# 1. Check for the installation file
if [ ! -f "$VIMBA_TGZ" ]; then
    echo "-----------------------------------------------------------------------"
    echo "FILE NOT FOUND: $VIMBA_TGZ"
    echo ""
    echo "Due to Allied Vision website restrictions, you must download the"
    echo "package manually before running this script."
    echo ""
    echo "1. Visit: $VIMBA_URL"
    echo "2. Click on 'Vimba X SDK for Linux - 64 bit'"
    echo "3. Accept the terms and download the .tar.gz file"
    echo "4. Copy the downloaded file to this directory: $(pwd)"
    echo "5. Run this script again."
    echo "-----------------------------------------------------------------------"
    exit 1
fi

echo "File found! Proceeding with extraction..."

# 2. Extract to a temporary directory
TMP_DIR="vimbax_install_tmp"
mkdir -p "$TMP_DIR"
tar -xf "$VIMBA_TGZ" -C "$TMP_DIR" --strip-components=1

# 3. Execute the official Allied Vision install script
cd "$TMP_DIR"
echo "Running Allied Vision install.sh..."
./install.sh

# 4. Configure udev rules (allows camera access without root)
echo "Reloading udev rules..."
udevadm control --reload-rules && udevadm trigger

# 5. Update system dynamic library links
echo "Updating ldconfig..."
ldconfig

# 6. Cleanup
cd ..
rm -rf "$TMP_DIR"

echo ""
echo "--- INSTALLATION COMPLETE ---"
echo "NOTE: To enable VmbPy, make sure to add this line to your ~/.bashrc:"
echo "export VIMBA_X_HOME=/opt/VimbaX_2023-4" # Note: check the actual folder in /opt
echo ""
echo "WARNING: A REBOOT IS REQUIRED to apply the GigE network driver changes."
read -p "Would you like to reboot now? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
    reboot
fi