def parsenamefile(namfilename, packages, verbose=True):
    # add the .nam extension to namfilename if missing
    if not os.path.isfile(namfilename):
        if namfilename[-4:].lower() != '.nam':
            namfilename += '.nam'
    
    # initiate the ext_unit_dict dictionary
    ext_unit_dict = dict()

    if verbose:
        print('Parsing the namefile --> {0:s}'.format(namfilename))
        print('Setting filehandles:')

    if not os.path.isfile(namfilename):
        dn = os.path.dirname(namfilename)
        s = 'Could not find {} in path {} with files \n {}'.format(namfilename, dn, os.listdir(dn))
        raise Exception(s)
    indata = open(namfilename, 'r').readlines()
    for line in indata:
        tmp = line.strip().split()
        if len(tmp) == 0:
            continue
        # be sure the line is not a comment
        if '#' not in tmp[0]:
            # be sure the second value is an integer
            if testint(tmp[1]):
                fname = os.path.join(os.path.dirname(namfilename), tmp[2])
                if not os.path.isfile(fname):
                    # change to lower and make comparison (required for linux)
                    dn = os.path.dirname(fname)
                    fls = os.listdir(dn)
                    lownams = [f.lower() for f in fls]
                    bname = os.path.basename(fname)
                    if bname.lower() in lownams:
                        idx = lownams.index(bname.lower())
                        fname = os.path.join(dn, fls[idx])
                # parse the line
                openmode = 'r'
                if tmp[0].upper() == 'DATA(BINARY)':
                    openmode = 'rb'
                try:
                    filehandle = open(fname, openmode)
                except:
                    if verbose:
                        print('could not set filehandle for {0:s}'\
                            .format(tmp[2]))
                    filehandle = None
                # populate the dictionary
                key = int(tmp[1])
                #
                # Trap for the case where unit numbers are specified as zero
                # In this case, the package must have a variable called
                # unit number attached to it.  If not, then the key is set
                # to fname
                if key == 0:
                    ftype = tmp[0].lower()
                    if ftype in packages:
                        key = packages[ftype].unitnumber
                    else:
                        key = tmp[0]
                ext_unit_dict[key] = NamData(tmp[0].upper(), fname, filehandle,
                                             packages)
    return ext_unit_dict
Filter products that the user doesn't have permission to update
dataset/ETHPy150Open modflowpy/flopy/flopy/utils/mfreadnam.py/parsenamefile--crossover with--dataset/ETHPy150Open django-oscar/django-oscar/src/oscar/apps/dashboard/catalogue/views.py/ProductDeleteView.get_queryset