Author: poeml Date: Tue Dec 22 02:39:45 2009 New Revision: 7939 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7939&view=rev Log: mb update: - add -c option to update geographical coordinates, freshly looked up Modified: trunk/mirrordoctor/mirrordoctor.py Modified: trunk/mirrordoctor/mirrordoctor.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mirrordoctor.py?rev=7939&r1=7938&r2=7939&view=diff ============================================================================== --- trunk/mirrordoctor/mirrordoctor.py (original) +++ trunk/mirrordoctor/mirrordoctor.py Tue Dec 22 02:39:45 2009 _at_@ -357,6 +357,8 @@ help='update the network prefix') _at_cmdln.option('-a', '--asn', action='store_true', help='update the AS number') + _at_cmdln.option('-c', '--coordinates', action='store_true', + help='update the geographical coordinates') def do_update(self, subcmd, opts, *args): """${cmd_name}: update mirrors network data in the database _at_@ -373,6 +375,9 @@ from mb.asn import iplookup from mb.util import hostname_from_url from sqlobject.sqlbuilder import AND + + if not (opts.asn or opts.prefix or opts.coordinates): + sys.exit('Either -c, -a or -p must be given as option.') #r = mb.asn.iplookup(self.conn, ip) _at_@ -396,14 +401,29 @@ self.conn.Server.q.enabled)) for mirror in mirrors: - print mirror.identifier, + #print mirror.identifier, hostname = hostname_from_url(mirror.baseurl) - res = iplookup(self.conn, hostname) - if res: print res - if res and opts.prefix: - mirror.prefix = res.prefix - if res and opts.asn: - mirror.asn = res.asn + + if opts.prefix or opts.asn: + res = iplookup(self.conn, hostname) + #if res: print res + if opts.prefix and res: + if mirror.prefix != res.prefix: + print 'updating network prefix for %s (%s -> %s)' \ + % (mirror.identifier, mirror.prefix, res.prefix) + mirror.prefix = res.prefix + if opts.asn and res: + if mirror.asn != res.asn: + print 'updating autonomous system number for %s (%s -> %s)' \ + % (mirror.identifier, mirror.asn, res.asn) + mirror.asn = res.asn + + if opts.coordinates: + lat, lng = mb.geoip.lookup_coordinates(hostname) + if float(mirror.lat or 0) != lat or float(mirror.lng or 0) != lng: + print 'updating geographical coordinates for %s (%s %s -> %s %s)' \ + % (mirror.identifier, mirror.lat, mirror.lng, lat, lng) + mirror.lat, mirror.lng = lat, lng def do_test(self, subcmd, opts, identifier): _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Tue Dec 22 2009 - 01:39:46 GMT
This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT