Skip to content

Commit 511c86a

Browse files
author
Ben Supnik
committed
New script allows running the add-on out of the GIT directory directly, avoiding
install hassle.
1 parent 22495ef commit 511c86a

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

run.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# This is a small python script that launches Blender from the command line with the X-Plane exporter out of your GIT repo. This
2+
# saves having to work "in" the Blender add-ons dir, having to check out code to the Blender add-ons dir, or any fancy sim-linking.
3+
#
4+
# Like the test script, --blender lets you specify an executable, and it injects the code via the --addons flag, e.g.
5+
#
6+
# python3 run.py --blender /Applications/Blender.app/Contents/MacOS/Blender
7+
8+
import argparse
9+
import os
10+
import subprocess
11+
import sys
12+
13+
def _make_argparse():
14+
parser = argparse.ArgumentParser(description="Runs the XPlane2Blender test suite")
15+
blender_options = parser.add_argument_group("Blender Options")
16+
17+
blender_options.add_argument(
18+
"--blender",
19+
default="blender", # Use the blender in the system path
20+
type=str,
21+
help="Provide alternative path to Blender executable",
22+
)
23+
blender_options.add_argument(
24+
"--force-blender-debug",
25+
help="Turn on Blender's --debug flag",
26+
action="store_true",
27+
)
28+
blender_options.add_argument(
29+
"-n",
30+
"--no-factory-startup",
31+
help="Run Blender with current prefs rather than factory prefs",
32+
action="store_true",
33+
)
34+
return parser
35+
36+
37+
def main(argv=None) -> int:
38+
39+
if argv is None:
40+
argv = _make_argparse().parse_args(sys.argv[1:])
41+
42+
blender_args = [
43+
argv.blender,
44+
"--addons",
45+
"io_xplane2blender",
46+
"--factory-startup",
47+
]
48+
49+
if argv.no_factory_startup:
50+
blender_args.remove("--factory-startup")
51+
52+
if argv.force_blender_debug:
53+
blender_args.append("--debug")
54+
55+
# Small Hack!
56+
# Blender stops parsing after '--', so we can append the test runner
57+
# args and bridge the gap without anything fancy!
58+
blender_args.extend(["--"] + sys.argv[1:])
59+
60+
# print the command used to execute the script
61+
# to be able to easily re-run it manually to get better error output
62+
print(" ".join(blender_args))
63+
64+
# Environment variables - in order for --addons to work, we need to have OUR folder
65+
# exist, and we need to have "addons/modules" simlink BACK to us to create the illusion
66+
# of the directory structure Blender expects.
67+
enviro={"BLENDER_USER_SCRIPTS": os.path.dirname(os.path.realpath(__file__))}
68+
69+
# Run Blender, normalize output line endings because Windows is dumb
70+
out = subprocess.check_output(
71+
blender_args, stderr=subprocess.STDOUT, universal_newlines=True, env=enviro
72+
) # type: str
73+
74+
75+
main()
76+

0 commit comments

Comments
 (0)