Please index this so when I run into this again, I can find it.
So I just spent the past 6 hours debugging an esoteric problem with using the p4 command through python, taking advantage of the “-G” option to marshal the data directly back into python objects. p4 is the command line client for perforce. Pretty good client, even if perforce annoys me half the time. It has a really nice feature in that you can ask for the results of commands to be handed back as marshaled objects for either python or ruby using the “-G” or “-R” option respectively. Fantastic for accessing perforce through a script. I’ve been using python…
It turns out that if you invoke the
p4 -G where command with a path, you can get back somewhat inconsistent results when that path is a directory and not a file. For example, “p4 -G where //depot/dir/project” is how I’ve been using the command for quite a while. Worked pretty darn well. I iterate through the results, and get the dictionary of the paths – use them in a script. What I found is that there are some directory structures which this doesn’t work – but using “p4 -G //depot/dir/project/…” does work. In my simple case, I get an EOFException when trying to unmarshal the data from one of these special directories. I’m not even sure what makes it a special directory – just that there are some that we’ve found that don’t work.
For the curious, here’s my quick test code:
import os import marshal from subprocess import * trouble_path = '//depot_name/Projects/Shared' print "TROUBLE PATH" cmd = "p4 -G where %s" % (trouble_path,) print "invoking cmd %s" % cmd f = os.popen(cmd) print f d = marshal.load(f) print d f.close() OK_path = '//depot_name/Projects/Shared/...' print "OK PATH" cmd = "p4 -G where %s" % (OK_path,) print "invoking cmd %s" % cmd f = os.popen(cmd) print f d = marshal.load(f) print d
And yes, I know about Robert Cowham’s really nice libraries. I won’t even explain why I can’t use them because I’ll just start foaming at the mouth and using obscenities. I’m working with perforce through my own scripts, using the -G option, and for the most part its working very nicely. This was just one of those places where it wasn’t. I take the results of the p4 where command and strip the “/…” or “…” off the end to get what I want for desktop client paths, and I’m good to go.