From 4ca1cbf40c58dbf1ea95422652d3aea42a96d98d Mon Sep 17 00:00:00 2001 From: iiPython Date: Sat, 14 Jan 2023 22:19:15 -0600 Subject: [PATCH] Full pyinstaller support --- src/__init__.py | 10 ++++++---- src/config.py | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index df80dab..d7f4f60 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,6 +1,7 @@ # Copyright 2022 StreamX Developers # Modules +import os import logging from aiohttp import web from rich.logging import RichHandler @@ -31,11 +32,12 @@ serverSelectionTimeoutMS = 1000 # ms ) try: - mongo.server_info() - log.info(f"Connected to MongoDB at {mongo.client.address[0]}!") + if os.getenv("SXPYINSTALLER") != "1": + mongo.server_info() + log.info(f"Connected to MongoDB at {mongo.client.address[0]}!") - app.mongo = mongo["streaming"] - app.payment = mongo["purchases"] + app.mongo = mongo["streaming"] + app.payment = mongo["purchases"] except errors.ServerSelectionTimeoutError: log.critical("FAILED to connect to MongoDB! Check MONGO* env and database status.") diff --git a/src/config.py b/src/config.py index 5619975..a7d8405 100644 --- a/src/config.py +++ b/src/config.py @@ -2,6 +2,7 @@ # Modules import os +import sys import json import logging import requests @@ -10,7 +11,7 @@ log, upstream_url = logging.getLogger("rich"), os.getenv("STREAMX_UPSTREAM", "") def e(message: str) -> None: log.critical(message) - exit(1) + sys.exit(1) if not upstream_url.strip(): e("Missing upstream configuration URL!") @@ -28,7 +29,8 @@ def e(message: str) -> None: e("Configuration server is offline!") else: - fp = os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json") + fl = os.path.dirname(__file__ if not getattr(sys, "frozen", False) else sys.executable) + fp = os.path.join(fl, "config.json") if not os.path.isfile(fp): e("Config upstream set to file but no configuration file exists!")