<commit_before>import sys
import os

VIEW_EXTENSION = ".cshtml"

FILES_TO_SEARCH = [".cshtml", "Controller.cs"]

def main(argv):
	directory = argv[0]

	views = find_view_files_in_directory(directory)

	print("Locating view files...")
	print_break()

	print("View files found: {0}".format(len(views)))
	print_break()

	print("Finding unused views...")
	print_break()

	for view_filename in views:
		references, looked_at = find_references_for_view_file(directory, view_filename)

		if not references:
			print("UNUSED VIEW: ", view_filename)
			print_break()

def print_break():
	print("-" * 45)

def find_references_for_view_file(directory, viewfilename):
	references = []
	looking_in = []

	for root, directories, files in os.walk(directory):
		for filename in [f for f in files if any([f.endswith(ext) for ext in FILES_TO_SEARCH]) and not f == viewfilename + VIEW_EXTENSION]:
			looking_in.append(os.path.join(root, filename))
			with open(os.path.join(root, filename), 'r', encoding="utf-8") as searchfile:
				linenumber = 0
				for line in searchfile:
					linenumber += 1
					if viewfilename in line :
						references.append((filename, linenumber, line))

	return (references, looking_in)


def find_view_files_in_directory(directory):
	views = []

	for root, directories, files in os.walk(directory):
		for filename in [f for f in files if f.endswith(VIEW_EXTENSION)]:
			views.append(filename.replace(VIEW_EXTENSION, ""))

	return views

if __name__ == "__main__":
	if len(sys.argv) == 1:
		sys.exit("Argument required: application path")<commit_msg>looking up for unused files<commit_after>import sys
import os

LOOKUP_EXTENSIONS = [".cshtml", ".gif", ".jpg", ".png", ".js", ".css"]
FILES_TO_SEARCH = [".cshtml", "Controller.cs", ".css", ".less", ".js"]

def main(argv):
	directory = argv[0]

	files_to_look_for = find_view_files_in_directory(directory)

	print_break()
	print("Loading files...")
	print_break()

	print("files to look for: {0}".format(len(files_to_look_for)))
	print_break()

	print("Looking for unused files...")
	print_break()

	results = {'using': [], 'not_using': []}

	for file_name in files_to_look_for:
		references, looked_at = find_references_for_view_file(directory, file_name)

		if not references:
			results['using'].append(file_name)
		else:
			results['not_using'].append(file_name)

	print("USING: {0} files".format(len(results['using'])))
	print("NOT USING: {0} files".format(len(results['not_using'])))

def print_break():
	print("-" * 45)

def find_references_for_view_file(directory, file_name):
	using = []
	looking_in = []

	for root, directories, files in os.walk(directory):
		for filename in [f for f in files if any([f.endswith(ext) for ext in FILES_TO_SEARCH])]:
			looking_in.append(os.path.join(root, filename))
			with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as searchfile:
				content = searchfile.read()
				if file_name in content:
					using.append(filename)

	return (using, looking_in)


def find_view_files_in_directory(directory):
	views = []

	for root, directories, files in os.walk(directory):
		for ext in LOOKUP_EXTENSIONS:
			for filename in [f for f in files if f.endswith(ext)]:
				views.append(filename)

	return views

if __name__ == "__main__":
	if len(sys.argv) == 1:
		sys.exit("Argument required: application path")
{'fraction_non_alphanumeric': 0.14040373606507983, 'fraction_numerical': 0.006025911419102139, 'mean_word_length': 4.9391771019677995, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3537489', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1127, 'n_words': 285}