[英]How can I automate rpmbuild with signing in python?
Normally you can automate answers to an interactive prompt by piping stdin: 通常,您可以通过管道输入stdin来自动完成交互式提示的答案:
import subprocess as sp
cmd = 'rpmbuild --sign --buildroot {}/BUILDROOT -bb {}'.format(TMPDIR, specfile)
p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE, stdin=sp.PIPE, universal_newline=True, shell=True)
for out in p.communicate(input='my gpg passphrase\n'):
print(out)
For whatever reason, this is not working for me. 无论出于什么原因,这都不适合我。 I've tried writing to
p.stdin
, before executing p.communicate()
, I've tried flushing the buffer, I've tried using bytes without universal_newlines=True
, I've hard coded things, etc. In all scenarios, the command is executed and hangs on: 我尝试过写入
p.stdin
,在执行p.communicate()
之前,尝试过刷新缓冲区,尝试过使用不p.communicate()
universal_newlines=True
字节,对内容进行了硬编码等。在所有情况下,该命令已执行并挂起:
Enter pass phrase:
My first hunch was that stdin
was not the correct file descriptor and that rpmbuild
was internally calling a gpg
command, and maybe my input isn't piped. 我的第一个直觉是
stdin
不是正确的文件描述符,并且rpmbuild
在内部调用了gpg
命令,也许我的输入没有通过管道传递。 But when I do p.stdin.close()
I get an OSerror
about subprocess
trying to write to the closed descriptor. 但是当我执行
p.stdin.close()
我收到有关尝试写入已关闭描述符的subprocess
OSerror
。
What is the rpmbuild command doing to stdin
that prevents me from writing to it? rpmbuild命令对
stdin
做了什么阻止我对其进行写入?
Is there a hack I can do? 我能做些骇客吗? I tried
echo "my passphrase" | rpmbuild ....
我尝试
echo "my passphrase" | rpmbuild ....
echo "my passphrase" | rpmbuild ....
as the command but that doesn't work. echo "my passphrase" | rpmbuild ....
作为命令,但是不起作用。
I know I can do something with gpg
like command and sign packages without a passphrase but I kind of want to avoid that. 我知道我可以使用
gpg
来执行某些操作,例如命令和签名包而无需输入密码,但是我有点想避免这种情况。
EDIT: 编辑:
After some more reading, I realize this is issue is common to commands that require password input, typically using a form of getpass
. 经过一番阅读之后,我意识到这是需要输入密码的命令的常见问题,通常使用
getpass
形式。
I see a solution would be to use a library like pexpect
, but I want something from the standard library. 我看到一个解决方案是使用像
pexpect
这样的库,但是我想要标准库中的东西。 I am going to keep looking, but I think maybe i can try writing to something similar /dev/tty
. 我将继续寻找,但是我想也许我可以尝试写类似
/dev/tty
东西。
rpm uses getpass(3) which reopens /dev/tty. rpm使用getpass(3)重新打开/ dev / tty。
There are 2 approaches to automating: 1) create a pseudotty 2) (linux) find the reopened file descriptor in /proc 有2种自动化方法:1)创建一个伪指令2)(linux)在/ proc中找到重新打开的文件描述符
If scripting, expect(1) has (or had) a short example with pseudotty's that can be used. 如果编写脚本,则Expect(1)包含一个(或具有一个)简短示例,其中包含可以使用的伪脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.