1

I want to create a new branch in perforce with python and I used: self._p4.run("branch", name) but, every time I used that, automatically it's open an editor to insert the mapping.

My question is if it's any way to create a new branch without open the editor and in the perfect world I can pass the mapping as a list of strings.

Thank you!

2 Answers 2

2

In P4Python you can edit specs via the fetch_spec and save_spec methods:

https://www.perforce.com/perforce/r14.2/manuals/p4script/python.p4.html#python.p4.fetch_spectype https://www.perforce.com/perforce/r14.2/manuals/p4script/python.p4.html#python.p4.save_spectype

which are equivalent to p4 <spec> -o and p4 <spec> -i, but they convert the spec to and from a dictionary to make it easier to manipulate. Creating a branch spec would look something like:

branch = p4.fetch_branch(name)
branch["View"] = ["//depot/main/... //depot/"+name+"/..."]
p4.save_branch(branch)
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to control the mapping yourself, and avoid the editor, you just need to use p4 branch -i and pass the already-filled-in form yourself.

So, for example:

  1. p4 branch -o name > branchData.txt to generate the branch form into a temporary file
  2. modify branchData.txt as you desire (e.g., to change the mappings to your desired set)
  3. p4 branch -i < branchData.txt to load your branch data into the Perforce server and create the new branch spec in the server.

Of course, you don't really need to do step (1) if your program already knows how it wants to set up the branch spec data. Just put your desired branch spec data into a file and run p4 branch -i with stdin redirected to that file. Or, even, you can just feed your form data directly from your program into p4 branch -i since it's just reading from stdin.

2 Comments

It's working, but at the end I am gonna use the Sam solution with fetch and save_branch. Thank you for your help Bryan
Glad you got it figured out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.