process_utils.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """
  2. Process Utilities
  3. Utilities for detecting and interacting with running processes/applications.
  4. """
  5. import psutil
  6. from typing import List, Dict
  7. def is_process_running(process_name: str) -> bool:
  8. """
  9. Check if a process is currently running.
  10. Args:
  11. process_name: Name of the process (e.g., 'EOS Utility.exe')
  12. Returns:
  13. bool: True if process is running, False otherwise
  14. """
  15. try:
  16. for proc in psutil.process_iter(['name']):
  17. try:
  18. if proc.info['name'] and process_name.lower() in proc.info['name'].lower():
  19. return True
  20. except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
  21. pass
  22. except Exception as e:
  23. print(f"Error checking process {process_name}: {e}")
  24. return False
  25. def check_camera_applications() -> Dict[str, bool]:
  26. """
  27. Check if required camera applications are running.
  28. Returns:
  29. Dict[str, bool]: Dictionary mapping application name to running status
  30. """
  31. # Common process names for camera applications
  32. camera_apps = {
  33. 'EOS Utility': ['EOS Utility.exe', 'EOSUtility.exe', 'eu.exe'],
  34. '2nd Look': ['2ndLook.exe', 'secondlook.exe', '2nd Look.exe'],
  35. 'AnalyzIR': ['AnalyzIR.exe', 'analyzir.exe']
  36. }
  37. results = {}
  38. for app_name, process_names in camera_apps.items():
  39. running = False
  40. for proc_name in process_names:
  41. if is_process_running(proc_name):
  42. running = True
  43. break
  44. results[app_name] = running
  45. return results
  46. def get_running_camera_apps() -> List[str]:
  47. """
  48. Get list of camera applications that are currently running.
  49. Returns:
  50. List[str]: List of running camera application names
  51. """
  52. status = check_camera_applications()
  53. return [app for app, running in status.items() if running]
  54. def get_missing_camera_apps() -> List[str]:
  55. """
  56. Get list of camera applications that are not running.
  57. Returns:
  58. List[str]: List of camera application names that are not running
  59. """
  60. status = check_camera_applications()
  61. return [app for app, running in status.items() if not running]