ngcloud.util module

ngcloud.util.open(path_like, *args, **kwargs)[source]

Custom open() that accepts pathlib.Path object.

All the parameters will be passed to original open().

Examples

>>> with open(Path('say'), 'w') as f:
...     f.write('hi')
ngcloud.util.expanduser(path_like)[source]

Custom expanduser() that accepts both str and Path object.

Internally it calls os.path.expanduser()

ngcloud.util.copy(src_path_like, dst_path_like, metadata=False, **kwargs)[source]

pathlib support for path-like objects.

Internally use either shutil.copy() or shutil.copy2() based on metadata value.

ngcloud.util.discover_file_by_patterns(path_like, file_patterns='*')[source]

Discover files under certain path based on given patterns.

Support both ** and * globbing syntax. Call pathlib.Path.glob() internally.

Parameters:

path_like : path-like object

file_patterns : str or iterable

glob-style file pattern

Returns:

List of pathlib.Path object.

Examples

>>> discover_file_by_patterns("report", "**/_*.html")
[PosixPath('report/templates/_nav.html'),
 PosixPath('report/templates/_footer.html'),
 PosixPath('report/templates/_stage_pipe.html')]
>>> discover_file_by_patterns("report", ["**/_*.html", "**/*.js"])
[PosixPath('report/templates/_nav.html'),
 PosixPath('report/templates/_footer.html'),
 PosixPath('report/templates/_stage_pipe.html'),
 PosixPath('report/static/vendor/bootstrap-3.1.1/js/bootstrap.min.js'),
 PosixPath('report/static/vendor/bootstrap-3.1.1/js/bootstrap.js')]
ngcloud.util.merged_copytree(src_list, dst)[source]
ngcloud.util.strify_path(path_like)[source]

Normalized path-like object to POSIX style str.

Examples

>>> strify_path(Path('ngcloud') / 'hi.py'))
"ngcloud/hi.py"
>>> strify_path('ngcloud/hi.py')
"ngcloud/hi.py"
ngcloud.util.is_pathlike(path_like)[source]

Helper function to determine is pathlike object.

ngcloud.util._val_bool_or_none(arg, name)[source]

Check if argument is of True, False, or None.

Otherwise ValueError is raised.

Raises:ValueError