openschemas.utils package

Submodules

openschemas.utils.fileio module

openschemas.utils.fileio.convert2boolean(arg)[source]

convert2boolean is used for environmental variables that must be returned as boolean

arg: the argument (string) to parse and check for indicators of boolean

openschemas.utils.fileio.copy_directory(src, dest, force=False)[source]

Copy an entire directory recursively

openschemas.utils.fileio.find_directories(root, fullpath=True)[source]

Return directories at one level specified by user (not recursive)

openschemas.utils.fileio.find_subdirectories(basepath)[source]

Return directories (and sub) starting from a base

openschemas.utils.fileio.get_installdir()[source]
openschemas.utils.fileio.getenv(variable_key, default=None, required=False, silent=True)[source]

getenv will attempt to get an environment variable. If the variable is not found, None is returned.

variable_key: the variable name required: exit with error if not found silent: Do not print debugging information for variable
openschemas.utils.fileio.load_module(module_str)[source]

load a module based on a string name.

module_str: complete python path to module (and function). Note that this MUST be a python module (module.py) and not a function in an __init__.py

openschemas.utils.fileio.mkdir_p(path)[source]

mkdir_p attempts to get the same functionality as mkdir -p :param path: the path to create.

openschemas.utils.fileio.read_file(filename, mode='r', readlines=True)[source]

write_file will open a file, “filename” and write content, “content” and properly close the file

openschemas.utils.fileio.read_frontmatter(filename, mode='r', quiet=False)[source]

read a yaml file, only including sections between dashes

openschemas.utils.fileio.read_json(filename, mode='r')[source]

read_json reads in a json file and returns the data structure as dict.

openschemas.utils.fileio.read_markdown(filename, mode='r')[source]

read the OTHER part of the markdown file (remove the frontend matter)

openschemas.utils.fileio.read_yaml(filename, mode='r', quiet=False)[source]

read a yaml file, only including sections between dashes

openschemas.utils.fileio.write_file(filename, content, mode='w')[source]

write_file will open a file, “filename” and write content, “content” and properly close the file

openschemas.utils.fileio.write_json(json_obj, filename, mode='w', print_pretty=True)[source]

write_json will (optionally,pretty print) a json object to file

json_obj: the dict to print to json filename: the output file to write to pretty_print: if True, will use nicer formatting

openschemas.utils.fileio.write_yaml(yaml_dict, filename, mode='w')[source]

write a dictionary to yaml file

yaml_dict: the dict to print to yaml filename: the output file to write to pretty_print: if True, will use nicer formatting

openschemas.utils.managers module

class openschemas.utils.managers.YamlManager(yml_path=None)[source]

Bases: object

get_key(key='specifications')[source]

return a portion of the yml file based on key

key: defaults to specifications

load(file_path=None)[source]

load the yaml file depending on its extension

file_path: a yaml/html file path, if desired, to override previous

save_yaml(output_file, content=None, mode='w')[source]
save_yml(output_file, content=None, mode='w', ext='yml')[source]

save a yml file, either provided by the client (content) or if not provided, the loaded content.

output_file: the output file to save to. Should end in yml or yaml content: the content to parse to yaml, can be str or dict mode: the mode to use (default is w, write)

set_yml_path(file_path)[source]
yml_path = None

openschemas.utils.terminal module

openschemas.utils.terminal.check_install(software=None, quiet=True)[source]

check_install will attempt to run some command, and return True if installed. The command line utils will not run without this check.

openschemas.utils.terminal.get_installdir()[source]

get_installdir returns the installation directory of the application

openschemas.utils.terminal.run_command(cmd, sudo=False, capture=True, no_newline_regexp='Progess', quiet=False)[source]

run_command uses subprocess to send a command to the terminal. If capture is True, we use the parent stdout, so the progress bar (and other commands of interest) are piped to the user. This means we don’t return the output to parse. Parameters ========== cmd: the command to send, should be a list for subprocess sudo: if needed, add to start of command no_newline_regexp: the regular expression to determine skipping a

newline. Defaults to finding Progress

capture: if True, don’t set stdout and have it go to console. This option can print a progress bar, but won’t return the lines as output.

openschemas.utils.terminal.stream_command(cmd, no_newline_regexp='Progess', sudo=False)[source]

stream a command (yield) back to the user, as each line is available. :: note

# Example usage: results = [] for line in stream_command(cmd):

print(line, end=”“) results.append(line)

cmd: the command to send, should be a list for subprocess no_newline_regexp: the regular expression to determine skipping a newline. Defaults to finding Progress

openschemas.utils.web module

openschemas.utils.web.clone(url, tmpdir=None, branch='master')[source]

clone a repository from Github

openschemas.utils.web.get_post_fields(request)[source]

parse through a request, and return fields from post in a dictionary

Module contents