Enforce HOME, TERM, and PATH env vars when running

Instead of showing an ugly traceback
This commit is contained in:
mathieui 2018-01-13 15:31:10 +01:00
parent 391eb27964
commit 6fe2f20833
No known key found for this signature in database
GPG key ID: C59F84CEEFD616E3
2 changed files with 18 additions and 4 deletions

View file

@ -1,11 +1,11 @@
def run():
from poezio.poezio import test_curses, main
from poezio.poezio import main, test_curses, test_env
if test_curses():
main()
else:
if not test_curses() or not test_env():
import sys
sys.exit(1)
else:
main()
return 0

View file

@ -37,6 +37,20 @@ Poezio is currently unable to read your input or draw its interface properly,\
so it will now exit.""")
return False
def test_env():
"""
Check if the environment has the right variables set
"""
unset = set()
for i in ('HOME', 'PATH', 'TERM'):
if not os.environ.get(i):
unset.add(i)
if unset:
variables = ', '.join('$%s' % i for i in unset)
print('ERROR: %s not set' % variables)
return False
return True
def main():
"""