Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5486857

Browse files
committed
This script will check to see if all of the environment variables I require are set
1 parent eaffd49 commit 5486857

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

env_check.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Script Name : env_check.py
2+
# Author : Craig Richards
3+
# Created : 14th May 2012
4+
# Last Modified :
5+
# Version : 1.0
6+
7+
# Modifications :
8+
9+
# Description : This script will check to see if all of the environment variables I require are set
10+
11+
import os
12+
13+
confdir = os.getenv("my_config") # Set the variable confdir from the OS environment variable
14+
conffile = 'env_check.conf' # Set the variable conffile
15+
conffilename=os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together
16+
17+
for env_check in open(conffilename): # Open the config file and read all the settings
18+
env_check = env_check.strip() # Set the variable as itsself, but strip the extra text out
19+
print '[{}]'.format(env_check) # Format the Output to be in Square Brackets
20+
newenv = os.getenv(env_check) # Set the variable newenv to get the settings from the OS what is currently set for the settings out the configfile
21+
if newenv is None: # If it doesn't exist
22+
print env_check, 'is not set' # Print it is not set
23+
else: # Else if it does exist
24+
print 'Current Setting for {}={}\n'.format(env_check, newenv) # Print out the details

0 commit comments

Comments
 (0)