Based on what was done in the parser, replicate the logic so it can be used in the python tools. Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>