1 message in com.perforce.perforce-user[p4] p4api adventures with RedHat 6.2...
FromSent OnAttachments
cima...@taylors.org10 Dec 2000 10:06 
Subject:[p4] p4api adventures with RedHat 6.2 and the hidden -G option
From:cima...@taylors.org (cima@taylors.org)
Date:12/10/2000 10:06:13 AM
List:com.perforce.perforce-user

| Instead we're using the -G option to the p4 command (see "p4 help | undoc") which causes Perforce to do input and output as a list of | marshalled Python dictionaries.

Ah ha! That must be what clientuserpy.o is for. This looks very promising. Gareth, thank you very much for pointing this out!

I still haven't gotten the api to build on my machine so in the meantime I just coded up a class which implements functions like the following:

def p4files(self): """ Return list of files from files command """ return self.popen(P4_PATH + ' files ' + self.filename, 'r').readlines()

def parsefiles(self, line): """ Parse output of p4 files command """ start = '/' + self.ArchiveDir + '/' end = '#' p1 = string.find(line, start) p2 = string.find(line, end) return line[p1+len(start):p2]

def p4filelog(self, opts=""): """ Return list of lines from p4 filelog command """ return self.popen(P4_PATH + ' filelog ' + opts + ' ' + self.filename,
'r').readlines()

def parsefilelog(self, line): """ Parse the output of p4 filelog command """ m = re.match("\.\.\. #(?P<num>\S+) \S+ \S+ \S+ \S+ (?P<date>\d+/\d+/\d+)
\S+ \S+ \S+ '(?P<who>[^' ]+)", line) if m: return m.group('num', 'date', 'who') return None

Now that you've referred me to the -G option, I can probably get rid of my parsing code and use marshal.load() as you have in your p4.py replicator.

Although the overhead of spawning processes is probably not a serious problem on the platforms I use most often, I would still rather use the "supported" api than a secret option to p4 but from a practical point of view the os.popen method will work.

This looks like an ideal project for the public perforce depot - I'm sure there must be a few dozen people who have implemented this lind of python wrapper. When I'm done with what I'm doing I'll put my code there for people to use if they want.

Cim