3 # Generate an xearth database from the LDAP entries
4 # LDAP entires for lat/long can be in one of 3 different formats
6 # +-DDD.DDDDDDDDDDDDDDD
7 # 2) Degrees Minutes (DGM), common output from GPS units
8 # +-DDDMM.MMMMMMMMMMMMM
9 # 3) Degrees Minutes Seconds (DGMS)
10 # +-DDDMMSS.SSSSSSSSSSS
11 # Decimal Degrees is the most basic format, but to have good accuracy it
12 # needs a large number of decimals. The other formats are all derived from it:
13 # DGM -> DD DDD + (MM.MMMMMMMM)/60
14 # DGMS -> DD DDD + (MM + (SS.SSSSSS)/60)/60
15 # For Latitude + is North, for Longitude + is East
17 import string, re, time, ldap, getopt, sys, pwd, os, posix;
18 from userdir_ldap import *;
22 # Main program starts here
23 User = pwd.getpwuid(posix.getuid())[0];
25 (options, arguments) = getopt.getopt(sys.argv[1:], "au:")
26 for (switch, val) in options:
32 # Connect to the ldap server
33 l = passwdAccessLDAP(LDAPServer, BaseDn, User)
35 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"latitude=*",\
36 ["uid","cn","mn","sn","latitude","longitude"]);
40 print "Markers file will be written to markers.dat,",
42 F = open("markers.dat","w");
46 if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
51 F.write("%8s %8s \"\"\n"%(DecDegree(GetAttr(x,"latitude"),Anon),DecDegree(GetAttr(x,"longitude"),Anon)));
53 F.write("%16s %16s \"%s\" \t# %s\n"%(DecDegree(GetAttr(x,"latitude"),Anon),DecDegree(GetAttr(x,"longitude"),Anon),GetAttr(x,"uid"),EmailAddress(x)));
57 F.write("# Failed %s => %s: %s\n" %(x[0],sys.exc_type,sys.exc_value));
59 F.write("# Failed => %s: %s\n" %(sys.exc_type,sys.exc_value));
61 print Count,"entries,",Failed,"failures.";