summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2020-07-31 20:26:21 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2020-07-31 20:26:21 (GMT)
commitc8a9add309feda90b18ad4e0c8019c50390748de (patch)
treea609614271de808771cf421aacac682484a71e63
parentd173265f5c6f31631e00181c7c2d7e1ff7c30c31 (diff)
downloadmisc-fred-c8a9add309feda90b18ad4e0c8019c50390748de.zip
misc-fred-c8a9add309feda90b18ad4e0c8019c50390748de.tar.gz
misc-fred-c8a9add309feda90b18ad4e0c8019c50390748de.tar.bz2
eoptasks: add stripsuffix configuration option
-rwxr-xr-xeoptasks/eoptasks.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/eoptasks/eoptasks.py b/eoptasks/eoptasks.py
index 49060e0..b204514 100755
--- a/eoptasks/eoptasks.py
+++ b/eoptasks/eoptasks.py
@@ -18,6 +18,7 @@
# [config]
# servergroups = /path/to/servergroups.yaml
# ignore = server1, server2
+# stripsuffix = .entrouvert.org
#
# Examples:
#
@@ -51,8 +52,9 @@ import libtmux
import yaml
class Server:
- def __init__(self, servername, group=''):
+ def __init__(self, servername, group='', display_name=''):
self.name = servername
+ self.display_name = display_name or self.name
self.keywords = set(re.split(r'[-_ \.]', servername + ' ' + group))
self.keywords.add(group)
@@ -83,12 +85,19 @@ def get_servers():
sys.exit(1)
ignorelist = [x.strip() for x in config.get('config', 'ignore', fallback='').split(',')]
+ stripsuffix = config.get('config', 'stripsuffix', fallback='')
servergroups = yaml.safe_load(open(servergroup))['servergroups']
+
+ def get_display_name(x):
+ if stripsuffix and x.endswith(stripsuffix):
+ return x[:-len(stripsuffix)]
+ return x
+
for group in servergroups:
for servername in servergroups[group]:
if servername in ignorelist:
continue
- servers.append(Server(servername, group))
+ servers.append(Server(servername, group, display_name=get_display_name(servername)))
return servers
def parse_args():
@@ -160,13 +169,13 @@ def status_window(args):
try:
height, width = window.getmaxyx()
- max_length = max([len(x) for x in servers_info.keys()]) + 4
+ max_length = max([len(x['display_name']) for x in servers_info.values()]) + 4
nb_columns = (width-4) // max_length
for i, server_name in enumerate(servers_info):
y = 2 + (i//nb_columns)
x = 1 + (width//nb_columns) * (i%nb_columns)
- window.addstr(y, x+3, server_name)
+ window.addstr(y, x+3, servers_info[server_name]['display_name'])
status_icon = {
'running': '⏳',
'done': '🆗',
@@ -324,7 +333,7 @@ else:
servers_info = {}
for server in selected_servers:
- servers_info[server.name] = {'status': ''}
+ servers_info[server.name] = {'status': '', 'display_name': server.display_name}
def send_status():
current_windows = [x.name for x in session.list_windows()]