Source code for cgl.plugins.perforce.alchemy
import logging
import subprocess
from typing import Tuple
[docs]
def check_connection() -> Tuple[bool, str]:
"""
checks if perforce is installed and configured
"""
try:
subprocess.run("p4", check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except FileNotFoundError:
return False, "Perforce is not installed"
try:
completed_process = subprocess.run("p4 info", check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
except subprocess.CalledProcessError as e:
return False, "Perforce is installed but not configured"
output_ = completed_process.stdout.split("\n")
logging.info(output_)
return True, output_[0]
if __name__ == "__main__":
is_connected, message = check_connection()
if is_connected:
print(f"Perforce is installed and configured: {message}")
else:
print(f"Error: {message}")