fix
[myplc.git] / plc-orphan-accounts.py
1 #!/usr/bin/env plcsh
2
3 # searches and displays any local orphan account (not attached to a site)
4 # remote accounts with identical emails are displayed as well
5
6 import time
7
8 def get_orphans ():
9     return [p for p in GetPersons({'peer_id':None,'-SORT':'date_created'}) if not p['site_ids'] ]
10
11 def list_person (margin,p):
12     print margin,'%6d'%p['person_id'], time.asctime(time.gmtime(p['date_created'])),
13     if not p['peer_id']: print 'LOCAL',
14     else: print 'pr=',p['peer_id'],
15     print p['email']
16
17 def get_related(email):
18     return GetPersons ({'email':email,'~peer_id':None})
19
20 def main ():
21     
22     orphans = get_orphans()
23     print GetPeerName(),' ---  %d  --- '%len(orphans),'orphan accounts'
24     print '---'
25     index=1
26     for p in orphans:
27         list_person ("%3d"%index,p)
28         for related in get_related(p['email']):
29             list_person("dup",related)
30         index+=1
31     
32 if __name__ == '__main__':
33     main()