123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- import sys
- if "" in sys.path:
- sys.path.remove("")
- import argparse
- import faulthandler
- import os
- from PyQt5.QtNetwork import QSslConfiguration, QSslSocket
- from UM.Platform import Platform
- from cura import ApplicationMetadata
- from cura.ApplicationMetadata import CuraAppName
- from cura.CrashHandler import CrashHandler
- try:
- import sentry_sdk
- with_sentry_sdk = True
- except ImportError:
- with_sentry_sdk = False
- parser = argparse.ArgumentParser(prog = "cura",
- add_help = False)
- parser.add_argument("--debug",
- action = "store_true",
- default = False,
- help = "Turn on the debug mode by setting this option."
- )
- known_args = vars(parser.parse_known_args()[0])
- if with_sentry_sdk:
- sentry_env = "unknown"
- if hasattr(sys, "frozen"):
- sentry_env = "production"
- if ApplicationMetadata.CuraVersion == "master":
- sentry_env = "development"
- elif "beta" in ApplicationMetadata.CuraVersion or "BETA" in ApplicationMetadata.CuraVersion:
- sentry_env = "beta"
- try:
- if ApplicationMetadata.CuraVersion.split(".")[2] == "99":
- sentry_env = "nightly"
- except IndexError:
- pass
-
- ignore_errors = [KeyboardInterrupt, MemoryError]
- try:
- sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564",
- before_send = CrashHandler.sentryBeforeSend,
- environment = sentry_env,
- release = "cura%s" % ApplicationMetadata.CuraVersion,
- default_integrations = False,
- max_breadcrumbs = 300,
- server_name = "cura",
- ignore_errors = ignore_errors)
- except Exception:
- with_sentry_sdk = False
- if not known_args["debug"]:
- def get_cura_dir_path():
- if Platform.isWindows():
- appdata_path = os.getenv("APPDATA")
- if not appdata_path:
- appdata_path = "."
- return os.path.join(appdata_path, CuraAppName)
- elif Platform.isLinux():
- return os.path.expanduser("~/.local/share/" + CuraAppName)
- elif Platform.isOSX():
- return os.path.expanduser("~/Library/Logs/" + CuraAppName)
-
- if hasattr(sys, "frozen") and "cli" not in os.path.basename(sys.argv[0]).lower():
- dirpath = get_cura_dir_path()
- os.makedirs(dirpath, exist_ok = True)
- sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w", encoding = "utf-8")
- sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w", encoding = "utf-8")
- if Platform.isLinux():
-
-
- try:
- import ctypes
- from ctypes.util import find_library
- libGL = find_library("GL")
- ctypes.CDLL(libGL, ctypes.RTLD_GLOBAL)
- except:
-
- pass
- if Platform.isWindows() and hasattr(sys, "frozen"):
- try:
- del os.environ["PYTHONPATH"]
- except KeyError:
- pass
- if Platform.isLinux() and hasattr(sys, "frozen"):
- os.chdir(os.path.expanduser("~"))
- if "PYTHONPATH" in os.environ.keys():
- PYTHONPATH = os.environ["PYTHONPATH"].split(os.pathsep)
- PYTHONPATH.reverse()
- for PATH in PYTHONPATH:
- PATH_real = os.path.realpath(PATH)
- if PATH_real in sys.path:
- sys.path.remove(PATH_real)
- sys.path.insert(1, PATH_real)
- def exceptHook(hook_type, value, traceback):
- from cura.CrashHandler import CrashHandler
- from cura.CuraApplication import CuraApplication
- has_started = False
- if CuraApplication.Created:
- has_started = CuraApplication.getInstance().started
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- from PyQt5.Qt import QApplication
- if CuraApplication.Created:
- _crash_handler = CrashHandler(hook_type, value, traceback, has_started)
- if CuraApplication.splash is not None:
- CuraApplication.splash.close()
- if not has_started:
- CuraApplication.getInstance().removePostedEvents(None)
- _crash_handler.early_crash_dialog.show()
- sys.exit(CuraApplication.getInstance().exec_())
- else:
- _crash_handler.show()
- else:
- application = QApplication(sys.argv)
- application.removePostedEvents(None)
- _crash_handler = CrashHandler(hook_type, value, traceback, has_started)
-
- if CuraApplication.splash is not None:
- CuraApplication.splash.close()
- _crash_handler.early_crash_dialog.show()
- sys.exit(application.exec_())
- sys.excepthook = exceptHook
- if sys.stderr and not sys.stderr.closed:
- faulthandler.enable(file = sys.stderr, all_threads = True)
- elif sys.stdout and not sys.stdout.closed:
- faulthandler.enable(file = sys.stdout, all_threads = True)
- from cura.CuraApplication import CuraApplication
- if Platform.isOSX() and getattr(sys, "frozen", False):
- old_env = os.environ.get("DYLD_FALLBACK_LIBRARY_PATH", "")
-
- search_path = os.path.join(CuraApplication.getInstallPrefix(), "MacOS")
- path_list = old_env.split(":")
- if search_path not in path_list:
- path_list.append(search_path)
- os.environ["DYLD_FALLBACK_LIBRARY_PATH"] = ":".join(path_list)
- import trimesh.exchange.load
- os.environ["DYLD_FALLBACK_LIBRARY_PATH"] = old_env
- if Platform.isLinux() and getattr(sys, "frozen", False):
- old_env = os.environ.get("LD_LIBRARY_PATH", "")
-
- search_path = os.path.join(CuraApplication.getInstallPrefix(), "bin")
- path_list = old_env.split(":")
- if search_path not in path_list:
- path_list.append(search_path)
- os.environ["LD_LIBRARY_PATH"] = ":".join(path_list)
- import trimesh.exchange.load
- os.environ["LD_LIBRARY_PATH"] = old_env
- if Platform.isLinux():
- os.environ["QT_QUICK_CONTROLS_STYLE"] = "default"
-
- if ApplicationMetadata.CuraDebugMode:
- ssl_conf = QSslConfiguration.defaultConfiguration()
- ssl_conf.setPeerVerifyMode(QSslSocket.VerifyNone)
- QSslConfiguration.setDefaultConfiguration(ssl_conf)
- app = CuraApplication()
- app.run()
|