check-mirrors check-mirrors.conf, 1.8, 1.9 check-mirrors.py, 1.22, 1.23 return-mirrorlist.py, 1.8, 1.9
Michael Patrick McGrath (mmcgrath)
fedora-extras-commits at redhat.com
Wed Aug 2 22:03:49 UTC 2006
Author: mmcgrath
Update of /cvs/fedora/check-mirrors
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv11268
Modified Files:
check-mirrors.conf check-mirrors.py return-mirrorlist.py
Log Message:
More db support, web now pulls from db
Index: check-mirrors.conf
===================================================================
RCS file: /cvs/fedora/check-mirrors/check-mirrors.conf,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- check-mirrors.conf 2 Aug 2006 16:12:06 -0000 1.8
+++ check-mirrors.conf 2 Aug 2006 22:03:46 -0000 1.9
@@ -1,10 +1,9 @@
[global]
-db=/mirrors.db
-file_prefix = global
+db=/tmp/mirrors.db
[core-5]
inputfile = http://fedora.redhat.com/download/mirrors/fedora-core-5
-outputpath = /var/www/mirrors
+outputpath = /tmp/var/www/mirrors
archlist = i386, x86_64, ppc
timeout = 10
canonical = http://redhat.download.fedoraproject.org/pub/fedora/linux/core/5/$ARCH/os/
@@ -12,7 +11,7 @@
[extras-5]
inputfile = http://fedora.redhat.com/download/mirrors/fedora-extras-5
-outputpath = /var/www/mirrors
+outputpath = /tmp/var/www/mirrors
archlist = i386, x86_64, ppc
timeout = 10
canonical = http://redhat.download.fedoraproject.org/pub/fedora/linux/extras/5/$ARCH/
@@ -20,7 +19,7 @@
[updates-released-5]
inputfile = http://fedora.redhat.com/download/mirrors/fedora-core-5
-outputpath = /var/www/mirrors
+outputpath = /tmp/var/www/mirrors
archlist = i386, x86_64, ppc
timeout = 10
canonical = http://redhat.download.fedoraproject.org/pub/fedora/linux/core/updates/5/$ARCH/
@@ -28,7 +27,7 @@
[updates-testing-5]
inputfile = http://fedora.redhat.com/download/mirrors/updates-testing-fc5
-outputpath = /var/www/mirrors
+outputpath = /tmp/var/www/mirrors
archlist = i386, x86_64, ppc
timeout = 10
canonical = http://redhat.download.fedoraproject.org/pub/fedora/linux/core/updates/testing/5/$ARCH/
@@ -36,7 +35,7 @@
[rawhide]
inputfile = http://fedora.redhat.com/download/mirrors/fedora-core-rawhide
-outputpath = /var/www/mirrors
+outputpath = /tmp/var/www/mirrors
archlist = i386, x86_64, ppc
timeout = 10
canonical = http://download.fedoraproject.org/pub/fedora/linux/core/development/$ARCH/os/
@@ -44,7 +43,7 @@
[extras-devel]
inputfile = http://fedora.redhat.com/download/mirrors/fedora-extras-devel
-outputpath = /var/www/mirrors
+outputpath = /tmp/var/www/mirrors
archlist = i386, x86_64, ppc
timeout = 10
canonical = http://download.fedoraproject.org/pub/fedora/linux/extras/development/$ARCH/
Index: check-mirrors.py
===================================================================
RCS file: /cvs/fedora/check-mirrors/check-mirrors.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- check-mirrors.py 2 Aug 2006 16:12:41 -0000 1.22
+++ check-mirrors.py 2 Aug 2006 22:03:46 -0000 1.23
@@ -27,7 +27,7 @@
# - pull mirrors from the database instead of fedora.redhat.com ?
-debug = True
+debug = False
__revision__ = '$Id$'
CONFIG = '/etc/check-mirrors.conf'
Index: return-mirrorlist.py
===================================================================
RCS file: /cvs/fedora/check-mirrors/return-mirrorlist.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- return-mirrorlist.py 18 Jul 2006 02:57:09 -0000 1.8
+++ return-mirrorlist.py 2 Aug 2006 22:03:46 -0000 1.9
@@ -41,6 +41,7 @@
import GeoIP
import ConfigParser
import cgi
+import sqlite
# - separate cgi script needed to return the proper geoip-based file for
# the requesting client's country, if it exists, otherwise return the global
@@ -48,25 +49,79 @@
class ConfigHolder(object):
pass
+
+class RepoDB:
+ def __init__(self, db):
+ (self.dbconn, self.dbcursor) = self.connect(db)
+ return None
+
+ def connect(self, db):
+ try:
+ conn = sqlite.connect(db)
+ cursor = conn.cursor()
+ except sqlite.Error, errmsg:
+ errorprint('Failed to connect to database: %s' % db)
+ errorprint('Err: %s ' % errmsg)
+ return None, None
+ else:
+ return(conn, cursor)
+ def getMirrors(self, repo, arch, country):
+
+ if country.lower() == 'global':
+ countrysql = ""
+ else:
+ countrysql = "and country='%s'" % country
+ try:
+ self.dbcursor.execute('SELECT url FROM mirrors where repo="%s" and arch="%s" %s;' % (repo, arch, countrysql))
+ except sqlite.Error, err:
+ print "%s" % err
+
+ dataList = []
+ for row in self.dbcursor.fetchall():
+ dataList.append([ item for item in row])
+ return dataList
+
+ def printMirrors(self, repo, arch, country):
+ rows = self.getMirrors(repo, arch, country)
+ results = 0
+ for row in rows:
+ for field in row:
+ print "%s" % field
+ results = results + 1
+
+ if results == 0:
+ print "# No results found for country: %s\n# Defaulting to global" % country
+ self.printMirrors(repo, arch, 'global')
+ else:
+ return True
+
+
+ def close(self):
+ self.dbconn.cursor()
+ self.dbconn.close()
+
def get_config(cnf_fn):
conf = ConfigParser.ConfigParser()
conf.read(cnf_fn)
config = ConfigHolder()
config.paths = {}
config.prefixes = {}
+ config.dbpath = ""
for section in conf.sections():
+ if section.lower() == 'global':
+ config.dbpath = conf.get(section, 'db')
+ continue
if conf.has_option(section, 'outputpath'):
config.paths[section] = conf.get(section, 'outputpath')
if conf.has_option(section, 'file_prefix'):
config.prefixes[section] = conf.get(section, 'file_prefix')
else:
config.prefixes[section] = '%s' % section
-
+
return config
-
-
+
def sanity_check(config, form):
errors = []
if not form.has_key('repo') or not form['repo'].value:
@@ -89,7 +144,6 @@
msg = "# no arch specified"
errors.append(msg)
return errors
-
return errors
@@ -97,6 +151,8 @@
config = get_config(CONFIG)
form = cgi.FieldStorage()
errors = sanity_check(config, form)
+ DB = RepoDB(config.dbpath)
+
if errors:
for error in errors:
print '%s' % error
@@ -134,7 +190,6 @@
if not country_list:
country_list = ['global']
-
# if they didn't specify a country name in the variables and their country code
# doesn't exist - then give them global
if not country_specified:
@@ -145,8 +200,6 @@
if country_list[0] != 'global' and not os.path.exists(rp):
country_list = ['global']
-
-
for country in country_list:
return_file = '%s/%s-%s-%s.txt' % (lists_path, prefix, country, arch)
rp = os.path.realpath(return_file)
@@ -154,21 +207,23 @@
if not rp.startswith(lists_path):
print "# someone is messing with the path via get-string %s not inside %s" % (rp, lists_path)
continue
-
+
if not os.path.exists(return_file):
print '# no file found for repo = %s, country = %s, arch = %s' % (repo, country, arch)
print '# filename was: %s' % os.path.basename(return_file)
continue
-
print '# repo = %s country = %s arch = %s ' % (repo, country, arch)
- fo = open(return_file, 'r')
- for line in fo.readlines():
- line = line.replace('\n', '')
- print line
-
- fo.close()
+ DB.printMirrors(repo, arch, country)
+
+# fo = open(return_file, 'r')
+# for line in fo.readlines():
+# line = line.replace('\n', '')
+# print line
+#
+# fo.close()
+ DB.close()
if __name__ == '__main__':
main()
More information about the fedora-extras-commits
mailing list