[p4] Python scripting with Perforce

Darin Petty Darin.Petty at Configuresoft.com
Wed Oct 5 14:05:27 PDT 2005

I didn't see another answer.
Marshal.load only reads the first record.
I use a home-made function to read the whole collection:

def RunMarshal(command):
    # run marshal.load in a loop
	while 1:
    except EOFError:
    return results

I hope that solves your problem with the counters.


Paul said:
	Hey all:
	I've just started playing with scripting some Perforce triggers
and such 
	with Python. I went with Python because of Perforce's -G option,
	after playing with it for an afternoon, I'm slightly
	I'm curious if anyone knows:
	1. Why the marshal module was used, as opposed to the
pickle/shelve modules?
	I'm having problems fetching data from a Perforce ("p4
	invocation. In further reading the Python documentation, I saw:
	[marshal] is not a general ``persistence'' module. For general 
	persistence and transfer of Python objects through RPC calls,
see the 
	modules pickle and shelve. The marshal module exists mainly to
	reading and writing the ``pseudo-compiled'' code for Python
modules of 
	.pyc files. Therefore, the Python maintainers reserve the right
	modify the marshal format in backward incompatible ways should
the need 
	arise. If you're serializing and de-serializing Python objects,
use the 
	pickle module instead.
	I'm wondering if my problems (namely that my counters invocation
	returns the first counter) are related to possible changes that
may have 
	been made to the Python interpreter in 2.3.x that are
incompatible with 
	the binary marshaled data Perforce is dumping.
	2. Am I the only one that finds the structure of the marshaled
	somewhat... confusing?
	The sample trigger on page 102 of 2005.1 Administrator's Guide
gives a 
	"p4 group -o" invocation with marshaled output; the output dumps
keys of 
	UserNNN, where N is 0 to the total number of users you have.
	requires matching against the keys (see if it matches '^User',
as the 
	sample does) to see if it's a key you want the value to. Why
wasn't this 
	just put into an array of hashes called "Users"? Is this a
limitation of 
	the marshal module, or?
	I'd be curious to see the reasoning used here; I'm building some

	infrastructure that I rallied behind using Python for, most
	because of this convenient marshaling capability, but my initial

	impression of this feature is that it's somewhat incomplete and
	in terms of specific Python interpreter version dependencies,
and if 
	that's actually a case, that makes this a no-go; I can't have 
	infrastructure breaking when we do a x.y.z+1 Python interpreter
	Is this accurate or am I doing something wrong?
	Build/Release Engineer
	preed at vmware.com
	(650) 475-5248

Darin Petty
Project Manager, Support & Tools

Configuresoft, Inc.
Security. Compliance. Control.
Office: 719.687-2676
mailto:Darin.Petty at Configuresoft.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.perforce.com/pipermail/perforce-user/attachments/20051005/8ed233d9/attachment-0006.html>

More information about the perforce-user mailing list