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:
parent
3aa1373758
commit
85de0ec1ca
4 changed files with 172 additions and 50 deletions
69
p4GetCLDetails.py
Normal file
69
p4GetCLDetails.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf8 -*-
|
||||
# author: Brian Ernst
|
||||
|
||||
"""
|
||||
This is an experimental script for fetching changelist details based on changelists
|
||||
containing a specific search string of your choice.
|
||||
A future version of this script would generate unified diffs of the desired output.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
# TODO: Use p4helper instead of adding this.
|
||||
# TODO: Consider updating helpers to use json output instead of parsing the standard p4 output
|
||||
def get_proc_output( args, path = None ):
|
||||
proc = subprocess.Popen( args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=path, encoding='utf-8' )
|
||||
proc.wait()
|
||||
data, err = proc.communicate()
|
||||
return data
|
||||
|
||||
def output_cls_with_string(directory = None):
|
||||
"""
|
||||
Args:
|
||||
directory (str): This is the directory to limit scanning to, can be None.
|
||||
MUST use Perforce syntax; if you want to scan directory must end with `/...` to search path
|
||||
"""
|
||||
|
||||
cwd = os.getcwd()
|
||||
|
||||
command = f"p4 -ztag -Mj changes -L {directory if directory else ''}"
|
||||
|
||||
wrote = False
|
||||
count = 0
|
||||
# TODO: update to arg output
|
||||
with open(pathlib.Path(cwd) / 'TODO_UPDATE_SCRIPT.log', 'w') as log_file:
|
||||
|
||||
proc = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd )
|
||||
for line in proc.stdout:
|
||||
j = json.loads(line)
|
||||
|
||||
# TODO: update to arg search term
|
||||
if 'TODO_SEARCH_TERMS' not in j['desc'].lower():
|
||||
continue
|
||||
|
||||
print(j)
|
||||
print()
|
||||
|
||||
command2 = f"p4 describe {j['change']}"
|
||||
output = get_proc_output(command2, path=cwd)
|
||||
if wrote:
|
||||
log_file.write('\n\n\n\n')
|
||||
wrote = True
|
||||
log_file.write(output)
|
||||
log_file.flush()
|
||||
|
||||
count += 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('-d', '--directory')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
output_cls_with_string(directory = args.directory)
|
||||
Loading…
Add table
Add a link
Reference in a new issue