Created
December 29, 2017 20:56
-
-
Save AKSarav/d265602ff299a7e12c4aee3a556a0a77 to your computer and use it in GitHub Desktop.
storeuserconfig_v2.py ( The Second One)
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 sys | |
import os | |
import re | |
from os.path import exists | |
from sys import argv | |
def conn(): | |
connect(USERNAME, PASSWORD, ADMINURL) | |
def store_custom(): | |
storeUserConfig(CONFIGFILE,KEYFILE) | |
def store_default(): | |
storeUserConfig() | |
def get_script_path(): | |
return os.path.dirname(os.path.realpath(sys.argv[0])) | |
def start(): | |
try: | |
global CONFIGFILE | |
global KEYFILE | |
global USERNAME | |
global PASSWORD | |
global ADMINURL | |
global DEFAULTFLAG | |
CONFIGFILE = _dict.get('configfile') | |
KEYFILE = _dict.get('keyfile') | |
USERNAME = _dict.get('username') | |
PASSWORD = _dict.get('password') | |
ADMINURL = _dict.get('adminurl') | |
DEFAULTFLAG = _dict.get('defaultflag') | |
if (DEFAULTFLAG != "ON"): | |
if (CONFIGFILE and KEYFILE and USERNAME and PASSWORD and ADMINURL): | |
print "\nINFO: Values have been set properly" | |
conn() | |
store_custom() | |
else: | |
print "\nERROR: Some Essential Keys are missing"; | |
else: | |
if (USERNAME and PASSWORD and ADMINURL): | |
print "\nValues have been set properly" | |
conn() | |
store_default() | |
else: | |
print "\nERROR: Some Essential Keys are missing"; | |
usage() | |
except: | |
print "\nERROR: Got Some Error! Please make sure you are executing the script right",sys.exc_info()[0] | |
usage() | |
# MAIN | |
_dict={} | |
propfile = get_script_path()+"/store.properties" | |
if exists(propfile): | |
fileobj = open(propfile, 'r+') | |
lines = fileobj.readlines() | |
for line in lines: | |
mat = re.search(r'(.+)(=)(.+)', line) | |
if mat: | |
line = line.rstrip() | |
key = line.split('=')[0] | |
value = line.split('=')[1] | |
_dict[key]=value | |
if key != "password": | |
print key+":"+value | |
else: | |
print key+":********" | |
fileobj.close() | |
start() | |
else: | |
print "Unable to find the store.properties in the base location",propfile | |
sys.exit(2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment