我是python的新手。我有一个python脚本从S3存储桶下载rpm文件。
import platform
import boto3
import botocore
BUCKET_NAME = 'tempdownload'
KEY = 'temp.rpm' # packaged using golang
platformName = platform.system()
s3 = boto3.resource('s3')
print(platformName)
if platformName == 'Linux':
try:
bucket = s3.Bucket(BUCKET_NAME)
bucket.download_file(KEY, 'temp.rpm')
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
print("The object does not exist.")
else:
raise
else:
print("not valid operating system")
我想在同一个文件中添加一个脚本来安装下载的rpm文件或msi软件包。我尝试在线搜索但没有得到任何信息。如果有人提供一些指示,我将不胜感激。
谢谢!
答案 0 :(得分:1)
您可以使用rpm绑定直接从Python安装它。请参阅:https://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch16s06.html
但是,你不应该直接调用rpm,而是调用Yum或DNF或它的python绑定。
答案 1 :(得分:0)
您必须致电系统命令 - rpm -Ivh yourpackage.rpm
import subprocess
package_path = '/home/mypackage.rpm'
command = ['rpm', '-Ivh', package_path]
p = subprocess.Popen(command)
p.wait()
if p.returncode == 0:
print("OK")
else:
print("Something went wrong")