import re


def ppdInfo(filename):
    """
    Get information from the printer's installed PPD file. All keys will
    be set to blank strings if they could not be found in the PPD.
    """
    textfile = open(filename, 'r')
    filetext = textfile.read()
    textfile.close()

    info = { }
    matches = re.findall('\*Manufacturer:[ \t]*\"(.*)\"', filetext)
    if len(matches) > 0:
        info['Manufacturer'] = matches[0]
    else:
        info['Manufacturer'] = ''

    matches = re.findall('\*ModelName:[ \t]*\"(.*)\"', filetext)
    if len(matches) > 0:
        info['ModelName'] = matches[0]
    else:
        info['ModelName'] = ''

    matches = re.findall('\*NickName:[ \t]*\"(.*)\"', filetext)
    if len(matches) > 0:
        info['NickName'] = matches[0]
    else:
        info['NickName'] = ''

    #
    # Update the Model and NickName to include the Manufacturer
    # if they do not already.
    #
    if len(info['ModelName']) > 0:
        if info['ModelName'].find(info['Manufacturer']) != 0:
            info['ModelName'] = info['Manufacturer'] + " " + info['ModelName']
        if info['NickName'].find(info['Manufacturer']) != 0:
            info['NickName'] = info['Manufacturer'] + " " + info['NickName']

    return info