Revision 2ef1e2d7 snf-astakos-app/astakos/im/management/commands/astakos-quota.py
b/snf-astakos-app/astakos/im/management/commands/astakos-quota.py | ||
---|---|---|
70 | 70 |
|
71 | 71 |
def handle(self, *args, **options): |
72 | 72 |
sync = options['sync'] |
73 |
verify = options['verify'] or sync
|
|
73 |
verify = options['verify'] |
|
74 | 74 |
user_ident = options['user'] |
75 |
list_only = not sync and not verify |
|
76 |
|
|
75 | 77 |
|
76 | 78 |
if user_ident is not None: |
77 | 79 |
log = self.run_sync_user(user_ident, sync) |
78 | 80 |
else: |
79 | 81 |
log = self.run(sync) |
80 | 82 |
|
81 |
ex, nonex, qh_l, qh_c, astakos_i, astakos_q, info = log |
|
82 |
|
|
83 |
if verify: |
|
84 |
self.print_verify(nonex, qh_l, astakos_q) |
|
83 |
ex, nonex, qh_l, qh_c, astakos_i, diff_q, info = log |
|
85 | 84 |
|
86 |
else:
|
|
85 |
if list_only:
|
|
87 | 86 |
self.list_quotas(qh_l, qh_c, astakos_i, info) |
87 |
else: |
|
88 |
if verify: |
|
89 |
self.print_verify(nonex, qh_l, diff_q) |
|
90 |
if sync: |
|
91 |
self.print_sync(diff_q) |
|
88 | 92 |
|
89 | 93 |
@transaction.commit_on_success |
90 | 94 |
def run_sync_user(self, user_ident, sync): |
... | ... | |
150 | 154 |
line = ' '.join(output) |
151 | 155 |
self.stdout.write(line + '\n') |
152 | 156 |
|
157 |
def print_sync(self, diff_quotas): |
|
158 |
size = len(diff_quotas) |
|
159 |
if size == 0: |
|
160 |
self.stdout.write("No sync needed.\n") |
|
161 |
else: |
|
162 |
self.stdout.write("Synced %s users:\n" % size) |
|
163 |
for holder in diff_quotas.keys(): |
|
164 |
user = get_user_by_uuid(holder) |
|
165 |
self.stdout.write("%s (%s)\n" % (holder, user.username)) |
|
166 |
|
|
153 | 167 |
def print_verify(self, |
154 | 168 |
nonexisting, |
155 | 169 |
qh_limits, |
156 |
astakos_quotas):
|
|
170 |
diff_quotas):
|
|
157 | 171 |
|
158 | 172 |
if nonexisting: |
159 | 173 |
self.stdout.write("Users not registered in quotaholder:\n") |
... | ... | |
161 | 175 |
self.stdout.write("%s\n" % (user)) |
162 | 176 |
self.stdout.write("\n") |
163 | 177 |
|
164 |
diffs = 0 |
|
165 |
for holder, local in astakos_quotas.iteritems(): |
|
178 |
for holder, local in diff_quotas.iteritems(): |
|
166 | 179 |
registered = qh_limits.pop(holder, None) |
180 |
user = get_user_by_uuid(holder) |
|
167 | 181 |
if registered is None: |
168 |
diffs += 1 |
|
169 |
self.stdout.write("No quotas for %s in quotaholder.\n\n" % |
|
170 |
(get_user_by_uuid(holder))) |
|
171 |
elif local != registered: |
|
172 |
diffs += 1 |
|
173 |
self.stdout.write("Quotas differ for %s:\n" % |
|
174 |
(get_user_by_uuid(holder))) |
|
182 |
self.stdout.write( |
|
183 |
"No quotas for %s (%s) in quotaholder.\n" % |
|
184 |
(holder, user.username)) |
|
185 |
else: |
|
186 |
self.stdout.write("Quotas differ for %s (%s):\n" % |
|
187 |
(holder, user.username)) |
|
175 | 188 |
self.stdout.write("Quotas according to quotaholder:\n") |
176 | 189 |
self.stdout.write("%s\n" % (registered)) |
177 | 190 |
self.stdout.write("Quotas according to astakos:\n") |
178 | 191 |
self.stdout.write("%s\n\n" % (local)) |
179 | 192 |
|
193 |
diffs = len(diff_quotas) |
|
180 | 194 |
if diffs: |
181 | 195 |
self.stdout.write("Quotas differ for %d users.\n" % (diffs)) |
Also available in: Unified diff