Adding some try/except statements and some changes on output layout.
This commit is contained in:
parent
20bf0ce068
commit
776f8cc7c6
1 changed files with 68 additions and 53 deletions
121
scripts/checkMirrors/checkMirrors.py
Normal file → Executable file
121
scripts/checkMirrors/checkMirrors.py
Normal file → Executable file
|
@ -1,53 +1,68 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
#
|
#
|
||||||
# [Author]
|
# [Author]
|
||||||
# Davi Vercillo C. Garcia (davivercillo@gmail.com)
|
# Davi Vercillo C. Garcia (davivercillo@gmail.com)
|
||||||
#
|
#
|
||||||
# [License]
|
# [License]
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
if len(sys.argv) < 4:
|
if len(sys.argv) < 4:
|
||||||
print "Use: ./mirror_checker.py updates 11 x86_64"
|
print "Use: ./mirror_checker.py updates 11 x86_64"
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
main_mirror = "http://download.fedora.redhat.com/pub/fedora/linux/%s/%s/%s/repodata/"
|
main_mirror = "http://download.fedora.redhat.com/pub/fedora/linux/%s/%s/%s/repodata/"
|
||||||
mirror_list = "http://mirrors.fedoraproject.org/mirrorlist?path=/pub/fedora/linux/%s/%s/%s/repodata"
|
mirror_list = "http://mirrors.fedoraproject.org/mirrorlist?path=/pub/fedora/linux/%s/%s/%s/repodata&country=global"
|
||||||
xml_file = "repomd.xml"
|
xml_file = "repomd.xml"
|
||||||
|
|
||||||
directory = sys.argv[1]
|
directory = sys.argv[1]
|
||||||
version = sys.argv[2]
|
version = sys.argv[2]
|
||||||
architecture = sys.argv[3]
|
architecture = sys.argv[3]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mirrors = urllib.urlopen(mirror_list % (directory, version, architecture)).read().split("\n")
|
mirrors = urllib.urlopen(mirror_list % (directory, version, architecture)).read().split("\n")
|
||||||
repomd = urllib.urlopen(main_mirror % (directory, version, architecture) + xml_file).read()
|
repomd = urllib.urlopen(main_mirror % (directory, version, architecture) + xml_file).read()
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print "[ERROR] Cannot get info from URLs. Please check the parameters."
|
print "[ERROR] Cannot get info from URLs. Please check the parameters."
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
print "\nUsing:", main_mirror % (directory, version, architecture), "\n"
|
results = [[],[]]
|
||||||
for url in mirrors:
|
for url in mirrors:
|
||||||
if "#" in url or not url:
|
if "#" in url or not url:
|
||||||
continue
|
continue
|
||||||
if urllib.urlopen(url + xml_file).read() == repomd:
|
print ".",
|
||||||
print url, "[Good]"
|
sys.stdout.flush()
|
||||||
else:
|
try:
|
||||||
print url, "[Bad]"
|
if urllib.urlopen(url + xml_file).read() == repomd:
|
||||||
print "\n"
|
results[0].append(url)
|
||||||
sys.exit(0)
|
else:
|
||||||
|
results[1].append(url)
|
||||||
|
except Exception, err:
|
||||||
|
print "[ERROR]", url
|
||||||
|
|
||||||
|
print "\nUsing:", main_mirror % (directory, version, architecture), "\n"
|
||||||
|
print "[Good]"
|
||||||
|
for url in results[0]:
|
||||||
|
print url
|
||||||
|
print "\n[Bad]"
|
||||||
|
for url in results[1]:
|
||||||
|
print url
|
||||||
|
|
||||||
|
print "\n"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue