def add_package_ids(catalogitems, itemname_to_pkgid, pkgid_to_itemname):
    'Adds packageids from each catalogitem to two dictionaries.\n    One maps itemnames to receipt pkgids, the other maps receipt pkgids\n    to itemnames'
    for item in catalogitems:
        name = item.get('name')
        if (not name):
            continue
        if item.get('receipts'):
            if (not (name in itemname_to_pkgid)):
                itemname_to_pkgid[name] = {}
            for receipt in item['receipts']:
                if (('packageid' in receipt) and ('version' in receipt)):
                    pkgid = receipt['packageid']
                    vers = receipt['version']
                    if (not (pkgid in itemname_to_pkgid[name])):
                        itemname_to_pkgid[name][pkgid] = []
                    if (not (vers in itemname_to_pkgid[name][pkgid])):
                        itemname_to_pkgid[name][pkgid].append(vers)
                    if (not (pkgid in pkgid_to_itemname)):
                        pkgid_to_itemname[pkgid] = {}
                    if (not (name in pkgid_to_itemname[pkgid])):
                        pkgid_to_itemname[pkgid][name] = []
                    if (not (vers in pkgid_to_itemname[pkgid][name])):
                        pkgid_to_itemname[pkgid][name].append(vers)
Adds packageids from each catalogitem to two dictionaries.
One maps itemnames to receipt pkgids, the other maps receipt pkgids
to itemnames
def add_package_ids(catalogitems, itemname_to_pkgid, pkgid_to_itemname):
    'Adds packageids from each catalogitem to two dictionaries.\n    One maps itemnames to receipt pkgids, the other maps receipt pkgids\n    to itemnames'
    for item in catalogitems:
        name = item.get('name')
        if (not name):
            continue
        if item.get('receipts'):
            if (not (name in itemname_to_pkgid)):
                itemname_to_pkgid[name] = {}
            for receipt in item['receipts']:
                if (('packageid' in receipt) and ('version' in receipt)):
                    pkgid = receipt['packageid']
                    vers = receipt['version']
                    if (not (pkgid in itemname_to_pkgid[name])):
                        itemname_to_pkgid[name][pkgid] = []
                    if (not (vers in itemname_to_pkgid[name][pkgid])):
                        itemname_to_pkgid[name][pkgid].append(vers)
                    if (not (pkgid in pkgid_to_itemname)):
                        pkgid_to_itemname[pkgid] = {}
                    if (not (name in pkgid_to_itemname[pkgid])):
                        pkgid_to_itemname[pkgid][name] = []
                    if (not (vers in pkgid_to_itemname[pkgid][name])):
                        pkgid_to_itemname[pkgid][name].append(vers)