summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-09-04 15:19:04 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-09-04 15:19:04 +0200
commitb819c27aaaacbd629b67dfdceafd2a9ec9c08aec (patch)
treed286b6c570b07ca424aba8b05668f36b3ed805af
parent51d40aa5accc446953df4db8a93243233d29e44a (diff)
util: Ask fortune where fortunes can be found
-rwxr-xr-xkpov_util.py10
1 files 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: