JD2022-TU1/main/extern/UbiServices/custom/external/tools/templateClient/createNewClient.py

52 lines
1.8 KiB
Python

import os, sys
from shutil import copyfile
if(len(sys.argv) != 2):
print('Missing client name !!!')
print('Usage:')
print('>python createNewClient clientNameHere')
print('>Example: python createNewClient secondaryStore')
exit()
clientName = sys.argv[1]
print("New client name: " + clientName)
rootdir = os.getcwd()
print(rootdir)
for subdir, dirs, files in os.walk(rootdir):
for file in files:
filepath = subdir + os.sep + file
if filepath.endswith(".cpp") or filepath.endswith(".h"):
#print ("Source: " + filepath)
destinationPath = filepath.replace("external\\tools\\templateClient", "")
destinationPath = destinationPath.replace("\\templateClient\\", "\\" + clientName + "\\")
destinationPath = destinationPath.replace("template", clientName)
destinationPath = destinationPath.replace("Template", clientName.capitalize())
print("Destination: " + destinationPath)
try:
os.makedirs(os.path.dirname(destinationPath))
except FileExistsError:
# directory already exists
pass
copyfile(filepath, destinationPath)
# Update class name
with open(destinationPath, 'r') as file :
filedata = file.read()
filedata = filedata.replace("Template", clientName.capitalize())
filedata = filedata.replace("services/templateClient/", "services/" + clientName + "/")
filedata = filedata.replace("TEMPLATE", clientName.upper())
filedata = filedata.replace("template", clientName)
# Write the file out again
with open(destinationPath, 'w') as file:
file.write(filedata)
print("Done !!!")