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.
69 lines
No EOL
2 KiB
Python
69 lines
No EOL
2 KiB
Python
#!/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) |