anise.utils package¶
Submodules¶
anise.utils.basic module¶
Basic helpers for filesystem and other operating system related stuff.
-
class
anise.utils.basic.
ChDir
(path)¶ Bases:
object
Temporarily changes the current working directory in a scope of the
with
keyword.- Parameters
path (str) – The path to the new working directory.
-
class
anise.utils.basic.
Mount
(src, dst, options=None, mounter=None, unmounter=None, needsroot=True)¶ Bases:
object
Mounts a volume. Can either be used automatically with the
with
keyword or manually.- Parameters
src (str) – Mount source.
dst (str) – Mount destination.
options (Optional[List[str]]) – Optional additional mount options.
mounter (Optional[List[str]]) – Optional string list overriding the default mount call.
unmounter (Optional[List[str]]) – Optional string list overriding the default unmount call.
needsroot (bool) – If this mount action will need root permissions.
-
mount
()¶ Manually mount the volume.
- Return type
None
-
unmount
()¶ Manually unmount the volume.
- Return type
None
-
anise.utils.basic.
call
(*cmdline, shell=False, decode=True, raise_on_errors=None, split_output_channels=False)¶ Executes a command line.
- Parameters
cmdline (Union[str, List[str]]) – The command line as list of arguments.
shell (bool) – If the command shall be interpreted by a shell (only the first part of cmdline will apply!).
decode (bool) – If the result is to be decoded to a string.
raise_on_errors (Optional[str]) – If errors shall raise Exceptions (also specifies the exception text in this case).
split_output_channels (bool) – If to separately record output and error stream.
- Returns
Tuple of returncode, program output.
- Return type
Tuple[int, Union[AnyStr, Tuple]]
-
anise.utils.basic.
callanise
(*args)¶ Calls the Anise process (in a platform independent way).
- Parameters
args (str) – The command line arguments to pass.
- Return type
None
-
anise.utils.basic.
execwithretry
(fct, *args, maxtries=10, delaysecs=0.2, **kwargs)¶ Executes a function with a retry mechanism (executing it again when an exception was raised).
- Parameters
fct (Callable) – The function to execute.
args (Optional[Any]) – Arguments for the function call.
maxtries (int) – Maximum try count.
delaysecs (float) – Delay (in seconds) betweens tries.
kwargs (Optional[Any]) – Keyword arguments for the function call.
- Return type
Optional[Any]
-
anise.utils.basic.
getdriveletters
()¶ Returns a list of drive letters that exist on this system (only win32).
- Return type
List[str]
-
anise.utils.basic.
maketarball
(sourcepath, tarpath)¶ Makes a tar archive from a given directory structure.
- Parameters
sourcepath – The root source directory of the new tarball (becomes a directory in the archive as typical for tarballs).
tarpath (str) – The destination path for the tar archive.
- Return type
None
-
anise.utils.basic.
mkdirs
(dname)¶ Creates a directory path recursively if it does not yet exist.
- Parameters
dname (str) – The directory path.
- Return type
None
-
anise.utils.basic.
openfile
(filepath)¶ Opens a file path in the operating system’s default way.
- Parameters
filepath (str) – A file path.
- Return type
None
-
anise.utils.basic.
openurl
(url)¶ Opens a url (or file path) in the operating system’s default way.
- Parameters
url (str) – A url or file path.
- Return type
None
-
anise.utils.basic.
readfromfile
(filename, onestring=True, notexist_default=<object object>, binary=False)¶ Reads the content from a file.
- Parameters
filename (str) – The file path.
onestring (bool) – If the content is to be read in one single string (instead of a list of lines).
notexist_default (Any) – The default content when the file does not exist.
binary (bool) – If this is binary content instead of text.
- Return type
AnyStr
-
anise.utils.basic.
verify_tool_installed
(toolname)¶ Checks if a tool is installed and raises an exception if not.
- Parameters
toolname (str) – The tool name as to execute on command line.
- Return type
None
-
anise.utils.basic.
writetofile
(filename, content)¶ Writes some content to a file.
- Parameters
filename (str) – The file path.
content (AnyStr) – The content to write.
- Return type
None
anise.utils.data module¶
Helpers for creation and handling of some data structures.
-
anise.utils.data.
constructobject
(**d)¶ Creates an object with properties from the given keyword arguments.
- Parameters
d (Optional[Any]) –
- Return type
object
-
anise.utils.data.
createobjectstructure
(root, newnames, objclass=None)¶ Creates a chain of new objects, so you can access property chains like
foo.bar.baz.bam
on the root object.- Parameters
root (Any) – The object to populate with the new structure.
newnames (str) – The complete property chain.
objclass (Optional[Type]) – Which object class to use for the cascaded new members.
- Returns
Tuple of the deepest object in the cascade (corresponding to the last part of the chain) and its parent.
- Return type
Tuple[object, object]
anise.utils.logging module¶
Logging.
-
class
anise.utils.logging.
Severity
¶ Bases:
object
Enumeration of log message severities.
-
Debug
= 0¶ Debug logging severity.
-
Error
= 300¶ Error logging severity.
-
Info
= 100¶ Info logging severity.
-
Warning
= 200¶ Warning logging severity.
-
-
anise.utils.logging.
_logmessage_default
(text, severity, terminalonly, tofile, textescaper)¶ This is the fallback lowlevel logging implementation. Typically it gets overridden by a different one in early initialization steps.
- Return type
None
-
anise.utils.logging.
logdebug
(text, printcaller=True, skiplevels=1, terminalonly=False)¶ Logs a text message with debug severity.
- Parameters
text (str) – The log message.
printcaller (bool) – Also logs the caller name.
skiplevels (int) – If given, it controls the position on the call stack that is used for logging the caller name.
terminalonly (bool) – If this log message shall just go to the terminal and not to the report, the web interface, etc. Only used by the infrastructure.
- Return type
None
-
anise.utils.logging.
logerror
(text, printcaller=True, skiplevels=1, terminalonly=False)¶ Logs a text message with error severity.
- Parameters
text (str) – The log message.
printcaller (bool) – Also logs the caller name.
skiplevels (int) – If given, it controls the position on the call stack that is used for logging the caller name.
terminalonly (bool) – If this log message shall just go to the terminal and not to the report, the web interface, etc. Only used by the infrastructure.
- Return type
None
-
anise.utils.logging.
logexception
(exception, prolog='Error: ')¶ Logs an exception.
- Parameters
exception (BaseException) – The occurred exception. This only works from within the
except
-handler of this exception.prolog (str) – This is prepended to the exception text in the output.
- Return type
None
-
anise.utils.logging.
loginfo
(text, printcaller=True, skiplevels=1, terminalonly=False)¶ Logs a text message with info severity.
- Parameters
text (str) – The log message.
printcaller (bool) – Also logs the caller name.
skiplevels (int) – If given, it controls the position on the call stack that is used for logging the caller name.
terminalonly (bool) – If this log message shall just go to the terminal and not to the report, the web interface, etc. Only used by the infrastructure.
- Return type
None
-
anise.utils.logging.
logmessage
(text, severity, printcaller=True, skiplevels=1, terminalonly=False)¶ Logs a text message.
- Parameters
text (str) – The log message.
severity (int) – The message severity. One of the values from
Severity
.printcaller (bool) – Also logs the caller name.
skiplevels (int) – If given, it controls the position on the call stack that is used for logging the caller name.
terminalonly (bool) – If this log message shall just go to the terminal and not to the report, the web interface, etc. Only used by the infrastructure.
- Return type
None
-
anise.utils.logging.
logwarning
(text, printcaller=True, skiplevels=1, terminalonly=False)¶ Logs a text message with warning severity.
- Parameters
text (str) – The log message.
printcaller (bool) – Also logs the caller name.
skiplevels (int) – If given, it controls the position on the call stack that is used for logging the caller name.
terminalonly (bool) – If this log message shall just go to the terminal and not to the report, the web interface, etc. Only used by the infrastructure.
- Return type
None
-
anise.utils.logging.
setlowlevellogger
(fct)¶ Sets the lowlevel logging implementation.
- Parameters
fct (Callable[[str, int, bool, TextIO, Callable[[str], str]], None]) – The logger function.
- Return type
None
anise.utils.ssh module¶
Utilities for ssh usage.
-
class
anise.utils.ssh.
Mount
(src, dst, options=None, port=22, identityfile=None)¶ Bases:
anise.utils.basic.Mount
Mounts a volume via ssh.
- Parameters
src (str) – The remote mount source (an ssh address like
'user@machine'
).dst (str) – The local mount destination.
options (Optional[List[str]]) – Optional additional mount options.
port (int) – Optional tcp port.
identityfile (Optional[str]) – Optional identity file for authentication.
-
anise.utils.ssh.
call
(server, command, options=None, port=22, identityfile=None)¶ Executes a command via ssh.
- Parameters
server (str) – The ssh server hostname.
command (str) – The command to execute.
options (Optional[List[str]]) – Additional ssh options.
port (int) – Port number.
identityfile (Optional[str]) – Optional identity file for authentication.
- Return type
str
-
anise.utils.ssh.
copy
(src, dst, options=None, port=22, identityfile=None)¶ Copies a local directory to a remote place via ssh.
- Parameters
src (str) – The source.
dst (str) – The destination.
options (Optional[List[str]]) – Optional additional mount options.
port (int) – Optional tcp port.
identityfile (Optional[str]) – Optional identity file for authentication.
- Return type
None
anise.utils.threading module¶
Threading.
-
class
anise.utils.threading.
Thread
(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)¶ Bases:
threading.Thread
A thread implementation that is perfectly compatible with the internal Anise bookkeeping.
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
start
()¶ Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
-
Module contents¶
Utility functions from several categories which make life easier. All stuff here is not tightly bound to Anise infrastructure but can easily be understood separately. Most stuff here is used by deeper parts of Anise.