Created
June 6, 2018 23:44
-
-
Save Jaxmetalmax/14199d353855730568e88d2dfc0487c6 to your computer and use it in GitHub Desktop.
script to check variables in env files before commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
listvars=[] | |
listexvars=[] | |
varsnotlisted=[] | |
my_path = os.path.abspath(os.path.dirname(__file__)) | |
filevar = os.path.join(my_path,"../../.env") | |
filevarex = os.path.join(my_path,"../../.env.example") | |
if not os.path.isfile(filevar): | |
print("File .env doesn't exist...") | |
exit(2) | |
if not os.path.isfile(filevarex): | |
print("File .env.example doesn't exist...") | |
exit(2) | |
with open(filevar, 'r') as fp: | |
read_lines = fp.readlines() | |
for var in read_lines: | |
if not var.strip(): | |
continue | |
elif '#' in var: | |
continue | |
else: | |
start = step = None | |
stop = var.find('=') | |
mycleanvar = var[start:stop:step] | |
listvars.append(mycleanvar) | |
with open(filevarex, 'r') as fp: | |
read_lines = fp.readlines() | |
for var in read_lines: | |
if not var.strip(): | |
continue | |
elif '#' in var: | |
continue | |
else: | |
start = step = None | |
stop = var.find('=') | |
mycleanvar = var[start:stop:step] | |
listexvars.append(mycleanvar) | |
for var in listvars: | |
if var not in listexvars: | |
varsnotlisted.append(var) | |
if len(varsnotlisted) > 0: | |
for var in varsnotlisted: | |
print("The variable {0} is not in var.example...".format(var)) | |
exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment