install .rpm or .msi file through python script

0 votes

I'm a newbie to python. I have a python script to download a rpm file from S3 bucket.

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")

I want to add a script in the same file to install the downloaded rpm file or msi package for windows. I tried searching online but didn't get any information. Would appreciate if anyone provide some pointers.

Thanks!

Sep 18, 2018 in AWS by bug_seeker
• 15,350 points
271 views

1 answer to this question.

0 votes

You have to call system command - 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")
answered Sep 18, 2018 by Priyaj
• 56,520 points

Related Questions In AWS

0 votes
1 answer

How can I install curl 7.34 or later on Amazon linux old instance

got answer from this link https://www.digitalocean.com/community/questions/how-to-upgrade-curl-in-centos6 worked for ...READ MORE

answered Aug 9, 2018 in AWS by Priyaj
• 56,520 points
759 views
0 votes
1 answer

Boto3 - python script to view all directories and files

There are no folders, only S3 object ...READ MORE

answered Sep 14, 2018 in AWS by Priyaj
• 56,520 points
8,229 views
0 votes
1 answer
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,560 points
295 views
0 votes
1 answer
+1 vote
2 answers

How do I run python script on aws EC2 instance(ubuntu)?

I believe that you are using the ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,260 points
1,941 views
+1 vote
2 answers

How to install Python MySQLdb module using pip?

It's easy to do, but hard to ...READ MORE

answered Aug 1, 2018 in AWS by Priyaj
• 56,520 points
1,158 views