file_utils.py

file_utils.py

Utilities for working with files.

openmdao.utils.file_utils.files_iter(start_dir='.', dir_includes=None, dir_excludes=(), file_includes=None, file_excludes=(), package_only=False)[source]

Iterate over files (recursively) starting in start_dir.

NOTE : all _includes and *_excludes are applied to *local directory and file names.

Parameters
start_dirstr

Starting directory.

dir_includesiter of str or None

Glob patterns for directory inclusion. Be careful here because dir names are local, so, for example, if includes=(‘foo’,), then directory ‘foo’ would be included, but any subdirectories of ‘foo’ that were not also named ‘foo’ would not.

dir_excludesiter of str

Glob patterns for directory exclusion.

file_includesiter of str or None

Glob patterns for file inclusion.

file_excludesiter of str

Glob patterns for file exclusion.

package_onlybool

If True, only yield files that are contained in a python package.

Yields
str

Filenames (full path from start_dir).

openmdao.utils.file_utils.get_module_path(fpath)[source]

Given a module filename, return its full Python module path.

This includes enclosing packages and is based on existence of __init__.py files.

Parameters
fpathstr

Pathname of file.

Returns
str or None

Full module path of the given file. Returns None if the file is not part of a package.

openmdao.utils.file_utils.image2html(imagefile, title='', alt='')[source]

Wrap the given image for display as an html file.

Returns an html syntax string that can be written to a file.

Parameters
imagefilestr

Name of image file to be displayed.

titlestr

The page title.

altstr

Set the alt text for the image.

Returns
str

Content string to create an html file.

openmdao.utils.file_utils.package_iter(start_dir='.', dir_includes=None, dir_excludes=(), file_includes=None, file_excludes=())[source]

Iterate over python files in packages (recursively) starting in start_dir.

NOTE : all _includes and *_excludes are applied to *local directory and file names.

Parameters
start_dirstr

Starting directory.

dir_includesiter of str or None

Glob patterns for directory inclusion. Be careful here because dir names are local, so, for example, if includes=(‘foo’,), then directory ‘foo’ would be included, but any subdirectories of ‘foo’ that were not also named ‘foo’ would not.

dir_excludesiter of str

Glob patterns for directory exclusion.

file_includesiter of str or None

Glob patterns for file inclusion.

file_excludesiter of str

Glob patterns for file exclusion.

Yields
str

Filenames (full path from start_dir).

openmdao.utils.file_utils.text2html(text, title='', style=None)[source]

Wrap the given text for display as an html file.

Returns an html syntax string that can be written to a file.

Parameters
textstr

Text to be displayed.

titlestr

Title to display above text.

stylestr or None

If not None, use as the contents of the style block for the enclosing <pre> tag.

Returns
str

Content string to create an html file.