check-mirrors return-mirrorlist.conf, NONE, 1.1 return-mirrorlist.py, 1.1, 1.2
Seth Vidal (skvidal)
fedora-extras-commits at redhat.com
Mon Jul 10 21:09:25 UTC 2006
- Previous message: fedora-security/audit fc4,1.324,1.325 fc5,1.239,1.240
- Next message: rpms/wine-docs/FC-3 .cvsignore, 1.13, 1.14 sources, 1.13, 1.14 wine-docs.spec, 1.16, 1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: skvidal
Update of /cvs/fedora/check-mirrors
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv11750
Modified Files:
return-mirrorlist.py
Added Files:
return-mirrorlist.conf
Log Message:
add conf file for cgi
make cgi functional
http://server/cgi-bin/return-mirrorlist.py?repo=somename&arch=i386&country=country_code
are accepted options
--- NEW FILE return-mirrorlist.conf ---
[core-5]
path=/tmp/foopath
Index: return-mirrorlist.py
===================================================================
RCS file: /cvs/fedora/check-mirrors/return-mirrorlist.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- return-mirrorlist.py 10 Jul 2006 04:38:58 -0000 1.1
+++ return-mirrorlist.py 10 Jul 2006 21:09:22 -0000 1.2
@@ -1,12 +1,131 @@
#!/usr/bin/python -tt
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# written by seth vidal - skvidal at fedoraproject.org
-#GPL - blah
-# skvidal at fedoraproject.org
+
+# prettier errors
+print 'Content-type: text/plain'
+print
+import cgitb
+cgitb.enable()
+
+__revision__ = '$Id$'
+CONFIG = '/etc/return-mirrorlist.conf'
+VERSION = '0.1'
+
+
+import os
+import sys
+import GeoIP
+import ConfigParser
+import cgi
# - separate cgi script needed to return the proper geoip-based file for
# the requesting client's country, if it exists, otherwise return the global
# file.
-# - cgi should accept a get-variable which allows you to only output the
-# global mirrorlist - not the country-specific one and/or specify
-# a country.
+class ConfigHolder(object):
+ pass
+
+def get_config(cnf_fn):
+ conf = ConfigParser.ConfigParser()
+ conf.read(CONFIG)
+ config = ConfigHolder()
+ config.paths = {}
+
+ for section in conf.sections():
+ if conf.has_option(section, 'path'):
+ config.paths[section] = conf.get(section, 'path')
+
+ return config
+
+
+def sanity_check(config, form):
+ errors = []
+ if not form.has_key('repo') or not form['repo'].value:
+ msg = "# repository not specified"
+ errors.append(msg)
+ return errors
+
+ repo = form['repo'].value
+ if not config.paths.has_key(repo):
+ msg = "# no repository available for repo %s" % repo
+ errors.append(msg)
+ return errors
+
+ if not os.path.exists(config.paths[repo]):
+ msg = "# Path: %s for repo %s does not exist" % (config.paths[repo], repo)
+ errors.append(msg)
+ return errors
+
+ if not form.has_key('arch') or not form['arch'].value:
+ msg = "# no arch specified"
+ errors.append(msg)
+ return errors
+
+ return errors
+
+
+def main():
+ config = get_config(CONFIG)
+ form = cgi.FieldStorage()
+ errors = sanity_check(config, form)
+ if errors:
+ for error in errors:
+ print '%s' % error
+ sys.exit()
+
+ # requested repo
+ repo = form['repo'].value
+
+ # requested arch
+ arch = form['arch'].value
+
+ # path to mirrorlists
+
+ lists_path = config.paths[repo]
+
+ # get geoip resolution
+ # if country-specific file exists
+ # open and return
+ # otherwise return global
+
+
+ if not form.has_key('country'):
+ reqip = os.environ['REMOTE_ADDR']
+ gi = GeoIP.new(GeoIP.GEOIP_STANDARD)
+ country = gi.country_code_by_addr(reqip)
+ else:
+ country = form['country'].value
+
+ if not country:
+ country = 'global'
+
+ return_file = '%s/%s-%s-%s.txt' % (lists_path, repo, country, arch)
+ if not os.path.exists(return_file):
+ print '# no file found for repo = %s, country = %s, arch = %s' % (repo, country,arch)
+
+ 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()
+
+
+if __name__ == '__main__':
+ main()
+
- Previous message: fedora-security/audit fc4,1.324,1.325 fc5,1.239,1.240
- Next message: rpms/wine-docs/FC-3 .cvsignore, 1.13, 1.14 sources, 1.13, 1.14 wine-docs.spec, 1.16, 1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the scm-commits
mailing list