<commit_before>#!/usr/bin env python

# import glob
import os, sys, fileinput
# import time
# import SCIRunPythonAPI; from SCIRunPythonAPI import *
#
# def allFields(path):
# 	names = []
# 	for dirname, dirnames, filenames in os.walk(path):
# 		for filename in filenames:
# 			if filename.endswith("fld"):
# 				names.append(os.path.join(dirname, filename))
# 	return names
#
# def printList(list, name):
# 	thefile = open(name, 'w')
# 	for f,v in list:
# 		thefile.write("%s\n\t%s\n" % (f,v))
#

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 makeModuleHeaderFile(path, name):
	modPath = os.path.join(path, "Modules/Fields/")
	modFile = os.path.join(modPath, name + ".h")
	templatefile = os.path.join(modPath, "../Template/ModuleTemplate.h")
	makeFileFromTemplate(templatefile, modFile, "@ModuleName@", name)
	print("module header: ", modFile)

def makeModuleSourceFile(path, name):
	modPath = os.path.join(path, "Modules/Fields/")
	modFile = os.path.join(modPath, name + ".cc")
	templatefile = os.path.join(modPath, "../Template/ModuleTemplate.cc")
	makeFileFromTemplate(templatefile, modFile, "@ModuleName@", name)
	print("module source: ", modFile)

def makeModuleUnitTestFile(path, name):
  modPath = os.path.join(path, "Modules/Fields/Tests/")
  modFile = os.path.join(modPath, name + "Test.cc")
  templatefile = os.path.join(modPath, "../../Template/ModuleUnitTest.cc")
  makeFileFromTemplate(templatefile, modFile, "@ModuleName@", name)
  print("module unit test: ", modFile)

#def editModuleCMake(path, name):
#	print("module cmake edit: ", path, name)

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 makeAlgorithmHeaderFile(path, name):
	algoPath = os.path.join(path, "Core/Algorithms/Field/")
	algoFile = os.path.join(algoPath, name + "Algo.h")
	print("algo header: ", algoFile)

def makeAlgorithmSourceFile(path, name):
	algoPath = os.path.join(path, "Core/Algorithms/Field/")
	algoFile = os.path.join(algoPath, name + "Algo.cc")
	print("algo source: ", algoFile)

def makeAlgorithmUnitTestFile(path, name):
	algoPath = os.path.join(path, "Core/Algorithms/Field/Tests/")
	algoFile = os.path.join(algoPath, name + "AlgoTest.cc")
	print("algo unit test: ", algoFile)

def editAlgorithmCMake(path, name):
	print("algorithm cmake edit: ", path, name)

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)
	addModuleToFactory(path, name)

def makeAlgorithmFiles(path, name):<commit_msg>Improve script to avoid glob (part 1)<commit_after>#!/usr/bin env python

# import glob
import os, sys, fileinput
# import time
# import SCIRunPythonAPI; from SCIRunPythonAPI import *
#
# def allFields(path):
# 	names = []
# 	for dirname, dirnames, filenames in os.walk(path):
# 		for filename in filenames:
# 			if filename.endswith("fld"):
# 				names.append(os.path.join(dirname, filename))
# 	return names
#
# def printList(list, name):
# 	thefile = open(name, 'w')
# 	for f,v in list:
# 		thefile.write("%s\n\t%s\n" % (f,v))
#

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 makeModuleHeaderFile(path, name):
	modPath = os.path.join(path, "Modules/Fields/")
	modFile = os.path.join(modPath, name + ".h")
	templatefile = os.path.join(modPath, "../Template/ModuleTemplate.h")
	makeFileFromTemplate(templatefile, modFile, "@ModuleName@", name)
	print("module header: ", modFile)

def makeModuleSourceFile(path, name):
	modPath = os.path.join(path, "Modules/Fields/")
	modFile = os.path.join(modPath, name + ".cc")
	templatefile = os.path.join(modPath, "../Template/ModuleTemplate.cc")
	makeFileFromTemplate(templatefile, modFile, "@ModuleName@", name)
	print("module source: ", modFile)

def makeModuleUnitTestFile(path, name):
  modPath = os.path.join(path, "Modules/Fields/Tests/")
  modFile = os.path.join(modPath, name + "Test.cc")
  templatefile = os.path.join(modPath, "../../Template/ModuleUnitTest.cc")
  makeFileFromTemplate(templatefile, modFile, "@ModuleName@", name)
  print("module unit test: ", modFile)

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"
  for line in fileinput.input(cmakeFile, inplace=True):
    line = line.replace(replaceLineSrc, replaceLineSrc + "\n  " + name + ".cc")
    line = line.replace(replaceLineHeader, replaceLineHeader + "\n  " + name + ".h")
    sys.stdout.write(line)
  print("module cmake edit: ", path, name)

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 makeAlgorithmHeaderFile(path, name):
	algoPath = os.path.join(path, "Core/Algorithms/Field/")
	algoFile = os.path.join(algoPath, name + "Algo.h")
	print("algo header: ", algoFile)

def makeAlgorithmSourceFile(path, name):
	algoPath = os.path.join(path, "Core/Algorithms/Field/")
	algoFile = os.path.join(algoPath, name + "Algo.cc")
	print("algo source: ", algoFile)

def makeAlgorithmUnitTestFile(path, name):
	algoPath = os.path.join(path, "Core/Algorithms/Field/Tests/")
	algoFile = os.path.join(algoPath, name + "AlgoTest.cc")
	print("algo unit test: ", algoFile)

def editAlgorithmCMake(path, name):
	print("algorithm cmake edit: ", path, name)

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)
	addModuleToFactory(path, name)

def makeAlgorithmFiles(path, name):
{'fraction_non_alphanumeric': 0.1575714623198677, 'fraction_numerical': 0.001771793054571226, 'mean_word_length': 5.347076461769116, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6434242', 'n_tokens_mistral': 2976, 'n_tokens_neox': 2970, 'n_words': 633}