iblutil.io.params

Functions

as_dict

from_dict

getfile

Returns full path of the param file per system convention:

read

Reads in and parse Json parameter file into dictionary.

set_hidden

Set a given file or folder path to be hidden.

write

Write a parameter file in Json format

as_dict(par)[source]
from_dict(par_dict)[source]
getfile(str_params)[source]
Returns full path of the param file per system convention:

linux/mac: ~/.str_params, Windows: APPDATA folder

Parameters:

str_params – string that identifies parm file

Returns:

string of full path

set_hidden(path, hide: bool) Path[source]

Set a given file or folder path to be hidden. On macOS and Windows a specific flag is set, while on other systems the file or folder is simply renamed to start with a dot. On macOS the folder may only be hidden in Explorer.

Parameters:
  • path (str, pathlib.Path) – The path of the file or folder to (un)hide.

  • hide (bool) – If True the path is set to hidden, otherwise it is unhidden.

Returns:

The path of the file or folder, which may have been renamed.

Return type:

pathlib.Path

read(str_params, default=None)[source]

Reads in and parse Json parameter file into dictionary. If the parameter file doesn’t exist and no defaults are provided, a FileNotFound error is raised, otherwise any extra default parameters will be written into the file.

Examples

# Load parameters, raise error if file not found par = read(‘globus/admin’)

# Load with defaults par = read(‘globus/admin’, {‘local_endpoint’: None, ‘remote_endpoint’: None})

# Return empty dict if file not found (i.e. touch new param file) par = read(‘new_pars’, {})

Parameters:
  • str_params – path to text json file

  • default – default values for missing parameters

Returns:

named tuple containing parameters

write(str_params, par)[source]

Write a parameter file in Json format

Parameters:
  • str_params – path to text json file

  • par – dictionary containing parameters values

Returns:

None