Revision 7bffb44b snf-astakos-app/astakos/im/management/commands/project-control.py
b/snf-astakos-app/astakos/im/management/commands/project-control.py | ||
---|---|---|
80 | 80 |
"e.g. when denying a project")), |
81 | 81 |
) |
82 | 82 |
|
83 |
@commit_on_success_strict() |
|
83 | 84 |
def handle(self, *args, **options): |
84 | 85 |
|
85 | 86 |
message = options['message'] |
86 | 87 |
|
87 |
pid = options['terminate'] |
|
88 |
if pid is not None: |
|
89 |
self.run_command(terminate, pid) |
|
90 |
return |
|
91 |
|
|
92 |
pid = options['resume'] |
|
93 |
if pid is not None: |
|
94 |
self.run_command(resume, pid) |
|
95 |
return |
|
96 |
|
|
97 |
pid = options['suspend'] |
|
98 |
if pid is not None: |
|
99 |
self.run_command(suspend, pid) |
|
100 |
return |
|
101 |
|
|
102 |
appid = options['approve'] |
|
103 |
if appid is not None: |
|
104 |
self.run_command(approve_application, appid) |
|
105 |
return |
|
106 |
|
|
107 |
appid = options['deny'] |
|
108 |
if appid is not None: |
|
109 |
self.run_command(deny_application, appid, reason=message) |
|
110 |
return |
|
111 |
|
|
112 |
if options['check_expired']: |
|
113 |
self.expire(execute=False) |
|
114 |
return |
|
115 |
|
|
116 |
if options['terminate_expired']: |
|
117 |
self.expire(execute=True) |
|
118 |
|
|
119 |
def run_command(self, func, *args, **kwargs): |
|
120 |
@commit_on_success_strict() |
|
121 |
def inner(): |
|
122 |
try: |
|
123 |
func(*args, **kwargs) |
|
124 |
except BaseException as e: |
|
125 |
raise CommandError(e) |
|
126 |
inner() |
|
88 |
actions = { |
|
89 |
'terminate': terminate, |
|
90 |
'resume': resume, |
|
91 |
'suspend': suspend, |
|
92 |
'approve': approve_application, |
|
93 |
'deny': lambda a: deny_application(a, reason=message), |
|
94 |
'check_expired': lambda _: self.expire(execute=False), |
|
95 |
'terminate_expired': lambda _: self.expire(execute=True), |
|
96 |
} |
|
97 |
|
|
98 |
opts = [(key, value) |
|
99 |
for (key, value) in options.items() |
|
100 |
if key in actions and value] |
|
101 |
|
|
102 |
if len(opts) != 1: |
|
103 |
raise CommandError("Specify exactly one operation.") |
|
104 |
|
|
105 |
key, value = opts[0] |
|
106 |
action = actions[key] |
|
107 |
try: |
|
108 |
action(value) |
|
109 |
except BaseException as e: |
|
110 |
raise CommandError(e) |
|
127 | 111 |
|
128 | 112 |
def print_expired(self, projects, execute): |
129 | 113 |
length = len(projects) |
... | ... | |
152 | 136 |
self.stdout.write('%d projects have been terminated.\n' % ( |
153 | 137 |
length,)) |
154 | 138 |
|
155 |
@commit_on_success_strict() |
|
156 | 139 |
def expire(self, execute=False): |
157 |
try: |
|
158 |
projects = check_expiration(execute=execute) |
|
159 |
self.print_expired(projects, execute) |
|
160 |
except BaseException as e: |
|
161 |
raise CommandError(e) |
|
140 |
projects = check_expiration(execute=execute) |
|
141 |
self.print_expired(projects, execute) |
Also available in: Unified diff