#!/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)