2c8189b1a7f876ed895f07f0849acf07d102af18
[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 'Found',len(orphans),'orphan accounts'
24     index=1
25     for p in orphans:
26         list_person ("%3d"%index,p)
27         for related in get_related(p['email']):
28             list_person("---",related)
29         index+=1
30     
31 if __name__ == '__main__':
32     main()