Created
June 25, 2024 14:31
-
-
Save dyeo/470d4ed8349471fca4e06c9db19402f7 to your computer and use it in GitHub Desktop.
p4 - perforce utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from P4 import P4, P4Exception | |
def edit_files(p4, cl): | |
files = p4.run("describe", "-s", cl)[0]["depotFile"] | |
change = {"Change": "new", "Description": f"Checked out from CL{cl}"} | |
p4.input = change | |
change_output = p4.run("change", "-i") | |
new_cl = change_output[0].split()[1] | |
for file in files: | |
print(file) | |
p4.run("edit", "-c", new_cl, file) | |
def main(): | |
parser = argparse.ArgumentParser(prog="p5", description="p4 utility") | |
subparsers = parser.add_subparsers(dest="command") | |
checkout_parser = subparsers.add_parser("edit") | |
checkout_parser.add_argument("cl", help="Changelist to edit files from") | |
args = parser.parse_args() | |
p4 = P4() | |
try: | |
p4.connect() | |
if args.command == "edit": | |
print(f"Edit {args.cl}") | |
edit_files(p4, args.cl) | |
except P4Exception: | |
for e in p4.errors: | |
print(e) | |
finally: | |
p4.disconnect() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment