check-mirrors return-mirrorlist.py,1.7,1.8

Seth Vidal (skvidal) fedora-extras-commits at redhat.com
Tue Jul 18 02:57:12 UTC 2006


Author: skvidal

Update of /cvs/fedora/check-mirrors
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv25356

Modified Files:
	return-mirrorlist.py 
Log Message:

allow country to be a list of country codes



Index: return-mirrorlist.py
===================================================================
RCS file: /cvs/fedora/check-mirrors/return-mirrorlist.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- return-mirrorlist.py	17 Jul 2006 21:34:01 -0000	1.7
+++ return-mirrorlist.py	18 Jul 2006 02:57:09 -0000	1.8
@@ -16,7 +16,6 @@
 
 
 # TODO:
-# - accept a list of country codes as &country
 # - maybe a macro of certain country codes expand out to multiple countries
 #      note: - maintaining the abovelist will become a royal bitch.
 
@@ -52,7 +51,7 @@
     
 def get_config(cnf_fn):
     conf = ConfigParser.ConfigParser()
-    conf.read(CONFIG)
+    conf.read(cnf_fn)
     config = ConfigHolder()
     config.paths = {}
     config.prefixes = {}
@@ -120,45 +119,55 @@
     # otherwise return global
     
     country_specified = False
+    country_list = []
     if not form.has_key('country'):
         reqip = os.environ['REMOTE_ADDR']
         gi = GeoIP.new(GeoIP.GEOIP_STANDARD)
-        country = gi.country_code_by_addr(reqip)
+        caller_country = gi.country_code_by_addr(reqip)
+        if caller_country:
+            country_list = [caller_country]
     else:
         country_specified = True
-        country = form['country'].value
+        l = form['country'].value
+        country_list = l.split(',')
 
-    if not country:
-        country = 'global'
+    if not country_list:
+        country_list = ['global']
 
-    return_file = '%s/%s-%s-%s.txt' % (lists_path, prefix, country, arch)
-    rp = os.path.realpath(return_file)
 
     # if they didn't specify a country name in the variables and their country code
     # doesn't exist - then give them global
-    
-    if country != 'global'and not country_specified and not os.path.exists(rp):
-        country = 'global'
-        return_file = '%s/%s-%s-%s.txt' % (lists_path, prefix, country, arch)
+    if not country_specified:
+        # we're only dealing with a single country, then.
+        return_file = '%s/%s-%s-%s.txt' % (lists_path, prefix, country_list[0], arch)
         rp = os.path.realpath(return_file)
+    
+        if country_list[0] != 'global' and not os.path.exists(rp):
+            country_list = ['global']
 
-    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)
-        sys.exit()
 
 
-    if not rp.startswith(lists_path):
-        print "# someone is messing with the path via get-string %s not inside %s" % (rp, lists_path)
-        sys.exit()
+    for country in country_list:
+        return_file = '%s/%s-%s-%s.txt' % (lists_path, prefix, country, arch)
+        rp = os.path.realpath(return_file)
+
+        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
+        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()
+        fo.close()
     
 
 if __name__ == '__main__':




More information about the fedora-extras-commits mailing list