Files
2023-01-28 16:14:41 +00:00

61 lines
2.0 KiB
Python

import faulthandler
import logging
import multiprocessing
import os
import platform
import subprocess
import sys
from typing import TextIO
from PyQt6.QtCore import QTranslator, QLocale
from appdirs import user_log_dir
# Check for segfaults if not running in frozen mode
if getattr(sys, 'frozen', False) is False:
faulthandler.enable()
# Sets stderr to no-op TextIO when None (run as Windows GUI).
# Resolves https://github.com/chidiwilliams/buzz/issues/221
if sys.stderr is None:
sys.stderr = TextIO()
# Adds the current directory to the PATH, so the ffmpeg binary get picked up:
# https://stackoverflow.com/a/44352931/9830227
app_dir = getattr(sys, '_MEIPASS', os.path.dirname(
os.path.abspath(__file__)))
os.environ["PATH"] += os.pathsep + app_dir
# Add the app directory to the DLL list: https://stackoverflow.com/a/64303856
if platform.system() == 'Windows':
os.add_dll_directory(app_dir)
if __name__ == "__main__":
# Contrary to the multiprocessing docs (https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods),
# running sub-processes seem to exit with code 1 on Linux and Mac ARM without setting the "spawn" start method
if platform.system() == 'Linux':
multiprocessing.set_start_method('spawn')
if platform.system() == 'Darwin' and platform.processor() == 'arm':
print('setting start method to spawn')
multiprocessing.set_start_method('spawn')
# Fixes opening new window when app has been frozen on Windows:
# https://stackoverflow.com/a/33979091
multiprocessing.freeze_support()
log_dir = user_log_dir(appname='Buzz')
os.makedirs(log_dir, exist_ok=True)
logging.basicConfig(
filename=os.path.join(log_dir, 'logs.txt'),
level=logging.DEBUG,
format="[%(asctime)s] %(module)s.%(funcName)s:%(lineno)d %(levelname)s -> %(message)s")
cmd = subprocess.run(['ffmpeg', '-h'])
logging.debug('subprocess exited with code %s', cmd.returncode)
from buzz.gui import Application
app = Application()
sys.exit(app.exec())