Check
Check

Reputation: 130

How to create a branch in perforce with python and avoid the editor passing the mapping by argument

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!

Upvotes: 1

Views: 685

Answers (2)

Samwise
Samwise

Reputation: 71424

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)

Upvotes: 2

Bryan Pendleton
Bryan Pendleton

Reputation: 16339

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.

Upvotes: 1

Related Questions