Skip to content

Commit 01686c5

Browse files
committed
slight refactor to improve code
1 parent c344618 commit 01686c5

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed

ssri/ssri.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def getTextForIncludeFile(templateFile): # Returns the contents of the template
241241

242242

243243
def writeTextToFiles(
244-
templateFile, fileList, verbose
244+
templateFile, fileList, verbose
245245
): # write the provided template file into the fileList (which is actually a set of named tuples)
246246
# TODO: Change this to do multithreading - will want to swap out from using fileinput when you do this though
247247
verbosePrint(verbose, "\n")
@@ -259,13 +259,12 @@ def writeTextToFiles(
259259
print(
260260
f"{CGREEN}{templateFile} successfully included in {len(fileList)} files {CEND}"
261261
)
262-
# numFilesChanged += 1
263262
elif len(fileList) == 1:
264263
print(
265264
f"{CGREEN}{templateFile} successfully included in {len(fileList)} file {CEND}"
266265
)
267266
# numFilesChanged += 1
268-
# return(numFilesChanged)
267+
269268

270269

271270
def copyFilesToNewLocation(newFileLocation, oldFileLocation):
@@ -351,7 +350,8 @@ def main():
351350
numFilesChanged = (
352351
0 # Number of files that have had include statements with modifications
353352
)
354-
global numWarnings
353+
numIncludeStatements = 0
354+
# global numWarnings
355355
numWarnings = 0
356356

357357
os.makedirs(os.path.dirname(args.output[0] + "/"), exist_ok=True)
@@ -397,45 +397,31 @@ def main():
397397
# First copy files to new location
398398
# print(filesToSearch)
399399
dictOfTemplatesToFiles = None
400-
if args.templates_dir is None: # Get templates from same dir as rest of html files
401-
for fileSearchIndex in range(len(filesToSearch[0])):
400+
for fileSearchIndex in range(len(filesToSearch[0])):
402401
copyFilesToNewLocation(
403402
filesToSearch[1][fileSearchIndex], filesToSearch[0][fileSearchIndex]
404403
)
405404
fileCreatedCounter += 1
406-
dictOfTemplatesToFiles, numFilesChanged, numWarnings = checkFilesForIncludes(
407-
filesToSearch[1], templatesDir[0], numFilesChanged, verbose, numWarnings
408-
) # this is a dictionary where key is include file an values is a named tuple with fileName and includeText from the files that ask for the key
409-
for template in dictOfTemplatesToFiles.items():
410-
writeTextToFiles(template[0], template[1], verbose)
411-
412-
# numFilesChanged =
405+
if args.templates_dir is None: # Get templates from same dir as rest of html files
406+
dictOfTemplatesToFiles, numFilesChanged, numWarnings = checkFilesForIncludes(filesToSearch[1], templatesDir[0], numFilesChanged, verbose, numWarnings) # this is a dictionary where key is include file an values is a named tuple with fileName and includeText from the files that ask for the key
413407
else:
414-
for fileSearchIndex in range(len(filesToSearch[0])):
415-
copyFilesToNewLocation(
416-
filesToSearch[1][fileSearchIndex], filesToSearch[0][fileSearchIndex]
417-
)
418-
fileCreatedCounter += 1
419-
dictOfTemplatesToFiles, numFilesChanged, numWarnings = checkFilesForIncludes(
420-
filesToSearch[1],
421-
args.templates_dir[0],
422-
numFilesChanged,
423-
verbose,
424-
numWarnings,
425-
) # this is a dictionary where key is include file an values is a named tuple with fileName and includeText from the files that ask for the key
426-
# print(dictOfTemplatesToFiles)
427-
for template in dictOfTemplatesToFiles.items():
428-
writeTextToFiles(template[0], template[1], verbose)
408+
dictOfTemplatesToFiles, numFilesChanged, numWarnings = checkFilesForIncludes(filesToSearch[1], args.templates_dir[0], numFilesChanged, verbose, numWarnings) # this is a dictionary where key is include file an values is a named tuple with fileName and includeText from the files that ask for the key
409+
410+
for template in dictOfTemplatesToFiles.items():
411+
writeTextToFiles(template[0], template[1], verbose)
412+
numIncludeStatements += len(template[1])
413+
429414

430415
if numWarnings == 0:
431416
printColour = CGREEN
432417
includeText = "✓"
433418
else:
434419
printColour = CRED
435420
includeText = "!"
421+
436422
if args.dir:
437423
print(
438-
f"{printColour}{includeText} Looked at {fileCreatedCounter} files in {args.inputFile[0]}, found {numFilesChanged} file(s) with include statements, and output files to {args.output[0]} {CEND}"
424+
f"{printColour}{includeText} Looked at {fileCreatedCounter} files in {args.inputFile[0]}, found {numFilesChanged} file(s) with include statements (with a total of {numIncludeStatements} include statements found), and output files to {args.output[0]} {CEND}"
439425
)
440426
if numWarnings == 1:
441427
print(f"{printColour}{includeText} {numWarnings} error encountered {CEND}")

0 commit comments

Comments
 (0)