2 listings
[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':'email'}) 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     if p['enabled']: print 'ENB',
16     else: print 'DIS',
17     print p['email']
18
19 def get_related(email):
20     return GetPersons ({'email':email,'~peer_id':None})
21
22 def header (message):
23     print '--------------------'
24     print GetPeerName(),
25     print time.asctime(time.gmtime())
26     print 'Listing orphan accounts and any similar remote'
27     print '--------------------'
28
29 def main_orphans ():
30     orphans = get_orphans()
31     header ('Listing  %d  local accounts with no site - and similar remote accounts'%len(orphans))
32     index=1
33     for p in orphans:
34         list_person ("%3d"%index,p)
35         for related in get_related(p['email']):
36             list_person("dup",related)
37         index+=1
38     
39 def main_duplicates():
40
41     header ('Listing all duplicate accounts')
42     for local in GetPersons({'peer_id':None,'-SORT':'email'}):
43         remotes=GetPersons({'email':local['email'],'~peer_id':None})
44         if remotes:
45             list_person('---',local)
46             for remote in remotes:
47                 list_person('dup',remote)
48
49 def main():
50     main_orphans()
51     main_duplicates()
52
53 if __name__ == '__main__':
54     main()