<commit_before>#!/usr/bin env python

import os, sys, fileinput

def makeFileFromTemplate(path, newPath, placeholder, name):
	templatefile = open(path, 'r')
	outputFile = open(newPath, 'w')
	outputFile.writelines([line.replace(placeholder, name) for line in templatefile.readlines()])

def makeModuleFile(rootpath, name, filepath, extension, templatefilepath):
	modPath = os.path.join(rootpath, filepath)
	modFile = os.path.join(modPath, name + extension)
	templatefile = os.path.join(modPath, templatefilepath)
	makeFileFromTemplate(templatefile, modFile, "@ModuleName@", name)
	print("module file: ", modFile)

def makeModuleHeaderFile(path, name):
	makeModuleFile(path, name, "Modules/Fields/", ".h", "../Template/ModuleTemplate.h")

def makeModuleSourceFile(path, name):
	makeModuleFile(path, name, "Modules/Fields/", ".cc", "../Template/ModuleTemplate.cc")

def makeModuleUnitTestFile(path, name):
	makeModuleFile(path, name, "Modules/Fields/Tests", "Tests.cc", "../../Template/ModuleUnitTest.cc")

def editCMake(file, name, srcLine, headerLine, doHeader):
  for line in fileinput.input(file, inplace=True):
    line = line.replace(srcLine, srcLine + "\n  " + name + ".cc")
    if doHeader:
      line = line.replace(headerLine, headerLine + "\n  " + name + ".h")
    sys.stdout.write(line)
  print("cmake edit: ", file, name)

def editModuleCMake(path, name):
  modPath = os.path.join(path, "Modules/Fields/")
  cmakeFile = os.path.join(modPath, "CMakeLists.txt")
  replaceLineSrc = "SET(Modules_Fields_SRCS"
  replaceLineHeader = "SET(Modules_Fields_HEADERS"
  editCMake(cmakeFile, name, replaceLineSrc, replaceLineHeader, True)

def editModuleTestCMake(path, name):
  modPath = os.path.join(path, "Modules/Fields/Tests/")
  cmakeFile = os.path.join(modPath, "CMakeLists.txt")
  replaceLineSrc = "SET(Modules_Fields_Tests_SRCS"
  editCMake(cmakeFile, name + "Tests", replaceLineSrc, "", False)

def addModuleToFactory(path, name):
  factorypath = os.path.join(path, "Modules/Factory/ModuleFactoryImpl1.cc") #factoryfile = open(factorypath, 'w')
  replaceLine1 = "//#include <Modules/Fields/@ModuleName@.h>"
  replaceLine2 = "  // insert module desc here"
  for line in fileinput.input(factorypath, inplace=True):
    line = line.replace(replaceLine1, "#include <Modules/Fields/" + name + ".h>\n" + replaceLine1)
    line = line.replace(replaceLine2, "  addModuleDesc<" + name + ">(\"Status\", \"Description\");\n" + replaceLine2)
    sys.stdout.write(line)
  print("module factory edit: ", factorypath, name)

def makeAlgorithmFile(rootpath, name, filepath, extension, templatefilepath):
	algoPath = os.path.join(rootpath, filepath)
	algoFile = os.path.join(algoPath, name + extension)
	templatefile = os.path.join(algoPath, templatefilepath)
	makeFileFromTemplate(templatefile, algoFile, "@AlgorithmName@", name)
	print("algorithm file: ", algoFile)

def makeAlgorithmHeaderFile(path, name):
	makeAlgorithmFile(path, name, "Core/Algorithms/Field/", "Algo.h", "../Template/AlgorithmTemplate.h")

def makeAlgorithmSourceFile(path, name):
	makeAlgorithmFile(path, name, "Core/Algorithms/Field/", "Algo.cc", "../Template/AlgorithmTemplate.cc")

def makeAlgorithmUnitTestFile(path, name):
	makeAlgorithmFile(path, name, "Core/Algorithms/Field/Tests/", "AlgoTests.cc", "../../Template/AlgorithmTestTemplate.cc")

def editAlgorithmCMake(path, name):
	modPath = os.path.join(path, "Core/Algorithms/Field/")
	cmakeFile = os.path.join(modPath, "CMakeLists.txt")
	replaceLineSrc = "SET(Algorithms_Field_SRCS"
	replaceLineHeader = "SET(Algorithms_Field_HEADERS"
	editCMake(cmakeFile, name + "Algo", replaceLineSrc, replaceLineHeader, True)
	print("algorithm cmake edit: ", path, name)

def editAlgorithmTestCMake(path, name):
  modPath = os.path.join(path, "Core/Algorithms/Field/Tests/")
  cmakeFile = os.path.join(modPath, "CMakeLists.txt")
  replaceLineSrc = "SET(Algorithms_Field_Tests_SRCS"
  editCMake(cmakeFile, name + "AlgoTests", replaceLineSrc, "", False)

def addAlgorithmToFactory(path, name):
	uiPath = os.path.join(path, "Core/Algorithms/Factory")
	print("algorithm factory edit: ", uiPath, name)

def makeUIDesignerFile(path, name):
	print("ui designer file: ", path, name)

def makeUIHeaderFile(path, name):
	uiPath = os.path.join(path, "Interface/Modules/Fields/")
	print("ui header", uiPath, name)

def makeUISourceFile(path, name):
	uiPath = os.path.join(path, "Interface/Modules/Fields/")
	print("ui source: ", uiPath, name)

def editUICMake(path, name):
	uiPath = os.path.join(path, "Interface/Modules/Fields/")
	print("UI cmake edit: ", uiPath, name)

def addUIToFactory(path, name):
	uiPath = os.path.join(path, "Interface/Modules/Factory/")
	print("UI factory edit: ", uiPath, name)

def makeModuleFiles(path, name):
	makeModuleHeaderFile(path, name)
	makeModuleSourceFile(path, name)
	makeModuleUnitTestFile(path, name)
	editModuleCMake(path, name)<commit_msg>algo factory attempt<commit_after>#!/usr/bin env python

import os, sys, fileinput

def makeFileFromTemplate(path, newPath, placeholder, name):
	templatefile = open(path, 'r')
	outputFile = open(newPath, 'w')
	outputFile.writelines([line.replace(placeholder, name) for line in templatefile.readlines()])

def makeModuleFile(rootpath, name, filepath, extension, templatefilepath):
	modPath = os.path.join(rootpath, filepath)
	modFile = os.path.join(modPath, name + extension)
	templatefile = os.path.join(modPath, templatefilepath)
	makeFileFromTemplate(templatefile, modFile, "@ModuleName@", name)
	print("module file: ", modFile)

def makeModuleHeaderFile(path, name):
	makeModuleFile(path, name, "Modules/Fields/", ".h", "../Template/ModuleTemplate.h")

def makeModuleSourceFile(path, name):
	makeModuleFile(path, name, "Modules/Fields/", ".cc", "../Template/ModuleTemplate.cc")

def makeModuleUnitTestFile(path, name):
	makeModuleFile(path, name, "Modules/Fields/Tests", "Tests.cc", "../../Template/ModuleUnitTest.cc")

def editCMake(file, name, srcLine, headerLine, doHeader):
  for line in fileinput.input(file, inplace=True):
    line = line.replace(srcLine, srcLine + "\n  " + name + ".cc")
    if doHeader:
      line = line.replace(headerLine, headerLine + "\n  " + name + ".h")
    sys.stdout.write(line)
  print("cmake edit: ", file, name)

def editModuleCMake(path, name):
  modPath = os.path.join(path, "Modules/Fields/")
  cmakeFile = os.path.join(modPath, "CMakeLists.txt")
  replaceLineSrc = "SET(Modules_Fields_SRCS"
  replaceLineHeader = "SET(Modules_Fields_HEADERS"
  editCMake(cmakeFile, name, replaceLineSrc, replaceLineHeader, True)

def editModuleTestCMake(path, name):
  modPath = os.path.join(path, "Modules/Fields/Tests/")
  cmakeFile = os.path.join(modPath, "CMakeLists.txt")
  replaceLineSrc = "SET(Modules_Fields_Tests_SRCS"
  editCMake(cmakeFile, name + "Tests", replaceLineSrc, "", False)

def addModuleToFactory(path, name):
  factorypath = os.path.join(path, "Modules/Factory/ModuleFactoryImpl1.cc")
  replaceLine1 = "//#include <Modules/Fields/@ModuleName@.h>"
  replaceLine2 = "  // insert module desc here"
  for line in fileinput.input(factorypath, inplace=True):
    line = line.replace(replaceLine1, "#include <Modules/Fields/" + name + ".h>\n" + replaceLine1)
    line = line.replace(replaceLine2, "  addModuleDesc<" + name + ">(\"Status\", \"Description\");\n" + replaceLine2)
    sys.stdout.write(line)
  print("module factory edit: ", factorypath, name)

def makeAlgorithmFile(rootpath, name, filepath, extension, templatefilepath):
	algoPath = os.path.join(rootpath, filepath)
	algoFile = os.path.join(algoPath, name + extension)
	templatefile = os.path.join(algoPath, templatefilepath)
	makeFileFromTemplate(templatefile, algoFile, "@AlgorithmName@", name)
	print("algorithm file: ", algoFile)

def makeAlgorithmHeaderFile(path, name):
	makeAlgorithmFile(path, name, "Core/Algorithms/Field/", "Algo.h", "../Template/AlgorithmTemplate.h")

def makeAlgorithmSourceFile(path, name):
	makeAlgorithmFile(path, name, "Core/Algorithms/Field/", "Algo.cc", "../Template/AlgorithmTemplate.cc")

def makeAlgorithmUnitTestFile(path, name):
	makeAlgorithmFile(path, name, "Core/Algorithms/Field/Tests/", "AlgoTests.cc", "../../Template/AlgorithmTestTemplate.cc")

def editAlgorithmCMake(path, name):
	modPath = os.path.join(path, "Core/Algorithms/Field/")
	cmakeFile = os.path.join(modPath, "CMakeLists.txt")
	replaceLineSrc = "SET(Algorithms_Field_SRCS"
	replaceLineHeader = "SET(Algorithms_Field_HEADERS"
	editCMake(cmakeFile, name + "Algo", replaceLineSrc, replaceLineHeader, True)
	print("algorithm cmake edit: ", path, name)

def editAlgorithmTestCMake(path, name):
  modPath = os.path.join(path, "Core/Algorithms/Field/Tests/")
  cmakeFile = os.path.join(modPath, "CMakeLists.txt")
  replaceLineSrc = "SET(Algorithms_Field_Tests_SRCS"
  editCMake(cmakeFile, name + "AlgoTests", replaceLineSrc, "", False)

def addAlgorithmToFactory(path, name):
	factorypath = os.path.join(path, "Core/Algorithms/Factory/HardCodedAlgorithmFactory.cc")
	replaceLine1 = "#include <boost/functional/factory.hpp>"
	replaceLine2 = "    ;"
	for line in fileinput.input(factorypath, inplace=True):
		line = line.replace(replaceLine1, "#include <Core/Algorithms/Field/" + name + "Algo.h>\n" + replaceLine1)
		line = line.replace(replaceLine2, "      ADD_MODULE_ALGORITHM(" + name + ", " + name + "Algo)\n" + replaceLine2)
		sys.stdout.write(line)
	print("algo factory edit: ", factorypath, name)

def makeUIDesignerFile(path, name):
	print("ui designer file: ", path, name)

def makeUIHeaderFile(path, name):
	uiPath = os.path.join(path, "Interface/Modules/Fields/")
	print("ui header", uiPath, name)

def makeUISourceFile(path, name):
	uiPath = os.path.join(path, "Interface/Modules/Fields/")
	print("ui source: ", uiPath, name)

def editUICMake(path, name):
	uiPath = os.path.join(path, "Interface/Modules/Fields/")
	print("UI cmake edit: ", uiPath, name)

def addUIToFactory(path, name):
	uiPath = os.path.join(path, "Interface/Modules/Factory/")
	print("UI factory edit: ", uiPath, name)

def makeModuleFiles(path, name):
	makeModuleHeaderFile(path, name)
	makeModuleSourceFile(path, name)
	makeModuleUnitTestFile(path, name)
	editModuleCMake(path, name)
{'fraction_non_alphanumeric': 0.1495271867612293, 'fraction_numerical': 0.001970055161544523, 'mean_word_length': 5.827841291190316, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '973950', 'n_tokens_mistral': 3419, 'n_tokens_neox': 3426, 'n_words': 694}