watchme.utils package¶
Submodules¶
watchme.utils.fileio module¶
Copyright (C) 2019 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/.
The watcher is actually a connection to crontab. This is what helps to schedule the watched to check for changes at some frequency, and update the files.
-
watchme.utils.fileio.
copyfile
(source, destination, force=True)[source]¶ copy a file from a source to its destination.
-
watchme.utils.fileio.
generate_temporary_file
(folder=None, prefix='watchme', ext=None)[source]¶ write a temporary file, in base directory with a particular extension.
Parameters: - folder (the base directory to write in.)
- prefix (the prefix to use)
- ext (the extension to use.)
-
watchme.utils.fileio.
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
Parameters: - prefix (Given a need for a sandbox (or similar), we will need to)
- create a subfolder *within* the SREGISTRY_TMPDIR.
- create (boolean to determine if we should create folder (True))
-
watchme.utils.fileio.
mkdir_p
(path)[source]¶ mkdir_p attempts to get the same functionality as mkdir -p
param path: the path to create.
-
watchme.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
-
watchme.utils.fileio.
read_json
(filename, mode='r')[source]¶ read_json reads in a json file and returns the data structure as dict.
watchme.utils.terminal module¶
Copyright (C) 2019 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/.
-
watchme.utils.terminal.
choice_prompt
(prompt, choices=None, choice=None)[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, defaults to [Y/N/y/n])
-
watchme.utils.terminal.
confirm_prompt
(prompt)[source]¶ A wrapper around choice_prompt, but ask the user specifically for a yes / no response that is converted to boolean for the calling agent.
Parameters: prompt (the prompt to ask the user)
-
watchme.utils.terminal.
convert2boolean
(arg)[source]¶ convert2boolean is used for environmental variables that must be returned as boolean
-
watchme.utils.terminal.
get_installdir
()[source]¶ get_installdir returns the installation directory of the application
-
watchme.utils.terminal.
regexp_prompt
(prompt, regexp='.', answer='')[source]¶ Ask the user for a text entry that matches a regular expression
Parameters: - prompt (the prompt to ask the user)
- regexp (the regular expression to match. defaults to anything.)
-
watchme.utils.terminal.
run_command
(cmd, sudo=False)[source]¶ run_command uses subprocess to send a command to the terminal.
Parameters: - cmd (the command to send, should be a list for subprocess)
- error_message (the error message to give to user if fails,)
- if none specified, will alert that command failed.