author | David Douard <david.douard@logilab.fr> |
Thu, 02 Jul 2015 19:54:25 +0200 | |
changeset 10496 | e95b559a06a2 |
parent 8568 | 56d9eb013feb |
child 10589 | 7c23b7de2b8d |
permissions | -rw-r--r-- |
8568
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
1 |
""" |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
2 |
CAUTION: READ THIS CAREFULLY |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
3 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
4 |
Sometimes it happens that ldap (specifically ldapuser type) source |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
5 |
yield "ghost" users. The reasons may vary (server upgrade while some |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
6 |
instances are still running & syncing with the ldap source, unmanaged |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
7 |
updates to the upstream ldap, etc.). |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
8 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
9 |
This script was written and refined enough times that we are confident |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
10 |
in that it does something reasonnable (at least it did for the |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
11 |
target application). |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
12 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
13 |
However you should really REALLY understand what it does before |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
14 |
deciding to apply it for you. And then ADAPT it tou your needs. |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
15 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
16 |
""" |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
17 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
18 |
import base64 |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
19 |
from collections import defaultdict |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
20 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
21 |
from cubicweb.server.session import hooks_control |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
22 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
23 |
try: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
24 |
source_name, = __args__ |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
25 |
source = repo.sources_by_uri[source_name] |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
26 |
except ValueError: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
27 |
print('you should specify the source name as script argument (i.e. after --' |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
28 |
' on the command line)') |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
29 |
sys.exit(1) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
30 |
except KeyError: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
31 |
print '%s is not an active source' % source_name |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
32 |
sys.exit(1) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
33 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
34 |
# check source is reachable before doing anything |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
35 |
if not source.get_connection().cnx: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
36 |
print '%s is not reachable. Fix this before running this script' % source_name |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
37 |
sys.exit(1) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
38 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
39 |
def find_dupes(): |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
40 |
# XXX this retrieves entities from a source name "ldap" |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
41 |
# you will want to adjust |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
42 |
rset = sql("SELECT eid, extid FROM entities WHERE source='%s'" % source_name) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
43 |
extid2eids = defaultdict(list) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
44 |
for eid, extid in rset: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
45 |
extid2eids[extid].append(eid) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
46 |
return dict((base64.b64decode(extid).lower(), eids) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
47 |
for extid, eids in extid2eids.items() |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
48 |
if len(eids) > 1) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
49 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
50 |
def merge_dupes(dupes, docommit=False): |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
51 |
gone_eids = [] |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
52 |
CWUser = schema['CWUser'] |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
53 |
for extid, eids in dupes.items(): |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
54 |
newest = eids.pop() # we merge everything on the newest |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
55 |
print 'merging ghosts of', extid, 'into', newest |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
56 |
# now we merge pairwise into the newest |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
57 |
for old in eids: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
58 |
subst = {'old': old, 'new': newest} |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
59 |
print ' merging', old |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
60 |
gone_eids.append(old) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
61 |
for rschema in CWUser.subject_relations(): |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
62 |
if rschema.final or rschema == 'identity': |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
63 |
continue |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
64 |
if CWUser.rdef(rschema, 'subject').composite == 'subject': |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
65 |
# old 'composite' property is wiped ... |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
66 |
# think about email addresses, excel preferences |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
67 |
for eschema in rschema.objects(): |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
68 |
rql('DELETE %s X WHERE U %s X, U eid %%(old)s' % (eschema, rschema), subst) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
69 |
else: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
70 |
# relink the new user to its old relations |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
71 |
rql('SET NU %s X WHERE NU eid %%(new)s, NOT NU %s X, OU %s X, OU eid %%(old)s' % |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
72 |
(rschema, rschema, rschema), subst) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
73 |
# delete the old relations |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
74 |
rql('DELETE U %s X WHERE U eid %%(old)s' % rschema, subst) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
75 |
# same thing ... |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
76 |
for rschema in CWUser.object_relations(): |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
77 |
if rschema.final or rschema == 'identity': |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
78 |
continue |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
79 |
rql('SET X %s NU WHERE NU eid %%(new)s, NOT X %s NU, X %s OU, OU eid %%(old)s' % |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
80 |
(rschema, rschema, rschema), subst) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
81 |
rql('DELETE X %s U WHERE U eid %%(old)s' % rschema, subst) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
82 |
if not docommit: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
83 |
rollback() |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
84 |
return |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
85 |
commit() # XXX flushing operations is wanted rather than really committing |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
86 |
print 'clean up entities table' |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
87 |
sql('DELETE FROM entities WHERE eid IN (%s)' % (', '.join(str(x) for x in gone_eids))) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
88 |
commit() |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
89 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
90 |
def main(): |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
91 |
dupes = find_dupes() |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
92 |
if not dupes: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
93 |
print 'No duplicate user' |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
94 |
return |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
95 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
96 |
print 'Found %s duplicate user instances' % len(dupes) |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
97 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
98 |
while True: |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
99 |
print 'Fix or dry-run? (f/d) ... or Ctrl-C to break out' |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
100 |
answer = raw_input('> ') |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
101 |
if answer.lower() not in 'fd': |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
102 |
continue |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
103 |
print 'Please STOP THE APPLICATION INSTANCES (service or interactive), and press Return when done.' |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
104 |
raw_input('<I swear all running instances and workers of the application are stopped>') |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
105 |
with hooks_control(session, session.HOOKS_DENY_ALL): |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
106 |
merge_dupes(dupes, docommit=answer=='f') |
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
107 |
|
56d9eb013feb
[misc/scripts] a slightly experimental script to help repair LDAPUser cwusers suffering from split-brainite (closes #2497108)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
108 |
main() |