summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ogcp/views.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 6e9752b..1049675 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -2470,8 +2470,8 @@ def action_mode():
selected_clients=selected_clients,
clients=clients, modes_set=modes_set)
-def get_clients_oglive(ips, server):
- oglives = {}
+def get_client_list_by_key(ips, server, key):
+ ret = {}
for ip in ips:
r = server.get('/client/info', payload={"client": [ip]})
if not r:
@@ -2479,12 +2479,12 @@ def get_clients_oglive(ips, server):
if r.status_code != requests.codes.ok:
raise ServerErrorCode
resp = r.json()
- oglive = resp['livedir']
- if oglive not in oglives:
- oglives[oglive] = [ip]
+ val = resp[key]
+ if val not in ret:
+ ret[val] = [ip]
else:
- oglives[oglive].append(ip)
- return oglives
+ ret[val].append(ip)
+ return ret
@app.route('/action/oglive', methods=['GET', 'POST'])
@login_required
@@ -2511,7 +2511,7 @@ def action_oglive():
server = get_server_from_clients(list(ips))
try:
- oglives_set = get_clients_oglive(ips, server)
+ oglives_set = get_client_list_by_key(ips, server, key='livedir')
except ServerError:
return ogserver_down('commands')
except ServerErrorCode:
@@ -2601,9 +2601,25 @@ def action_repo_set():
except ServerErrorCode:
return ogserver_error(r, 'commands')
- form.repo.choices = [(repo["id"], repo["name"]) for repo in repositories]
-
scopes, clients = get_scopes(set(ips))
+
+ try:
+ repo_set = get_client_list_by_key(ips, server, key='repo_id')
+ except ServerError:
+ return ogserver_down('commands')
+ except ServerErrorCode:
+ return ogserver_error(r, 'commands')
+
+ most_used_repo_id = max(repo_set, key=lambda id: len(repo_set[id]))
+
+ form.repo.choices = []
+ for repo in repositories:
+ repo_entry = (repo["id"], repo["name"])
+ if repo["id"] == most_used_repo_id:
+ form.repo.choices.insert(0, repo_entry)
+ else:
+ form.repo.choices.append(repo_entry)
+
selected_clients = list(get_selected_clients(scopes['scope']).items())
return render_template('actions/repo_set.html', repos_set=repos_set, form=form, scopes=scopes,
selected_clients=selected_clients)