使用python skript进行Git拉

时间:2018-08-28 08:07:45

标签: python git raspberry-pi gitlab ssh-keys

我正在尝试为远程树莓派编写更新功能,而我不会直接访问它。意思是我有一个网络服务器,可以通过发布请求发送命令。当我想更改树莓的代码时,我向他发送“更新”作为树莓的询问,要求“ nextInstruction”。

现在我希望树莓进行git clean和git pull。

我的常规通讯。py:

#code beforhand
elif (decodedresponse['responseInfo']['data'][1]['command'] == "update"):

        subprocess.call("./update.sh", shell=True)

        #update
        #os.system('sudo git clean -f -d')
        #os.system('git pull')
        #os.system('sudo reboot')
#code after

我的update.sh:

#!/bin/bash

sudo git clean -f -d
git pull
sudo reboot

问题: 如果我直接执行update.sh,它将起作用。当我运行python脚本时,显然他没有在〜/ .ssh中获得ssh键。

如何将ssh密钥附加到我的python脚本?我什至了解问题吗? 是否有更简单的解决方案来登录我的远程gitlab存储库?

1 个答案:

答案 0 :(得分:0)

我宁愿让我的bash脚本运行python脚本,并通过python退出代码确定操作/作业。这是一个例子。

注意:调用mFrame.acquireCameraImage()可能需要输入密码,除非您编辑sudoers文件(sudo)并为此运行脚本和git的用户添加例外

p.py (确保py文件具有shebang(第一行)和visudo属性设置。

chmod +x

update.sh

#!/usr/bin/python
# instead of  >>subprocess.call("./update.sh", shell=True)
exit(100)