You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.8 KiB
Python
104 lines
2.8 KiB
Python
import os
|
|
from typing import Optional
|
|
|
|
import httpx
|
|
from fastapi import HTTPException, status
|
|
from sqlalchemy import Delete, Select, func
|
|
from sqlalchemy.orm import selectinload
|
|
|
|
from src.aeros_equipment.service import save_default_equipment
|
|
from src.aeros_simulation.service import save_default_simulation_node
|
|
from src.auth.service import CurrentUser
|
|
from src.config import AEROS_BASE_URL
|
|
from src.database.core import DbSession
|
|
from src.database.service import search_filter_sort_paginate
|
|
|
|
from .model import AerosProject
|
|
from .schema import AerosProjectInput
|
|
|
|
ALLOWED_EXTENSIONS = {".aro"}
|
|
MAX_FILE_SIZE = 5 * 1024 * 1024 # 5MB
|
|
client = httpx.AsyncClient(timeout=300.0)
|
|
|
|
|
|
async def import_aro_project(*, db_session: DbSession):
|
|
# file = aeros_project_in.aro_file
|
|
|
|
# file_ext = os.path.splitext(file.filename)[1].lower()
|
|
|
|
# if file_ext not in ALLOWED_EXTENSIONS:
|
|
# raise HTTPException(
|
|
# status_code=400,
|
|
# detail=f"File type not allowed. Allowed: {ALLOWED_EXTENSIONS}"
|
|
# )
|
|
|
|
# # Read and check file size
|
|
# content = await file.read()
|
|
# if len(content) > MAX_FILE_SIZE:
|
|
# raise HTTPException(
|
|
# status_code=400,
|
|
# detail="File too large. Max size: 5MB"
|
|
# )
|
|
|
|
project_name = "trialapi"
|
|
## save File to windows app
|
|
# Output is string of file path, examole
|
|
|
|
aro_path = r"C:/Users/user/Documents/Aeros/sample_project.aro"
|
|
|
|
aeros_project = AerosProject(project_name=project_name, aro_file_path=aro_path)
|
|
|
|
db_session.add(aeros_project)
|
|
await db_session.commit()
|
|
|
|
# Update path to AEROS APP
|
|
# Example BODy "C/dsad/dsad.aro"
|
|
try:
|
|
response = await client.post(
|
|
f"{AEROS_BASE_URL}/api/Project/ImportAROFile",
|
|
json=f"/",
|
|
headers={"Content-Type": "application/json"},
|
|
)
|
|
response.raise_for_status()
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e)
|
|
)
|
|
|
|
await _initialize_default_project_data(
|
|
db_session=db_session,
|
|
project_name=project_name
|
|
)
|
|
|
|
|
|
async def _initialize_default_project_data(
|
|
*,
|
|
db_session: DbSession,
|
|
project_name: str
|
|
) -> None:
|
|
"""
|
|
Initialize default equipment and simulation nodes for a project.
|
|
|
|
Args:
|
|
db_session: Database session
|
|
project_name: Name of the project to initialize
|
|
"""
|
|
try:
|
|
# Save default equipment
|
|
await save_default_equipment(
|
|
db_session=db_session,
|
|
project_name=project_name
|
|
)
|
|
|
|
# Save default simulation node
|
|
await save_default_simulation_node(
|
|
db_session=db_session,
|
|
project_name=project_name
|
|
)
|
|
|
|
await db_session.commit()
|
|
|
|
except Exception as e:
|
|
await db_session.rollback()
|
|
raise e
|