some updates
This commit is contained in:
44
callbacks/app.py
Normal file
44
callbacks/app.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any
|
||||
|
||||
async def run_app(args: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Запускает приложение или ярлык по указанному пути.
|
||||
|
||||
Args:
|
||||
args: Dictionary containing 'url' (string) of the website to open.
|
||||
|
||||
Returns:
|
||||
Dictionary with status message and input arguments.
|
||||
|
||||
Raises:
|
||||
OSError: If opening the website fails.
|
||||
"""
|
||||
try:
|
||||
path = args.get("path")
|
||||
# Проверка существования файла
|
||||
if not Path(path).exists():
|
||||
raise OSError(f"Файл не найден: {path}")
|
||||
|
||||
# Проверка расширения файла
|
||||
if not path.lower().endswith(('.exe', '.lnk', '.bat')):
|
||||
raise OSError(f"Файл {path} может не быть исполняемым файлом или ярлыком")
|
||||
|
||||
# Попытка запуска приложения
|
||||
subprocess.run(['start', '', path], shell=True, check=True)
|
||||
return {
|
||||
"message": f"App {path} opened successfully",
|
||||
"args": args
|
||||
}
|
||||
|
||||
except FileNotFoundError as e:
|
||||
raise OSError(f"Файл не найден или путь некорректен: {str(e)}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise OSError(f"Ошибка при запуске приложения: {str(e)}")
|
||||
except PermissionError as e:
|
||||
raise OSError(f"Недостаточно прав для запуска: {str(e)}")
|
||||
except OSError as e:
|
||||
raise OSError(f"Ошибка операционной системы при запуске: {str(e)}")
|
||||
except Exception as e:
|
||||
raise OSError(f"Непредвиденная ошибка: {str(e)}")
|
||||
Reference in New Issue
Block a user