4 # Copyright (c) 1999-2000 Jason Gunthorpe <jgg@debian.org>
5 # Copyright (c) 2004 Joey Schulze <joey@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 # Generate an xearth database from the LDAP entries
22 # LDAP entires for lat/long can be in one of 3 different formats
24 # +-DDD.DDDDDDDDDDDDDDD
25 # 2) Degrees Minutes (DGM), common output from GPS units
26 # +-DDDMM.MMMMMMMMMMMMM
27 # 3) Degrees Minutes Seconds (DGMS)
28 # +-DDDMMSS.SSSSSSSSSSS
29 # Decimal Degrees is the most basic format, but to have good accuracy it
30 # needs a large number of decimals. The other formats are all derived from it:
31 # DGM -> DD DDD + (MM.MMMMMMMM)/60
32 # DGMS -> DD DDD + (MM + (SS.SSSSSS)/60)/60
33 # For Latitude + is North, for Longitude + is East
35 import string, re, time, ldap, getopt, sys, pwd, os, posix;
36 from userdir_ldap import *;
40 # Main program starts here
41 User = pwd.getpwuid(posix.getuid())[0];
43 (options, arguments) = getopt.getopt(sys.argv[1:], "au:")
44 for (switch, val) in options:
50 # Connect to the ldap server
51 l = passwdAccessLDAP(LDAPServer, BaseDn, User)
53 Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL,"latitude=*",\
54 ["uid","cn","mn","sn","latitude","longitude"]);
58 print "Markers file will be written to markers.dat,",
60 F = open("markers.dat","w");
64 if x[1].has_key("latitude") == 0 or x[1].has_key("longitude") == 0:
69 F.write("%8s %8s \"\"\n"%(DecDegree(GetAttr(x,"latitude"),Anon),DecDegree(GetAttr(x,"longitude"),Anon)));
71 F.write("%16s %16s \"%s\" \t# %s\n"%(DecDegree(GetAttr(x,"latitude"),Anon),DecDegree(GetAttr(x,"longitude"),Anon),GetAttr(x,"uid"),EmailAddress(x)));
75 F.write("# Failed %s => %s: %s\n" %(x[0],sys.exc_type,sys.exc_value));
77 F.write("# Failed => %s: %s\n" %(sys.exc_type,sys.exc_value));
79 print Count,"entries,",Failed,"failures.";