X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=blobdiff_plain;f=ud-xearth;h=58f8e93f8465a35511b900ea86a89b38cdfcc0d4;hp=b1c1fee9b7241476f5c70dc093d4e31dbb9c3609;hb=HEAD;hpb=c50d88536a4feb3087d1aa802e110250cb2861fc diff --git a/ud-xearth b/ud-xearth index b1c1fee..58f8e93 100755 --- a/ud-xearth +++ b/ud-xearth @@ -14,67 +14,48 @@ # DGMS -> DD DDD + (MM + (SS.SSSSSS)/60)/60 # For Latitude + is North, for Longitude + is East -import string, re, time, ldap, getopt, sys, pwd, posix; +import re, time, ldap, getopt, sys, pwd, os, posix; from userdir_ldap import *; -# This needs to check for leading 0 to disambiguate some things -def DecDegree(Attr,Type): - Parts = re.match('[+-]?(\d*)\\.?(\d*)?',GetAttr(Attr,Type)).groups(); - Val = string.atof(GetAttr(Attr,Type)); - - if (abs(Val) >= 1806060.0): - raise ValueError,"Too Big"; - - # Val is in DGMS - if abs(Val) >= 18060.0 or len(Parts[0]) > 5: - Val = Val/100.0; - Secs = Val - long(Val); - Val = long(Val)/100.0; - Min = Val - long(Val); - Val = long(Val) + (Min*100.0 + Secs*100.0/60.0)/60.0; - - # Val is in DGM - elif abs(Val) >= 180 or len(Parts[0]) > 3: - Val = Val/100.0; - Min = Val - long(Val); - Val = long(Val) + Min*100.0/60.0; - - if Val >= 0: - return "+" + str(Val); - return str(Val); +Anon = 0; # Main program starts here User = pwd.getpwuid(posix.getuid())[0]; BindUser = User; -(options, arguments) = getopt.getopt(sys.argv[1:], "u:") +(options, arguments) = getopt.getopt(sys.argv[1:], "au:") for (switch, val) in options: if (switch == '-u'): - User = val + User = val; + if (switch == '-a'): + Anon = 1; # Connect to the ldap server -l = ldap.open(LDAPServer); -print "Accessing LDAP directory as '" + User + "'"; -Password = getpass(User + "'s password: "); -UserDn = "uid=" + User + "," + BaseDn; -l.simple_bind_s(UserDn,Password); +l = passwdAccessLDAP(BaseDn, User) Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"latitude=*",\ ["uid","cn","mn","sn","latitude","longitude"]); -#ttrs = [('uid=bma,ou=users,dc=debian,dc=org', {'longitude': ['-0771426.059'], 'sn': ['Almeida'], 'cn': ['Brian'], 'latitude': ['0384514.263'], 'uid': ['bma']}), ('uid=jgg,ou=users,dc=debian,dc=org', {'longitude': ['-11328'], 'sn': ['Gunthorpe'], 'cn': ['Jason'], 'latitude': ['+5333'], 'uid': ['jgg']})] Attrs.sort(); print "Markers file will be written to markers.dat,", sys.stdout.flush(); F = open("markers.dat","w"); Count = 0; +Failed = 0; for x in Attrs: if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0: continue; Count = Count + 1; try: - F.write("%16s %16s \"%s\" \t# %s\n"%(DecDegree(x,"latitude"),DecDegree(x,"longitude"),GetAttr(x,"uid"),EmailAddress(x))); + if Anon != 0: + F.write("%8s %8s \"\"\n"%(DecDegree(GetAttr(x,"latitude"),Anon),DecDegree(GetAttr(x,"longitude"),Anon))); + else: + F.write("%16s %16s \"%s\" \t# %s\n"%(DecDegree(GetAttr(x,"latitude"),Anon),DecDegree(GetAttr(x,"longitude"),Anon),GetAttr(x,"uid"),EmailAddress(x))); except: - F.write("# Failed %s => %s: %s\n" %(x[0],sys.exc_type,sys.exc_value)); + Failed = Failed + 1; + if Anon == 0: + F.write("# Failed %s => %s: %s\n" %(x[0],sys.exc_type,sys.exc_value)); + else: + F.write("# Failed => %s: %s\n" %(sys.exc_type,sys.exc_value)); F.close(); -print Count,"entries."; +print Count,"entries,",Failed,"failures.";