Added python script to edit uproject file.

This commit is contained in:
Axel 2020-12-11 12:17:17 +01:00 committed by Axel1092
parent c0c24f6756
commit bffd921958
6 changed files with 80 additions and 7 deletions

View File

@ -12,6 +12,7 @@ Plugins/Carla/Debug
Plugins/Carla/DerivedDataCache
Plugins/Carla/Intermediate
Plugins/Carla/Saved
CarlaUE4.uproject
/Content
Config/CarlaSettings.ini

View File

@ -106,8 +106,10 @@ if %BUILD_UE4_EDITOR% == true (
echo %FILE_N% Building Unreal Editor...
if %USE_CARSIM% == true (
py -3 %ROOT_PATH%../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
echo CarSim ON > "%ROOT_PATH%Unreal/CarlaUE4/Config/CarSimConfig.ini"
) else (
py -3 %ROOT_PATH%../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject"
echo CarSim OFF > "%ROOT_PATH%Unreal/CarlaUE4/Config/CarSimConfig.ini"
)

View File

@ -117,13 +117,15 @@ fi
if ${BUILD_CARLAUE4} ; then
if [ ! -f Makefile ]; then
if ${USE_CARSIM} ; then
python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
echo "CarSim ON" > ${PWD}/Config/CarSimConfig.ini
else
python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject"
echo "CarSim OFF" > ${PWD}/Config/CarSimConfig.ini
fi
if ${USE_CARSIM} ; then
echo "CarSim ON" > ${PWD}/Config/CarSimConfig.ini
else
echo "CarSim OFF" > ${PWD}/Config/CarSimConfig.ini
fi
if [ ! -f Makefile ]; then
# This command fails sometimes but normally we can continue anyway.
set +e

View File

@ -100,8 +100,10 @@ rem ============================================================================
if %DO_PACKAGE%==true (
if %USE_CARSIM% == true (
py -3 %ROOT_PATH%../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
echo CarSim ON > "%ROOT_PATH%Unreal/CarlaUE4/Config/CarSimConfig.ini"
) else (
py -3 %ROOT_PATH%../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject"
echo CarSim OFF > "%ROOT_PATH%Unreal/CarlaUE4/Config/CarSimConfig.ini"
)

View File

@ -91,9 +91,11 @@ if ${DO_CARLA_RELEASE} ; then
pushd "${CARLAUE4_ROOT_FOLDER}" >/dev/null
if [ ${USE_CARSIM} ]; then
if ${USE_CARSIM} ; then
python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject" -e
echo "CarSim ON" > ${PWD}/Config/CarSimConfig.ini
else
python ${PWD}/../../Util/BuildTools/enable_carsim_to_uproject.py -f="CarlaUE4.uproject"
echo "CarSim OFF" > ${PWD}/Config/CarSimConfig.ini
fi

View File

@ -0,0 +1,64 @@
#!/usr/bin/env python
# Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma de
# Barcelona (UAB).
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
import glob
import os
import sys
import argparse
import json
def main():
"""Edits the uproject file to enable and disable the CarSim plugin
"""
argparser = argparse.ArgumentParser()
argparser.add_argument(
'-f', '--file',
metavar='F',
default="",
type=str,
help='Path to the uproject file')
argparser.add_argument(
'-e', '--enable',
action='store_true',
help='enable carsim')
args = argparser.parse_args()
# Read uproject (json) file
uproject_file = open(args.file, 'r')
uproject_json = json.load(uproject_file)
uproject_file.close()
# Get the plugin list
plugin_list = uproject_json["Plugins"]
# Edit plugin
should_do_changes = False
carsim_found = False
for plugin in plugin_list:
if plugin['Name'] == 'CarSim':
if args.enable:
if not plugin['Enabled']:
should_do_changes = True
plugin['Enabled'] = True
else:
if plugin['Enabled']:
should_do_changes = True
plugin['Enabled'] = False
carsim_found = True
if not carsim_found and args.enable:
should_do_changes = True
plugin_list.append({'Name':'CarSim', 'MarketplaceURL': 'com.epicgames.launcher://ue/marketplace/content/2d712649ca864c80812da7b5252f5608', "Enabled": True})
# Save file if there are changes to do
if should_do_changes:
uproject_file = open(args.file, 'w')
uproject_file.write(json.dumps(uproject_json, indent = 4, sort_keys=True))
uproject_file.close()
if __name__ == '__main__':
main()