我用SCons作为软件构建工具。我想解开一个第三方软件。我使用UnTarBuilder来完成它,代码与给定的here相同
这是我的SConstruct文件的一部分:
def tarContentsEmitter(target, source, env):
import tarfile
sourceTar = tarfile.open(source[0].name,'r')
tarContents = sourceTar.getmembers()
tarFileContents = filter(lambda tarEntry: tarEntry.isfile(), tarContents)
newTargets = map(tarInfoToNode, tarFileContents)
sourceTar.close()
return (newTargets, source)
def tarInfoToNode(tarInfoObject):
return File(tarInfoObject.name)
def UnTar(target, source, env):
# Code to build "target" from "source" here
import tarfile
sourceTar = tarfile.open(source[0].name,'r')
sourceTar.extractall()
sourceTar.close()
return None
def UnTarString(target, source, env):
""" Information string for UnTar """
return 'Extracting %s' % os.path.basename
(str (source[0]))
unTarBuilder = Builder(action=SCons.Action.Action(UnTar, UnTarString),
src_suffix='.tar.bz2',
emitter=tarContentsEmitter)
env.append(BUILDERS = {'UnTar' : unTarBuilder})
env.UnTar(source='curl-7.37.0')
我得到以下错误:
^{pr2}$我知道UnTar希望得到target和env,但我不确定我是否遗漏了其他内容,因为它们会在上面提到的链接中更正,因为这很简单(我不是python人)
UnTar
接受3个参数,并且只传递1个(source),还必须传递“target”和“env”。 错误说明:当您创建一个类的实例时,
__init__()
会被自动调用,所以在您的例子中,只要您调用UnTar()就会得到这个错误。在不管怎样,你的代码是不完整的,“
env
”是从哪里来的?在相关问题 更多 >
编程相关推荐