Try to open /dev/mem before calling rpitx

mailbox.c tries to open /dev/mem and calls exit if it doesn't have
permission, which will forcefully exit the Python runtime. Try to open
it and throwing an exception if it fails before umping into C to give
users a chance to recover.

Also, because avconv is writing to a pipe, having the read end of the
pipe unexpectedly close breaks the terminal. I kept having to run
`reset` to get it back.
pull/72/head
Brandon Skari 2017-05-15 15:35:51 -06:00
rodzic b85ece8df6
commit bcc68e6973
1 zmienionych plików z 17 dodań i 0 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ import libavwrapper
import logging
import os
import subprocess
import sys
import threading
PIPE = 'pipe:1'
@ -18,6 +19,22 @@ def broadcast_fm(media_file_name, frequency):
logging.basicConfig()
logger = logging.getLogger('rpitx')
# Python < 3.3 throws IOError instead of PermissionError
if sys.version_info.major <= 2 or (sys.version_info.major == 3 and sys.version_info.minor < 3):
Error = IOError
else:
Error = PermissionError
# mailbox.c calls exit if /dev/mem can't be opened, which causes the avconv
# pipe to be left open and messes with the terminal, so try it here first
# just to be safe
try:
open('/dev/mem')
except Error:
raise Error(
'This program should be run as root. Try prefixing command with: sudo'
)
dev_null = open(os.devnull, 'w')
if subprocess.call(('which', 'ffmpeg'), stdout=dev_null) == 0:
Input = ffmpegwrapper.Input