Skip to content

Instantly share code, notes, and snippets.

@JacobCallahan
Created December 6, 2017 18:42
Show Gist options
  • Save JacobCallahan/7606df381f7049481fd0f7777e74ef22 to your computer and use it in GitHub Desktop.
Save JacobCallahan/7606df381f7049481fd0f7777e74ef22 to your computer and use it in GitHub Desktop.
"""Purpose of the script goes here.
Example usage for the script goes here.
python this_script.py <args>
"""
import os
import sys
import urllib2
import wget
from BeautifulSoup import BeautifulSoup
flag = flag1 = flag2 = 0
signature = sys.argv[3]
DIR = '~/packages'
os.mkdir(DIR)
def get_packages_name(html):
soup = BeautifulSoup(html)
anchors = soup.findAll('a')
links = [a['href'] for a in anchors]
return filter(lambda k: 'rpm' in k, links)
def get_package(package_name):
wget.download(sys.argv[1] + package_name, DIR)
list1 = get_packages_name(urllib2.urlopen(sys.argv[1]).read()).sort()
list2 = get_packages_name(urllib2.urlopen(sys.argv[2]).read()).sort()
print("There are {0} packages in build1 and {1} packages in build2.".format(
len(list1), len(list2)
))
for pkg1, pkg2 in zip(list1, list2):
if pkg1 == pkg2:
flag = flag+1
else:
print(
"The version of package {0} from build1 is not similar "
"to version of package {1} from build2.".format(pkg1, pkg2)
)
if flag == len(list1) - 1:
print("Versions in both builds are same")
else:
print("{0} packages version found mismatched!".format(len(list1)) - flag))
for pkg in list1:
get_package(pkg)
if 'NOT OK' not in os.popen('rpm -K ~/packages/'.format(pkg)).read():
flag1 = flag1 + 1
if signature in os.popen(
'rpm -qpi ~/packages/{0}| grep "Signature" '.format(pkg)).read():
flag2 = flag2 + 1
else:
print('signature not matched for {0}'.format(pkg))
else:
print('{0} package is not signed'.format(pkg))
if flag1 == len(list1):
print "All packages are signed!"
else:
print('{} packages are not signed!!'.format(len(list1) - flag1))
if flag2 == len(list1):
print("Signature matched for all packages!!")
else:
print('Signature for {0} packages not matched!!'.format(len(list1) - flag2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment