1. import platform
  2. import os
  3. import sys
  4. class RuntimeInfo:
  5. def __init__(self):
  6. self.os_name = platform.system()
  7. self.os_version = platform.version()
  8. self.cpu_count = os.cpu_count()
  9. self.memory_info = platform.memory_info()
  10. self.python_version = sys.version
  11. self.disk_space_gb = self.get_disk_space_gb() # Get disk space in GB
  12. def get_disk_space_gb(self):
  13. """
  14. Retrieves disk space in GB.
  15. """
  16. import shutil
  17. total, used, free = shutil.disk_usage("/") # Use "/" for root partition
  18. return total // (2**30) # Convert bytes to GB
  19. def check_limits(self):
  20. """
  21. Checks runtime environment against hard-coded limits.
  22. """
  23. limits = {
  24. "os_name": ["Windows", "Linux", "Darwin"], # Supported OS
  25. "os_version_min": "10",
  26. "cpu_count_min": 2,
  27. "disk_space_min": 20, # Minimum disk space in GB
  28. }
  29. for key, value in limits.items():
  30. if key == "os_name":
  31. if self.os_name not in value:
  32. print(f"Warning: OS '{self.os_name}' not supported.")
  33. elif key == "os_version_min":
  34. try:
  35. version_number = int(self.os_version.split('.')[0])
  36. if version_number < int(value):
  37. print(f"Warning: OS version {self.os_version} below minimum {value}.")
  38. except ValueError:
  39. print(f"Warning: Could not determine OS version from '{self.os_version}'.")
  40. elif key == "cpu_count_min":
  41. if self.cpu_count < int(value):
  42. print(f"Warning: CPU count {self.cpu_count} below minimum {value}.")
  43. elif key == "disk_space_min":
  44. if self.disk_space_gb < int(value):
  45. print(f"Warning: Disk space {self.disk_space_gb:.1f} GB below minimum {value} GB.")
  46. def print_runtime_info(self):
  47. """
  48. Prints runtime environment information.
  49. """
  50. print("Runtime Environment Information:")
  51. print(f" OS: {self.os_name}")
  52. print(f" OS Version: {self.os_version}")
  53. print(f" CPU Count: {self.cpu_count}")
  54. print(f" Memory: {self.memory_info}")
  55. print(f" Python Version: {self.python_version}")
  56. print(f" Disk Space: {self.disk_space_gb:.1f} GB")
  57. if __name__ == "__main__":
  58. runtime_info = RuntimeInfo()
  59. runtime_info.print_runtime_info()
  60. runtime_info.check_limits()

Add your comment