openbases.utils package

Submodules

openbases.utils.fileio module

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

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

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

Copy an entire directory recursively

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

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

openbases.utils.fileio.find_files(root, pattern, fullpath=True)[source]

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

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

Return directories (and sub) starting from a base

openbases.utils.fileio.get_installdir()[source]
openbases.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. :param variable_key: the variable name :param required: exit with error if not found :param silent: Do not print debugging information for variable

openbases.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

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

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

openbases.utils.fileio.read_bibtex(filename, mode='r')[source]

read a yaml file, only including sections between dashes

openbases.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

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

read a yaml file, only including sections between dashes

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

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

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

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

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

read a yaml file, only including sections between dashes

openbases.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

openbases.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

openbases.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

openbases.utils.terminal module

openbases.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.

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

get_installdir returns the installation directory of the application

openbases.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.

openbases.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

openbases.utils.web module

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

clone a repository from Github

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

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

Module contents