rse.utils package
Submodules
rse.utils.command module
Copyright (C) 2020 Vanessa Sochat.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
- class rse.utils.command.Capturing[source]
Bases:
object
capture output from stdout and stderr into capture object. This is based off of github.com/vsoch/gridtest but modified to write files. The stderr and stdout are set to temporary files at the init of the capture, and then they are closed when we exit. This means expected usage looks like:
- with Capturing() as capture:
process = subprocess.Popen(…)
And then the output and error are retrieved from reading the files: and exposed as properties to the client:
capture.out capture.err
And cleanup means deleting these files, if they exist.
- property err
Return error stream. Returns empty string if empty or doesn’t exist. Returns (str) : error stream written to file
- property out
Return output stream. Returns empty string if empty or doesn’t exist. Returns (str) : output stream written to file
- class rse.utils.command.Command(cmd=None)[source]
Bases:
object
Class method to invoke shell commands and retrieve output and error. This class is inspired and derived from utils functions in https://github.com/vsoch/scif
- decode(line)[source]
Given a line of output (error or regular) decode using the system default, if appropriate
rse.utils.file module
Copyright (C) 2020 Vanessa Sochat.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
- rse.utils.file.get_latest_modified(base, pattern='*.json')[source]
Given a folder, get the latest modified file
- rse.utils.file.get_tmpdir(prefix='', create=True)[source]
get a temporary directory for an operation.
- Arguments:
prefix (str) : prefix with this string
create (bool) : create the folder (defaults to true)
- rse.utils.file.get_tmpfile(prefix='')[source]
get a temporary file with an optional prefix. By default, the file is closed (and just a name returned).
- Arguments:
prefix (str) : prefix with this string
- rse.utils.file.mkdir_p(path)[source]
mkdir_p attempts to get the same functionality as mkdir -p
- Arguments:
path (str) : the path to create
- rse.utils.file.read_file(filename, readlines=True)[source]
write_file will open a file, “filename” and write content and properly close the file.
- Arguments:
filename (str) : the filename to read
readlines (bool) : read lines of the file (vs all raw)
- rse.utils.file.read_json(input_file)[source]
Read json from an input file.
- Arguments:
input_file (str) : the filename to read
- rse.utils.file.recursive_find(base, pattern='*.py')[source]
recursive find will yield python files in all directory levels below a base path.
- Arguments:
base (str) : the base directory to search
pattern: a pattern to match, defaults to *.py
rse.utils.prompt module
Copyright (C) 2020 Vanessa Sochat.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
- rse.utils.prompt.choice_prompt(prompt, choices, choice_prefix=None, multiple=False)[source]
Ask the user for a prompt, and only return when one of the requested options is provided.
- Parameters
prompt (the prompt to ask the user)
choices (a list of choices that are valid.)
multiple (allow multiple responses (separated by spaces))