Utils¶
Utility functions used by all the modules
- utils.utils.CSVEmpty(log_filepath, min_len=0)[source]¶
Check if given csv is empty by counting number of rows
- Parameters:
log_filepath – csv path
min_len – minimum number of rows after which csv is not considered empty
- Returns:
true if csv is empty
- class utils.utils.ThreadWithReturnValue(group=None, target=None, name=None, args=(), kwargs={}, Verbose=None)[source]¶
- __init__(group=None, target=None, name=None, args=(), kwargs={}, Verbose=None)[source]¶
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.
- join(*args)[source]¶
Wait until the thread terminates.
This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.
When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.
When the timeout argument is not present or None, the operation will block until the thread terminates.
A thread can be join()ed many times.
join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.
- run()[source]¶
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- utils.utils.add_json_element(node, key, value)[source]¶
Adds a JSON element to the specified node.
- Args:
node (dict): The node to add the element to. key (str): The key of the element. value (any): The value of the element.
- utils.utils.combineMultipleCsv(list_of_csv_to_combine, combined_csv_path)[source]¶
Combine multiple csv in a single file
- Parameters:
list_of_csv_to_combine – list of csv paths
combined_csv_path – path where to save combined csv
- utils.utils.concatIntoNoiseDf(noiseDf: DataFrame, value: str, colName: str, rowId: int) DataFrame [source]¶
Takes as input a df and a col/row/value combination and addes the row to the noiseDf
- Parameters:
noiseDf – Dataframe with Cols Value, Column Name, and Row ID
value – value of the cell that is noise
colName – Column name of the noisy cell
rowId – Row ID of the noisy cell
- Returns:
noiseDf with the added row
- utils.utils.convertToWindowsPath(path, username_on_source_os)[source]¶
convert path to windows path with trailing slashes
- Parameters:
path – input path
username_on_source_os – username of user on source operating system
- Returns:
path formatted for windows
- utils.utils.createDirectory(path)[source]¶
Create directory with the given path if it does not exist
- Parameters:
path – path of directory to be created
- utils.utils.createLogFile()[source]¶
Creates new log file with the current timestamp in /logs directory at the root of the project. used by main.
- Returns:
path of created log
- utils.utils.formatPathForCurrentOS(path, username_on_source_os)[source]¶
format a given path for current OS
- Parameters:
path – input path
username_on_source_os – username of user on source operating system
- Returns:
path with username of user of destination operating system
- utils.utils.getActiveWindowInfo(parameter)[source]¶
Get name and size of active window in foreground (windows only)
- Parameters:
parameter – either ‘name’ or ‘size’
- Returns:
name or size of active window
- utils.utils.getActiveWindowName()[source]¶
Get name of window in foreground (windows only)
- Returns:
name of window in foreground
- utils.utils.getChromeVersionMac()[source]¶
return current chrome version, used to detect selenium driver
- Returns:
current chrome version
- utils.utils.getChromedriverPath()[source]¶
return chromedriver path from automagica module used by selenium
- Returns:
hromedriver pat
- utils.utils.getFileExtension(path)[source]¶
return file extension of a given path like .csv
- Parameters:
path – input path
- Returns:
file extension of given path (e.g. .csv)
- utils.utils.getFilename(path)[source]¶
return filename of a given path without extension, like 2020-02-25_23-21-57
- Parameters:
path – path of event log
- Returns:
filename without extension
- utils.utils.getHostname(url)[source]¶
Get hostname from url
- Parameters:
url – url
- Returns:
hostname of url
- utils.utils.getPythonModuleLocation(module_name)[source]¶
return python module install location
- Parameters:
module_name – name of module to find
- Returns:
install location
- utils.utils.getRPADirectory(csv_file_path)[source]¶
Genreate path to save RPA files.
RPA_directory is like /Users/marco/Desktop/ComputerLogger/RPA/2020-02-25_23-21-57
- Parameters:
str (csv_file_path) – path of event log in input
- Returns:
path of RPA directory
- utils.utils.get_last_directory_name(path)[source]¶
Returns the name of the last directory within a given directory path.
- Parameters:
path – Path to the parent folder
- Returns:
“Newest” directory file name
- Return type:
String
- utils.utils.isInstalledMac(programName)[source]¶
detect if program is installed in /Applications folder on mac
- Parameters:
programName – name of program to be checked
- Returns:
true if program is present in /Applications folder, else false
- utils.utils.isInstalledWin(programName)[source]¶
detect if program (both 32bit and 64bit) is installed checking windows registry
- Parameters:
programName – name of program to be checked
- Returns:
true if program is installed, else false
- utils.utils.isPortInUse(port)[source]¶
check if port is available to start server
- Parameters:
port – port number
- Returns:
true if given port is in use by another process
- utils.utils.processClipboard(cb, remove_whitespaces=False)[source]¶
convert clipboard text to unicode and remove whitespaces
- Parameters:
cb – clipboard text
remove_whitespaces – boolean, if true remove whitespaces
- Returns:
unicode version of clipboard text
- utils.utils.removeWhitespaces(string)[source]¶
remove spaces before and after words in a string
- Parameters:
string – input string
- Returns:
string without whitespaces
- utils.utils.staticNoiseIdentification(uilog: DataFrame) DataFrame [source]¶
Gets a UI log and identifies all cells containing static noise Static noise is noise that is identified using attributes default formats
- Parameters:
uilog – User interaction log dataframe
- Returns:
Dataframe with value, col, row that are considered noise
- utils.utils.takeScreenshot(save_image: bool = False, scrshtFormat: str = 'png')[source]¶
Takes a screenshot and saves it to a directory with a filename based on its hash, current date/time and order of capture.
- Parameters:
scrshtFormat – (Optional) File format of screenshot, Default type is png
save_image – (Boolean) Default True
- Returns:
Name of the screenshot file
- utils.utils.timestamp(format=None)[source]¶
Generate current timestamp in ISO format (e.g. ‘2020-08-29T16:42:30.690’)
- Parameters:
format – format (Default None) specifies the datetime format, if none it is ISO Format
- Returns:
timestamp in (ISO) format