root / snf-astakos-app / astakos / im / management / commands / astakos-qh-sync.py @ 61a1b2d2
History | View | Annotate | Download (2.4 kB)
1 | fc1e2f02 | Sofia Papagiannaki | # Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | fc1e2f02 | Sofia Papagiannaki | #
|
3 | fc1e2f02 | Sofia Papagiannaki | # Redistribution and use in source and binary forms, with or
|
4 | fc1e2f02 | Sofia Papagiannaki | # without modification, are permitted provided that the following
|
5 | fc1e2f02 | Sofia Papagiannaki | # conditions are met:
|
6 | fc1e2f02 | Sofia Papagiannaki | #
|
7 | fc1e2f02 | Sofia Papagiannaki | # 1. Redistributions of source code must retain the above
|
8 | fc1e2f02 | Sofia Papagiannaki | # copyright notice, this list of conditions and the following
|
9 | fc1e2f02 | Sofia Papagiannaki | # disclaimer.
|
10 | fc1e2f02 | Sofia Papagiannaki | #
|
11 | fc1e2f02 | Sofia Papagiannaki | # 2. Redistributions in binary form must reproduce the above
|
12 | fc1e2f02 | Sofia Papagiannaki | # copyright notice, this list of conditions and the following
|
13 | fc1e2f02 | Sofia Papagiannaki | # disclaimer in the documentation and/or other materials
|
14 | fc1e2f02 | Sofia Papagiannaki | # provided with the distribution.
|
15 | fc1e2f02 | Sofia Papagiannaki | #
|
16 | fc1e2f02 | Sofia Papagiannaki | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | fc1e2f02 | Sofia Papagiannaki | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | fc1e2f02 | Sofia Papagiannaki | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | fc1e2f02 | Sofia Papagiannaki | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | fc1e2f02 | Sofia Papagiannaki | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | fc1e2f02 | Sofia Papagiannaki | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | fc1e2f02 | Sofia Papagiannaki | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | fc1e2f02 | Sofia Papagiannaki | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | fc1e2f02 | Sofia Papagiannaki | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | fc1e2f02 | Sofia Papagiannaki | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | fc1e2f02 | Sofia Papagiannaki | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | fc1e2f02 | Sofia Papagiannaki | # POSSIBILITY OF SUCH DAMAGE.
|
28 | fc1e2f02 | Sofia Papagiannaki | #
|
29 | fc1e2f02 | Sofia Papagiannaki | # The views and conclusions contained in the software and
|
30 | fc1e2f02 | Sofia Papagiannaki | # documentation are those of the authors and should not be
|
31 | fc1e2f02 | Sofia Papagiannaki | # interpreted as representing official policies, either expressed
|
32 | fc1e2f02 | Sofia Papagiannaki | # or implied, of GRNET S.A.
|
33 | fc1e2f02 | Sofia Papagiannaki | |
34 | e1a80257 | Sofia Papagiannaki | from django.core.management.base import NoArgsCommand, CommandError |
35 | fc1e2f02 | Sofia Papagiannaki | |
36 | bd4f356c | Sofia Papagiannaki | from astakos.im.models import AstakosUser, Resource |
37 | b6852727 | Olga Brani | from astakos.im.endpoints.qh import register_users, register_resources |
38 | fc1e2f02 | Sofia Papagiannaki | |
39 | 9a06d96f | Olga Brani | import logging |
40 | 9a06d96f | Olga Brani | logger = logging.getLogger(__name__) |
41 | 9a06d96f | Olga Brani | |
42 | 5ce3ce4f | Sofia Papagiannaki | |
43 | e1a80257 | Sofia Papagiannaki | class Command(NoArgsCommand): |
44 | fc1e2f02 | Sofia Papagiannaki | help = "Send user information and resource quota in the Quotaholder"
|
45 | 5ce3ce4f | Sofia Papagiannaki | |
46 | e1a80257 | Sofia Papagiannaki | def handle_noargs(self, **options): |
47 | fc1e2f02 | Sofia Papagiannaki | try:
|
48 | 61a1b2d2 | Georgios D. Tsoukalas | resources = list(Resource.objects.all())
|
49 | 61a1b2d2 | Georgios D. Tsoukalas | print("Registering resources")
|
50 | 61a1b2d2 | Georgios D. Tsoukalas | register_resources(resources) |
51 | 61a1b2d2 | Georgios D. Tsoukalas | print("Registering users")
|
52 | 61a1b2d2 | Georgios D. Tsoukalas | users = list(AstakosUser.objects.verified().all())
|
53 | 61a1b2d2 | Georgios D. Tsoukalas | if users:
|
54 | 61a1b2d2 | Georgios D. Tsoukalas | register_users(users) |
55 | 61a1b2d2 | Georgios D. Tsoukalas | else:
|
56 | 61a1b2d2 | Georgios D. Tsoukalas | print(" -> No verified users found.")
|
57 | fc1e2f02 | Sofia Papagiannaki | except BaseException, e: |
58 | 9a06d96f | Olga Brani | logger.exception(e) |
59 | 9a06d96f | Olga Brani | raise CommandError("Syncing failed.") |