-
Notifications
You must be signed in to change notification settings - Fork 2
/
wt_lint.py
executable file
·96 lines (75 loc) · 3 KB
/
wt_lint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
import gedcom
import datetime
def stdPrint(data=''):
print data
def lint(fname, options, out=stdPrint):
output = None
opts = {}
for o in options:
out(o)
if '=' in o:
k,v = o.split('=',1)
opts[k] = v
else:
opts[o] = None
if opts.has_key('output'):
output = open(opts['output'],'w')
maxage = None
if opts.has_key('maxage'):
maxage = float(opts['maxage'])
g = gedcom.Gedcom(fname)
llg = gedcom.LineageLinkedGedcom(g)
if output is not None:
output.write('<html><body>\n')
output.write('<h1><a href="http://www.wikitree.com">WikiTree</a> Lint</h1>\n')
output.write('<p>Report run at: '+str(datetime.datetime.now())+'</p>\n')
output.write('<p>input: '+fname+'</p>\n')
output.write('<el>Lint options\n')
for k,v in opts.iteritems():
output.write('<li>'+k)
if v is not None:
output.write(': '+v)
output.write('</li>\n')
output.write('</el>\n')
for i in llg.individuals:
if i.records.has_key('WWW'):
problems = []
if maxage is not None and i.getAge() is not None and i.getAge() > maxage:
problems.append('age {0} greater than maximum age {1}'.format(i.getAge(),maxage))
if opts.has_key('birth') and i.get('BIRT').get('DATE') is None:
problems.append('missing birth date')
if opts.has_key('death') and i.get('DEAT') is None:
problems.append('missing date of death')
if i.get('SEX') is None:
problems.append('sex not defined')
for obj in i.getAll('OBJE'):
if obj.get('FORM').value == 'Message':
if obj.get('TEXT').value.lower().find('todo') != -1:
problems.append('todo found in message')
if i.get('NOTE').get('TEXT').value.lower().find('todo') != -1:
problems.append('todo found in bio')
if len(problems):
if output is not None:
output.write(i.html()+'\n')
output.write('<h3>Problems:</h3>\n')
output.write('<e1>\n')
for p in problems:
output.write('<li>'+p+'</li>\n')
output.write('</e1>\n')
out('')
out('\n'.join(problems))
out(i)
for obj in i.getAll('OBJE'):
if obj.get('FORM').value == 'Message':
out(obj.get('TEXT').value)
if output is not None:
output.write('</body></html>\n')
if __name__ == '__main__':
import sys
if len(sys.argv) < 2:
print 'usage: wt_lint.py gedcom.ged [options]'
print '\toptions:'
print '\t\toutput=report.html'
exit(1)
lint(sys.argv[1],sys.argv[2:])