Bricabrac classes (bricabrac
)¶
Modules¶
fileIO - Bits and bots dealing with input and output operations¶
-
class
Printer
[source]¶ Class to print strings in relation to a verbosity level. The verbosity level is shared with all Printer.verbosePrint calls in a python instance.
Usage:
Printer.setVerbosity(<NUMBER>) # set verbosity level to NUMBER Printer.verbosePrint(<TEXT>, <VERBOSITY>, *args, **kwargs) # print TEXT with verbosity VERBOSITY
-
class
Verbosity
(value)¶ An enumeration.
-
classmethod
error
(text, printLevel=<Verbosity.ALWAYS: 0>, *args, **kwargs)[source]¶ Prints an error message only, if its verbosity level is smaller than the global verbosity level.
-
classmethod
setVerbosity
(verbosity)[source]¶ Sets verbosity to verbosity.
- Parameters
verbosity (integer) – new global verbosity level
-
classmethod
verbosePrint
(text, printLevel=<Verbosity.DEFAULT: 2>, *args, **kwargs)[source]¶ Prints a message only, if its verbosity level is smaller than the global verbosity level.
- Parameters
text (string) – text to print
printLevel (integer) – print level of the text, 0 - ALWAYS, 1 - JENKINS, 2 - DEFAULT, 3 - DEBUG
*args (list) – argument list for print
**kwargs (dictionary) – keyword argument dictionary for print
- Returns
True if the printer actually printed something
- Return type
-
class
-
checkExecutables
(*args)[source]¶ Tests if a executable is found under the given path.
- Parameters
*args (list) – list of executables
-
ensurePath
(filepath, verbose=0)[source]¶ Ensure that the path to the file or directory exists If the path is not valid necessary sub-directories are created.
- parameters:
filepath (string) - path to directory
- optional parameters:
verbose (int) - level of verbosity
-
getAbsoluteFilePath
(path, allowDirectories=False)[source]¶ Returns the absolute path to an existing FILE handling following any symbolic link. Directories are not allowed when the allowDirectoriesFlag is not set to True and will raise an error.
-
globCopy
(source, destination, match=False, verbose=0)[source]¶ Allows to copy files or complete directories using the bash wild card syntax.
If a directory is specified the content will be overwritten by trying to remove the destination folder first.
- Parameters
source (string) – source path (Bash wild card syntax allowed)
destination (string) – destination path
match (boolean) – if set at least one match has to be found
verbose (integer) – verbosity level (0 - None, 1 - print commands)
-
globCopy2
(filepath, srcstring, deststring, verbose=0)[source]¶ Allows to copy files by replacing parts of the file path. Bash wild card syntax is allowed.
- Parameters
filepath (string) – source path (Bash wild card syntax allowed)
srcstring (string) – source string
deststring (string) – destination string
verbose (integer) – verbosity level (0 - None, 1 - print commands)
-
globMove
(source, destination, match=False, verbose=0)[source]¶ Allows to move files using the bash wild card syntax.
- Parameters
source (string) – source path (Bash wild card syntax allowed)
destination (string) – destination path
match (boolean) – if set at least one match has to be found
verbose (integer) – verbosity level (0 - None, 1 - print commands)
-
globRm
(*paths, **kwargs)[source]¶ Allows to remove files using the bash wild card syntax.
- Parameters
*paths (list) – source paths (Bash wild card syntax allowed)
(via **kwargs) (verbose) – verbosity level (0 - None, 1 - print commands)
-
md
(directory, verbose=0)[source]¶ Create directory if it does not already exist
- parameters:
directory (string) - path to directory
- optional parameters:
verbose (int) - level of verbosity
- return:
return code (int) (-1 : path is a file, 0 : path to directory is created, 1 : path is already a directory)
-
pureText
(path, comment='#', lineNumbers=False)[source]¶ A generator to get only text lines without comments from a file. To use in a for-loop:
Usage:
for line in pureText(path): do something with line
- Parameters
path (string) – path to the file to parse
comment (string) – string a comment line starts with
-
removeFile
(fileToRemove)[source]¶ Removes a file or a folder from the file system without asking anything. Deletes sub folders, too. If the given path does not exist the method just returns False. It will raise an error only if it is not possible to remove the existing file or folder
Warning
Use with caution.
- Parameters
fileToRemove (string) – path which will be removed
- Returns
returns True if something was removed, False otherwise
- Return type
boolean
finiteStateMachine¶
Offers a python implementation of a finite state machine.
It is used in the compareCGNS method to parse a POST cmpc file.
A tutorial for simple text file parsing state machines can be found under: https://www.ibm.com/developerworks/library/l-python-state/
@author: baye_fe
-
class
FiniteStateMachine
[source]¶ Python implementation of a finite state machine
-
addState
(state, handler, isEndState=False)[source]¶ Add a new state and its handler to the state machine. A flag tags the state as end state.
-
run
(consumee, *args, **kwargs)[source]¶ Run the previously set up state machine.
Starts using the initial state. ‘consumee’ should be the input stream for the state machine. ‘args’ and ‘kwargs’ can be used to pass arguments to the handlers and receive output. The state can be changed by returning the name of the new state in the handler method. If the returned state is a end state the state machine terminates.
- Parameters
consumee (iterable) – The input stream for the handlers
args – arbitrary arguments
kwargs – arbitrary keyword arguments
-
textIO¶
textIO provides a class to print formatted text into the console.
-
class
Color
[source]¶ Container to store color codes
-
classmethod
colorFileListing
(directoryPath, showHidden=False, ignoreFolders=None, ignoreExtensions=None, ignorePrefix=None)[source]¶ Creates colorful file listing of a folder
- Parameters
- Returns
formatted string
- Return type
-
static
printColorful
(text, *args)[source]¶ Manipulates and prints a string, using keyword arguments.
- Parameters
text (str) – text to format
*args (Color attributes) – Color class constant format attributes
-
static
printFileListing
(directoryPath, showHidden=False, ignoreFolders=None, ignoreExtensions=None, ignorePrefix=None)[source]¶ Creates colorful file listing of a folder and prints it
- Parameters
-
classmethod
Email - Contains a method to send mails.¶
Created on 10.05.2012
author: well_jn
requires¶
mimetypes smtplib os re email socket
stringFormatting - bits and bots dealing with string formatting¶
requires¶
math
-
class
Splashscreen
(lines, newMapping=False)[source]¶ Class to create automated splash screens for your executables. Usage:
someSplashscreen = Splashscreen(["SOFTWARE", "", "version 42"]) someSplashscreen.printScreen()
- Parameters
line (list) – list with lines to print in the box
newMapping (boolean) – Flag if to use unicode box drawing characters, can cause errors in shells which does not support unicode
-
convertToHumandReadableSize
(filesize)[source]¶ Convert a file size in Byte to a string giving the size in GB, MB, kB or B.
-
getColonDelimitedTimeString
(seconds)[source]¶ Convert a time span into Colon Delimited Time Format, e.g. HH:MM:SS
-
getHoursMinutesSeconds
(seconds)[source]¶ Convert a time span in seconds to appropriate format in hours, minutes and seconds
-
sci_notation
(num, decimal_digits=1, precision=None, exponent=None)[source]¶ Returns a string representation of the scientific notation of the given number formatted for use with LaTeX or Mathtext, with specified number of significant decimal digits and precision (number of decimal digits to show). The exponent to be used can also be specified explicitly.