Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import requests
- import re
- import subprocess
- repos = dict()
- repos['rpmforge'] = 'http://mirror1.hs-esslingen.de/repoforge/redhat/el6/en/x86_64/rpmforge/RPMS/'
- repos['bareos'] = 'http://download.bareos.org/bareos/release/15.2/CentOS_6/x86_64/'
- repos['epel'] = 'http://fedora-mirror01.rbc.ru/pub/epel/6/x86_64/' #http://mirror.yandex.ru/epel/6Server/x86_64/
- repos['extras'] = 'http://mirror.centos.org/centos/6.7/extras/x86_64/Packages/'
- repos['ius'] = 'https://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/'
- repos['base'] = 'http://mirror.centos.org/centos/6.7/os/x86_64/Packages/'
- repos['updates'] = 'http://mirror.centos.org/centos/6.7/updates/x86_64/Packages/'
- repos['mono'] = 'http://download.opensuse.org/repositories/Mono:/EL6/RHEL6/x86_64/'
- repos['nginx'] = 'http://nginx.org/packages/centos/6/x86_64/RPMS/'
- repos['percona'] = 'http://repo.percona.com/release/6Server/RPMS/x86_64/'
- repos['percona-release-noarch'] = 'http://repo.percona.com/release/6Server/RPMS/noarch/'
- repos['rpmforge'] = 'http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/'
- rpm_list_path = '/home/dna/all_rpms.txt'
- local_repo_path = '/home/dna/rpms/'
- notfound_rpm_list = '/home/dna/nf_rpms.txt'
- rpm_list = []
- def run_command(cmd):
- result = {}
- raw_result = subprocess.Popen(cmd.split(' '),
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- stdin=subprocess.PIPE).communicate()
- result['stdout'] = (raw_result[0].decode('UTF-8')).rstrip('\n')
- return result
- rpm_list_file = open(rpm_list_path, "r")
- stats = dict()
- stats['Founded'] = 0
- stats['Not found'] = 0
- stats['All'] = 0
- stats['Missed'] = 0
- for line in rpm_list_file:
- rpm_list.append(line.rstrip())
- stats['All'] = stats['All'] + 1
- for rpm_file in rpm_list:
- #gathering info from yum
- command = "/usr/bin/yum info " + rpm_file
- raw_package_info = run_command(command)
- package_info = (raw_package_info['stdout']).split("\n")
- reponames = re.compile("^\S\+*")
- iparams = dict()
- for line in package_info:
- if not (('Loaded plugins' in line) \
- or ('Loading mirror speeds from cached hostfile' in line) \
- or ('Installed Packages' in line) \
- or (not reponames.match(line))):
- key, value = line.split(':', 1)
- key = key.strip()
- value = value.strip()
- iparams[key] = value
- try:
- #search package in repo
- print("Search package " + rpm_file + " in " + iparams['From repo'])
- repo = iparams['From repo']
- repo_url = repos[repo]
- rpm_url = repo_url + rpm_file + '.rpm'
- try:
- ret_code = requests.head(rpm_url).status_code
- if ret_code == 200:
- stats['Founded'] = stats['Founded'] + 1
- elif ret_code == 404:
- stats['Not found'] = 0
- print(rpm_url + " not found!")
- with open(notfound_rpm_list, "a") as nf_rpms_file:
- nf_rpms_file.write(rpm_file)
- nf_rpms_file.close()
- except Exception as error:
- print(error)
- except:
- print(rpm_file + " is missed!")
- continue
- stats['Missed'] = stats['All'] - stats['Founded'] - stats['Not found']
- print('Founded:' + str(stats['Founded']))
- print('Not found:' + str(stats['Not found']))
- print('Missed' + str(stats['Missed']))
- print('All:' + str(stats['All']))
- rpm_list_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement