File: setupInitScriptUnix.py

package info (click to toggle)
meshroom 2025.1.1-1
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 5,196 kB
  • sloc: python: 14,951; javascript: 105; sh: 103; modula3: 53; makefile: 28
file content (47 lines) | stat: -rwxr-xr-x 1,966 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ------------------------------------------------------------------------------
# ConsoleSetLibPath.py
#   Initialization script for cx_Freeze which manipulates the path so that the
# directory in which the executable is found is searched for extensions but
# no other directory is searched. The environment variable LD_LIBRARY_PATH is
# manipulated first, however, to ensure that shared libraries found in the
# target directory are found. This requires a restart of the executable because
# the environment variable LD_LIBRARY_PATH is only checked at startup.
# ------------------------------------------------------------------------------

import os
import sys
import zipimport

FILE_NAME = sys.executable
DIR_NAME = os.path.dirname(sys.executable)

paths = os.environ.get("LD_LIBRARY_PATH", "").split(os.pathsep)

if DIR_NAME not in paths:
    paths.insert(0, DIR_NAME)
    paths.insert(0, os.path.join(DIR_NAME, "lib"))
    paths.insert(0, os.path.join(DIR_NAME, "aliceVision", "lib"))
    paths.insert(0, os.path.join(DIR_NAME, "aliceVision", "lib64"))
    paths.insert(0, os.path.join(DIR_NAME, "lib", "PySide6", "Qt", "qml", "QtQuick", "Dialogs"))

    os.environ["LD_LIBRARY_PATH"] = os.pathsep.join(paths)
    os.environ["PYTHONPATH"] = os.path.join(DIR_NAME, "aliceVision", "lib", "python") + os.pathsep + os.path.join(DIR_NAME, "aliceVision", "lib", "python3.11", "site-packages")
    os.execv(sys.executable, sys.argv)

sys.frozen = True
sys.path = sys.path[:6]


def run(*args):
    m = __import__("__main__")
    importer = zipimport.zipimporter(DIR_NAME + "/lib/library.zip")
    if len(args) == 0:
        name, ext = os.path.splitext(os.path.basename(os.path.normcase(FILE_NAME)))
        moduleName = "%s__main__" % name
    else:
        moduleName = args[0]
    pythonPaths = os.getenv("PYTHONPATH", "").split(os.pathsep)
    for p in pythonPaths:
        sys.path.append(p)
    code = importer.get_code(moduleName)
    exec(code, m.__dict__)