From a825804dcf5fc5dc3baba64f7e23a2de2588d41a Mon Sep 17 00:00:00 2001 From: SemvdH Date: Sun, 16 Nov 2025 13:18:07 +0100 Subject: [PATCH] add initial scripts --- change-track.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ enter_cars.py | 52 +++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 change-track.py create mode 100644 enter_cars.py diff --git a/change-track.py b/change-track.py new file mode 100644 index 0000000..1067ad7 --- /dev/null +++ b/change-track.py @@ -0,0 +1,72 @@ +import sys +from subprocess import call +import os + +length = len(sys.argv) +newname = sys.argv[1].strip() +config = "" +lines = {} + +if length > 2: + config = sys.argv[2].strip() + +if length <= 1: + print("did not supply correct arguments!") + sys.exit(-1) + +dirs = [x.path.replace("/home/sem/assetto-corsa/content/tracks/","") for x in os.scandir('/home/sem/assetto-corsa/content/tracks/') if x.is_dir()] +dirs.sort() + +resetname = False +if str(newname) not in dirs: + print("===== ERROR: the provided map was not found! =====") + print("===== You can try again and choose from one of the following: =====") + for dir in dirs: + print("\t" + dir) + print("===== For now, I'll set it to the drift map =====") + newname = "drift" + config = "" + resetname = True + +if resetname == False and len(config) > 0: + configdirs = [x.path.replace("/home/sem/assetto-corsa/content/tracks/" + newname + "/","") for x in os.scandir('/home/sem/assetto-corsa/content/tracks/' + newname + '/') if x.is_dir()] + configdirs.sort() + standard_folders = {'ai', 'ui', 'extension', 'data', 'skins','texture'} + for s in standard_folders: + if s in configdirs: + configdirs.remove(s) + if (len(configdirs) == 0): + print("===== The map you entered does not have a config! =====") + config = "" + + elif (config not in configdirs): + print("===== ERROR: provided config was not found in the map folder! =====") + print("===== If you're sure it has one, maybe try one of these? =====") + for cd in configdirs: + print("\t" + cd) + print("===== To make it easy, I'll choose the first one for now: " + configdirs[0] + " =====") + config = configdirs[0] + +new_content = "" +with open('/home/sem/assetto-corsa/cfg/server_cfg.ini','r') as file: + for line in file: + line = line.strip() + if line.startswith("TRACK="): + new_content += "TRACK=" + str(newname) + print("changing line " + line + " to " + "TRACK=" + str(newname)) + elif line.startswith("CONFIG_TRACK="): + if (len(config) > 1): + new_content +="CONFIG_TRACK=" + str(config) + print("changing line " + line + " to " + "CONFIG_TRACK=" + str(config)) + else: + new_content += "CONFIG_TRACK=" + print("no config entered, setting config line to CONFIG_TRACK=") + else: + new_content += line + new_content += "\n" + +with open('/home/sem/assetto-corsa/cfg/server_cfg.ini','w') as newfile: + print("applying changes...") + newfile.write(new_content) + +print("===== Successfully updated map! Don't forget to restart the server! (It's the button to the left of the one you just pressed) =====") \ No newline at end of file diff --git a/enter_cars.py b/enter_cars.py new file mode 100644 index 0000000..b373acb --- /dev/null +++ b/enter_cars.py @@ -0,0 +1,52 @@ +import os + +class Car: + def __init__(self, name, skin, number): + self.name = name + self.skin = skin + self.number = number + + def __str__(self): + return f"[CAR_{self.number}]\nMODEL={self.name}\nSKIN={self.skin}\nSPECTATOR_MODE=0\nDRIVERNAME=\nTEAM=\nGUID=\nBALLAST=0\nAI=auto\n" + + +cars = input("enter car string list: ").split(';') + +currentcar = 0 +dirs = [x.path.replace("/home/sem/assetto-corsa/content/cars/", "") + for x in os.scandir('/home/sem/assetto-corsa/content/cars/') if x.is_dir()] +dirs.sort() +# print(dirs) +finalcars = [] +for i in range(0, len(cars)): + + if cars[i] in dirs: + print("############################################\n\n") + print("found car: " + cars[i]) + car_skins = [x.path.replace("/home/sem/assetto-corsa/content/cars/" + cars[i] + "/skins/", "") + for x in os.scandir('/home/sem/assetto-corsa/content/cars/' + cars[i] + "/skins/") if x.is_dir()] + print("skins for car " + cars[i] + "\n") + + for skin in range(0, len(car_skins)): + print(str(skin) + " " + car_skins[skin]) + amount = int(input("enter amount of this car you want: ")) + for j in range(0, amount): + + skin = int(input("Enter skin number for " + + cars[i] + "(car " + str(currentcar) + ") :")) + print("set car skin to " + car_skins[skin]) + finalcars.append(Car(cars[i], car_skins[skin], currentcar)) + currentcar += 1 + + else: + print("car " + cars[i] + " not found") + continue +print("CARS LIST:\n\n\n") +for car in finalcars: + print(str(car)) +print("\n\n\n") +with open("entry_list.ini","w") as f: + for car in finalcars: + f.write(str(car)) + +print("cars wrote to entry_list.ini") \ No newline at end of file