add initial scripts
This commit is contained in:
72
change-track.py
Normal file
72
change-track.py
Normal file
@@ -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) =====")
|
||||
Reference in New Issue
Block a user