From b819c27aaaacbd629b67dfdceafd2a9ec9c08aec Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 4 Sep 2019 15:19:04 +0200 Subject: util: Ask fortune where fortunes can be found --- kpov_util.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kpov_util.py b/kpov_util.py index 6a667bf..f0c182a 100755 --- a/kpov_util.py +++ b/kpov_util.py @@ -11,6 +11,7 @@ import re import socket import string import struct +import subprocess def ssh_test(host, user, password, commands=()): import pexpect @@ -52,10 +53,13 @@ def alnum_gen(r, length=1, digit=True, lower=True, upper=True): for i in range(length)) def fortune(r, max_len): + # ask fortune where it stores its cookies + paths = subprocess.run(['fortune', '-f'], stderr=subprocess.PIPE, text=True).stderr.splitlines() + fortune_dir = paths[0].split()[-1] + + # make a list of all fortunes all_fortunes = [] - for fortune_file in itertools.chain( - glob.iglob('/usr/share/fortune/*.u8'), - glob.iglob('/usr/share/games/fortunes/*.u8')): + for fortune_file in glob.iglob(f'{fortune_dir}/*.u8'): f = open(fortune_file) l = f.read().split('\n%\n')[:-1] for i in l: -- cgit v1.2.1