开发者

How to parse Perforce "pickle" binary output?

开发者 https://www.devze.com 2022-12-10 21:50 出处:网络
Perforce command line has a special switch, -G, that supposedly causes its output to be machine readable, using python\'s \"pickle\" serialization format. Is this actually so, in general?

Perforce command line has a special switch, -G, that supposedly causes its output to be machine readable, using python's "pickle" serialization format. Is this actually so, in general?

For example, consider the output of p4 -G diff -duw3 <file1> <file2> <file3>. The output, as far as I can tell, is a sequence of: pickle, raw diff, pickle, raw diff, pickle, raw diff. It does not appear开发者_开发技巧 to contain any delimiters that would enable one to reliably locate the pickle/diff boundaries.

Am I missing something or is this "machine-readable" format not actually machine-readable? How can I find the boundaries between pickles and raw diffs in its output?


p4 -G outputs its data in marshaled form not pickled.

But you are right - p4 -G diff -duw3 also won't unmarshal, so I guess there is a problem there.

p4 -G opened unmarshals fine though. However any kind of diff fails.

Here is a relevant knowledge base article: http://kb.perforce.com/ToolsScripts/PerforceUtilities/UsingP4G

#!/usr/bin/env python
import marshal
import subprocess

# proc = subprocess.Popen(["p4","-G","diff","-duw3","configure.ac","Makefile.am"],stdout=subprocess.PIPE)
proc = subprocess.Popen(["p4","-G","diff"],stdout=subprocess.PIPE)
# proc = subprocess.Popen(["p4","-G","opened"],stdout=subprocess.PIPE)
pipe = proc.stdout
output = []
try:
    while 1:
        record = marshal.load(pipe)
        output.append(record)
except EOFError:
    pass
pipe.close()
proc.wait()

# print list of dictionary records
c = 0
for dict in output:
    c = c + 1
    print "\n--%d--" % c
    for key in dict.keys():
        print "%s: %s" % ( key, dict[key] )
0

精彩评论

暂无评论...
验证码 换一张
取 消