-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanVariables.py
More file actions
48 lines (34 loc) · 1.25 KB
/
cleanVariables.py
File metadata and controls
48 lines (34 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
Python Script to remove unused variables in pipeline templates
'''
import json
import sys
import os
import argparse
#Add parser arguments
parser = argparse.ArgumentParser()
parser.add_argument("-varFile",help="Location of variable file")
parser.add_argument("-directory",help="location of templates directory")
args = parser.parse_args()
if not args.varFile or not args.directory:
print("Missing OR wrong arguments. Use -h for help options")
exit()
InputFilename = args.varFile
directory = args.directory
with open(InputFilename, 'r') as inputFile:
content = json.loads(inputFile.read())
for everyKey in list(content):
counter = 0
for root, dirs, files in os.walk(directory):
for each_file in files:
input_file = os.path.join(directory, each_file)
with open(input_file, mode='r') as FileHandler:
file_content = FileHandler.read()
if everyKey in file_content:
counter = 1
if counter == 0:
print('We can delete: ' + str(everyKey))
del content[everyKey]
#print(json.dumps(content, indent=4))
with open(InputFilename, 'w') as outputFile:
outputFile.write(json.dumps(content, indent=4))