Calculate row format.

    Args:
        columns (dict): the keys are the column name and the value the max length.
        keys (list): optional list of keys to order columns as well as to filter for them.

    Returns:
        str: format for table row

def calculate_row_format(columns, keys=None):
    """
    Calculate row format.

    Args:
        columns (dict): the keys are the column name and the value the max length.
        keys (list): optional list of keys to order columns as well as to filter for them.

    Returns:
        str: format for table row
    """
    row_format = ''
    if keys is None:
        keys = columns.keys()
    else:
        keys = [key for key in keys if key in columns]

    for key in keys:
        if len(row_format) > 0:
            row_format += "|"
        row_format += "%%(%s)-%ds" % (key, columns[key])

    return '|' + row_format + '|'