oasislmf.utils.path¶
Classes¶
A callable that generates the absolute path of the given path and checks  | 
Functions¶
  | 
Processes the path and returns the absolute path.  | 
  | 
Empties the contents of a directory, but leaves the directory in place.  | 
  | 
return the object or module from the path given  | 
  | 
return the custom module present at the custom_module_path.  | 
  | 
Module Contents¶
- oasislmf.utils.path.as_path(path, label, is_dir=False, preexists=True, null_is_valid=True)[source]¶
 Processes the path and returns the absolute path.
If the path does not exist and
preexistsis true anOasisExceptionis raised.- Parameters:
 - Returns:
 The absolute path of the input path
- oasislmf.utils.path.empty_dir(dir_fp)[source]¶
 Empties the contents of a directory, but leaves the directory in place.
- Parameters:
 dir_fp (str) – A pre-existing directory path
- class oasislmf.utils.path.PathCleaner(label, preexists=True)[source]¶
 Bases:
objectA callable that generates the absolute path of the given path and checks that it exists if indicated as preexisting.
- Parameters:
 
- oasislmf.utils.path.import_from_string(name)[source]¶
 return the object or module from the path given >>> import os.path >>> mod = import_from_string(‘os.path’) >>> os.path is mod True
>>> from os.path import isabs >>> cls = import_from_string('os.path.isabs') >>> isabs is cls True
- oasislmf.utils.path.get_custom_module(custom_module_path, label)[source]¶
 return the custom module present at the custom_module_path. the try loop allow for the custom module to work even if it depends on other module of its package by testing recursively for the presence of __init__.py file
(ex: this module “path” is using from .exceptions import OasisException so it can only be imported as part of the utils package => sys.path.insert(0, path_to_utils);importlib.import_module(‘utils.path’)) >>> mod = get_custom_module(__file__, “test module”) >>> mod.__name__.rsplit(‘.’, 1)[-1] ‘path’