Git 拉取 python 脚本
Git pull using python skript
我正在尝试为我不会直接访问的远程树莓派编写更新函数。这意味着我有一个通过 post 请求发送命令的网络服务器。当我想更改树莓的代码时,我将 "update" 作为树莓询问 "nextInstruction".
的响应发送给他
现在我想让覆盆子 git 干净并 git 拉。
我的将军communications.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 存储库?
我宁愿让我的 bash 脚本 运行 成为 python 脚本,并由 python 的退出代码决定 action/job。这是一个例子。
注意:调用sudo
可能需要密码才能进入,除非你编辑你的sudoers文件(visudo
)并为这个用户添加一个例外运行宁脚本和 git。
p.py(确保 py 文件有 shebang(第一行)和 chmod +x
属性集。
#!/usr/bin/python
# instead of >>subprocess.call("./update.sh", shell=True)
exit(100)
update.sh
#!/usr/bin/bash
$(./p.py)
JOB=$? # get pythons exitcode here
if [ $JOB -eq 100 ]; then
echo "update"
elif [ $JOB -eq 50 ]; then
echo "delete";
else
echo "nothing"
fi
我正在尝试为我不会直接访问的远程树莓派编写更新函数。这意味着我有一个通过 post 请求发送命令的网络服务器。当我想更改树莓的代码时,我将 "update" 作为树莓询问 "nextInstruction".
的响应发送给他现在我想让覆盆子 git 干净并 git 拉。
我的将军communications.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 存储库?
我宁愿让我的 bash 脚本 运行 成为 python 脚本,并由 python 的退出代码决定 action/job。这是一个例子。
注意:调用sudo
可能需要密码才能进入,除非你编辑你的sudoers文件(visudo
)并为这个用户添加一个例外运行宁脚本和 git。
p.py(确保 py 文件有 shebang(第一行)和 chmod +x
属性集。
#!/usr/bin/python
# instead of >>subprocess.call("./update.sh", shell=True)
exit(100)
update.sh
#!/usr/bin/bash
$(./p.py)
JOB=$? # get pythons exitcode here
if [ $JOB -eq 100 ]; then
echo "update"
elif [ $JOB -eq 50 ]; then
echo "delete";
else
echo "nothing"
fi