qme.utils package¶
Submodules¶
qme.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
qme.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
qme.utils.command.
QueueMeCommand
(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
-
qme.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/.
-
qme.utils.file.
get_latest_modified
(base, pattern='*.json')[source]¶ Given a folder, get the latest modified file
-
qme.utils.file.
get_tmpdir
(prefix='', create=True)[source]¶ get a temporary directory for an operation. If SREGISTRY_TMPDIR is set, return that. Otherwise, return the output of tempfile.mkdtemp
- Arguments:
prefix (str) : prefix with this string
create (bool) : create the folder (defaults to true)
-
qme.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
-
qme.utils.file.
get_user
()[source]¶ Get the name of the user. We first try to import pwd, but fallback to extraction from the environment.
-
qme.utils.file.
get_userhome
()[source]¶ get the user home based on the effective uid. If import of pwd fails (not supported for Windows) then fall back to environment variable.
-
qme.utils.file.
mkdir_p
(path)[source]¶ mkdir_p attempts to get the same functionality as mkdir -p
- Arguments:
path (str) : the path to create
-
qme.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)
-
qme.utils.file.
read_json
(input_file)[source]¶ Read json from an input file.
- Arguments:
input_file (str) : the filename to read
-
qme.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
qme.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/.
qme.utils.regex 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/.