I added dry-run to p4SyncMissing some time ago; I don't remember if I finished it, but I don't have time to test, and don't want to lose it, so submitting it. Wow is this a rough testing branch or what.

Add TODOs.
Fix some directory bugs when running scripts with a cwd not in the p4 workspace. TODO: make sure all scripts and options work when run outside p4 workspace.
If user isn't logged in you can get weird errors later on in the pipeline, and without extra manually added prints, you wouldn't know you just need to log in. Added TODO: about detecting if we need to do a p4 login.
Some of my stuff seems to have stopped working with later version of Python/p4, had to update string to byte string; no doubt more of these issues hiding.
Haven't tested on python 2 in a while, do not consider these working there.
This commit is contained in:
Brian Ernst 2026-03-05 15:27:28 -08:00
parent 3aa1373758
commit 85de0ec1ca
4 changed files with 172 additions and 50 deletions

View file

@ -146,6 +146,9 @@ def fail_if_no_p4():
print( 'Perforce Command-line Client(p4) is required for this script.' )
sys.exit( 1 )
# TODO: Do an operation that would trigger login error like P4PASSWD missing.
# See if we need to trigger a p4 login or can avoid it.
# Keep these in mind if you have issues:
# https://stackoverflow.com/questions/16557908/getting-output-of-a-process-at-runtime
# https://stackoverflow.com/questions/4417546/constantly-print-subprocess-output-while-process-is-running
@ -174,13 +177,13 @@ def get_client_set( path ):
proc.wait( )
for line in proc.stderr:
if "no such file" in line:
if b"no such file" in line:
continue
raise Exception(line)
return files
def get_client_root( ):
def get_p4_info(info_tag):
"""
:rtype : string
@ -191,16 +194,23 @@ def get_client_root( ):
for line in proc.stdout:
line = get_str_from_process_stdout( line )
clientFile_tag = "Client root: "
if not line.startswith( clientFile_tag ):
if not line.startswith( info_tag ):
continue
local_path = normpath( line[ len( clientFile_tag ) : ].strip( ) )
local_path = normpath( line[ len( info_tag ) : ].strip( ) )
if local_path == "null":
local_path = None
return local_path
return None
def get_client_stream( ):
result = get_p4_info("Client stream: ")
return result
def get_client_root( ):
result = get_p4_info("Client root: ")
return result
class P4Workspace:
"""
Use this class when working in a workspace.
@ -218,7 +228,7 @@ class P4Workspace:
def __enter__( self ):
# get user
#print("\nChecking p4 info...")
result = get_p4_py_results('info')
result = get_p4_py_results('info', self.directory)
if len(result) == 0 or b'userName' not in result[0].keys():
print("Can't find perforce info, is it even setup? Possibly can't connect to server.")
sys.exit(1)
@ -248,7 +258,7 @@ class P4Workspace:
oldworkspace_name = parse_info_from_command('p4 info', 'Client name: ')
# get user workspaces
results = get_p4_py_results('workspaces -u ' + username)
results = get_p4_py_results('workspaces -u ' + username, self.directory)
workspaces = []
for r in results:
whost = get_str_from_process_stdout(r[b'Host'])