@ -16,11 +16,20 @@ DATA = {}
def isloaded ( ) :
def isloaded ( ) :
return DATA not in [ { } , None ]
return DATA not in [ { } , None ]
def exists ( path = REGISTRY_PATH ) :
"""
This function determines if there is a registry at all
"""
p = os . path . exists ( path )
q = os . path . exists ( os . sep . join ( [ path , REGISTRY_FILE ] ) )
print ( [ p , q , os . sep . join ( [ path , REGISTRY_FILE ] ) ] )
return p and q
def load ( _path = REGISTRY_PATH ) :
def load ( _path = REGISTRY_PATH ) :
global DATA
global DATA
_path = os . sep . join ( [ _path , REGISTRY_FILE ] )
if os . path . exists ( _path ) :
if exists ( _path ) :
f = open ( _path )
path = os . sep . join ( [ _path , REGISTRY_FILE ] )
f = open ( path )
DATA = json . loads ( f . read ( ) )
DATA = json . loads ( f . read ( ) )
f . close ( )
f . close ( )
def init ( email , path = REGISTRY_PATH , override = False ) :
def init ( email , path = REGISTRY_PATH , override = False ) :
@ -45,12 +54,19 @@ def init (email,path=REGISTRY_PATH,override=False):
raise Exception ( f """ Unable to write configuration, Please check parameters (or help) and try again """ )
raise Exception ( f """ Unable to write configuration, Please check parameters (or help) and try again """ )
else :
else :
raise Exception ( f """ Invalid Input, { email } is not well formatted, provide an email with adequate format """ )
raise Exception ( f """ Invalid Input, { email } is not well formatted, provide an email with adequate format """ )
def lookup ( label ) :
global DATA
return label in DATA
def get ( label = ' default ' ) :
def get ( label = ' default ' ) :
global DATA
global DATA
return copy . copy ( DATA [ label ] ) if label in DATA else { }
return copy . copy ( DATA [ label ] ) if label in DATA else { }
def set ( label , auth_file , default = False , path = REGISTRY_PATH ) :
def set ( label , auth_file , default = False , path = REGISTRY_PATH ) :
"""
This function will add a label ( auth - file data ) into the registry and can set it as the default
"""
if label == ' default ' :
raise Exception ( """ Invalid label name provided, please change the label name and use the switch """ )
reg_file = os . sep . join ( [ path , REGISTRY_FILE ] )
reg_file = os . sep . join ( [ path , REGISTRY_FILE ] )
if os . path . exists ( auth_file ) and os . path . exists ( path ) and os . path . exists ( reg_file ) :
if os . path . exists ( auth_file ) and os . path . exists ( path ) and os . path . exists ( reg_file ) :
f = open ( auth_file )
f = open ( auth_file )
@ -73,7 +89,7 @@ def set (label, auth_file, default=False,path=REGISTRY_PATH) :
f . write ( json . dumps ( _config ) )
f . write ( json . dumps ( _config ) )
f . close ( )
f . close ( )
else :
else :
_msg = f """ Unable to load file locate at { path } , \n Learn how to generate auth-file with wizard found at https://healthcareio.the-phi.com/data-transport """
raise Exception ( f """ Unable to load file locate at { path } , \n Learn how to generate auth-file with wizard found at https://healthcareio.the-phi.com/data-transport """ )
pass
pass
else :
else :
pass
pass