如何解析 Perforce “pickle”二进制输出?

发布于 2024-08-11 06:41:00 字数 322 浏览 7 评论 0原文

Perforce 命令行有一个特殊的开关 -G,据说可以使用 python 的“pickle”序列化格式使其输出成为机器可读的。一般来说,情况确实如此吗?

例如,考虑 p4 -G diff -duw3的输出<文件2> <文件3>。据我所知,输出是一个序列:pickle、raw diff、pickle、raw diff、pickle、raw diff。它似乎不包含任何可以使人可靠地定位 pickle/diff 边界的分隔符。

我是否遗漏了某些内容,或者这种“机器可读”格式实际上不是机器可读的?如何在其输出中找到泡菜和原始差异之间的界限?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动听の歌 2024-08-18 06:41:00

p4 -G 以编组格式(未腌制)输出其数据。

但你是对的 - p4 -G diff -duw3 也不会取消marshal,所以我猜那里有问题。

不过,p4 -G opening 解组效果很好。然而任何类型的 diff 都会失败。

以下是相关知识库文章: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] )

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] )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文