Source code for cgl.plugins.perforce.utils.git_operations

import glob
import logging
import os
import stat

from cgl.core.utils.general import cgl_execute


[docs] def check_out_depot(company, project, depot_name, location_name=None): """ Creates a local copy of the depot and opens it in Unreal Args: project: depot_name: Returns: """ from cgl.plugins.unreal.utils.setup import ( location_setup, open_project_in_unreal, ) from cgl.plugins.perforce.utils.depot import get_world_from_depot_name from cgl.plugins.unreal.utils.perforce import setup_location_in_perforce print(company, project, depot_name) if not location_name: world = get_world_from_depot_name(project=project, depot_name=depot_name) print("Location: ", world) else: world = location_name if not setup_location_in_perforce( company=company, project=project, world=world, depot_name=depot_name ): logging.error("Failed to setup location in perforce") return False location_setup(company=company, project=project, world=world) open_project_in_unreal(company=company, project=project, world=world) return True
[docs] def commit(company, project, world): """ Commit all files within specified folder Args: project: Name of project world: Name of world folder: Absolute file path to folder to be committed """ from cgl.plugins.perforce.utils.workspace import get_workspace_path from cgl.core.utils.general import cgl_execute workspace_path = get_workspace_path(company, project, world) result = cgl_execute( command="p4 reconcile -ead", working_directory=workspace_path, return_output=True, print_output=True, ) return result
[docs] def pull(company, project, location, check_for_writable=True): """ Pulls world from depot Args: compay: Name of company world belongs to project: Naame of project world belongs to location: Name of world to be pulled Returns: True if pull is successful, False if pull is not successful """ from cgl.plugins.perforce.utils.depot import get_depot_name, depot_exists depot_name = get_depot_name(company, project, location) if depot_exists(company, project, location): depot_path = "//{}/...".format(depot_name) logging.info("PULLING DEPOT: {}".format(depot_name)) command = "p4 sync {}".format(depot_path) return_ = cgl_execute(command=command, return_output=True, print_output=True) lines = return_["stdout"].splitlines() if check_for_writable: for line in lines: if "Can't clobber writable file" in line: ask_for_overwrite(project, location) return False return True else: logging.error(f"Depot {depot_name} Not Found") return False
[docs] def push(): """ Push changes from workspace to its corresponding depot with default Push Message Returns: True if push is successful, False if push is not successful """ command = 'p4 submit -d "Automatic Commit Message from Alchemy"' # os.system(command) result = cgl_execute(command) return result
[docs] def revert(project, world): from cgl.plugins.perforce.utils.depot import get_depot_name depot_name = get_depot_name(project=project, world=world) command = f"p4 revert //{depot_name}/..." cgl_execute(command=command, print_output=True)
[docs] def ask_for_overwrite(company, project, world): """ Args: company: project: world: Returns: """ from cgl.ui.widgets.dialog import InputDialog dialog_ = InputDialog( title="Overwrite File", message="Some local files have unsaved changes. Do you wish to continue pulling?", buttons=["Yes", "No"], ) dialog_.exec() if dialog_.button == "Yes": make_project_files_read_only(project, world) pull(company, project, world, check_for_writable=False)
[docs] def make_project_files_read_only(project, world): from cgl.plugins.perforce.utils.workspace import get_workspace_path from cgl.plugins.unreal.utils.uproject import get_uproject_path workspace_path = get_workspace_path(project, world) uproject_file = get_uproject_path(project, world) content_path = os.path.join(workspace_path, "Content") config_path = os.path.join(workspace_path, "Config") for file in glob.glob(content_path + "/**/*", recursive=True): os.chmod(file, stat.S_IREAD) for file in glob.glob(config_path + "/**/*", recursive=True): os.chmod(file, stat.S_IREAD) os.chmod(uproject_file, stat.S_IREAD)