diff --git a/gns3server/crash_report.py b/gns3server/crash_report.py index 2cefe0e4..a18d4335 100644 --- a/gns3server/crash_report.py +++ b/gns3server/crash_report.py @@ -33,6 +33,7 @@ except ImportError: from .version import __version__ from .config import Config +from .utils.get_resource import get_resource import logging log = logging.getLogger(__name__) @@ -46,7 +47,7 @@ class CrashReport: DSN = "sync+https://9e6f04df72c74b6894a6dcd2928d069e:2035d1beb1654136b170f1e91f05ee51@app.getsentry.com/38482" if hasattr(sys, "frozen"): - cacert = os.path.join(os.getcwd(), "cacert.pem") + cacert = get_resource("cacert.pem") if os.path.isfile(cacert): DSN += "?ca_certs={}".format(cacert) else: diff --git a/gns3server/utils/get_resource.py b/gns3server/utils/get_resource.py index dae285fc..04d44fac 100644 --- a/gns3server/utils/get_resource.py +++ b/gns3server/utils/get_resource.py @@ -19,6 +19,8 @@ import tempfile import pkg_resources import atexit import logging +import os +import sys log = logging.getLogger(__name__) @@ -39,3 +41,19 @@ def clean_egg_cache(): except Exception: # We don't care if we can not cleanup pass + + +def get_resource(resource_name): + """ + Return a resource in current directory or in frozen package + """ + + resource_path = None + if hasattr(sys, "frozen") and sys.platform.startswith("darwin"): + resource_name = os.path.join("../Resources", resource_name) + if hasattr(sys, "frozen") and os.path.exists(resource_name): + resource_path = os.path.normpath(os.path.join(os.getcwd(), resource_name)) + elif not hasattr(sys, "frozen") and pkg_resources.resource_exists("gns3", resource_name): + resource_path = pkg_resources.resource_filename("gns3", resource_name) + resource_path = os.path.normpath(resource_path) + return resource_path