Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create numbered changelist using P4Python?

P4.fetch_change() creates a change spec with Change equal to 'new'. I need to create a change spec with an actual number (that won't collide with any other changes). IOW, I need to be able to reserve a changelist number.

How can this be done with P4Python?

Context: My script takes in an already-existing changelist number. I need to be able to test that the script works correctly.

like image 736
Noel Yap Avatar asked May 05 '12 00:05

Noel Yap


2 Answers

P4.save_change() generates a changelist number -- that is, it creates a numbered, pending changelist. Try something like:

changespec = P4.fetch_change()
changespec[ "Description" ] = "placeholder"
P4.save_change( changespec )
like image 111
user1054341 Avatar answered Sep 30 '22 15:09

user1054341


Note that p4.fetch_change() gives you the dict of the current default changelist!

You might already have files in there! So to really create an empty one you can just pass a dict with 'Change': 'new' and a 'Description'.

I couldn't find a way to make save_change return the actual changelist integer. So one can split the result and have the nr that way:

from P4 import P4

def create_empty_changelist(desc='some description'):
    p4 = P4()
    p4.connect()
    result = p4.save_change({'Change': 'new', 'Description': desc})[0]
    return int(result.split()[1])
like image 22
ewerybody Avatar answered Sep 30 '22 15:09

ewerybody