コード例 #1
0
ファイル: iddgaps3.py プロジェクト: JasonGlazer/eppy
def repeatingfieldsnames(fields):
    """get the names of the repeating fields"""
    fnames = [field['field'][0] for field in fields]
    fnames = [bunchhelpers.onlylegalchar(fname) for fname in fnames]
    fnames = [fname for fname in fnames if bunchhelpers.intinlist(fname.split())]
    fnames = [(bunchhelpers.replaceint(fname), None) for fname in fnames]
    dct = dict(fnames)
    repnames = fnames[:len(dct.keys())]
    return repnames
コード例 #2
0
ファイル: iddgaps3.py プロジェクト: JasonGlazer/eppy

    # get all fields
    fields = getfields(comm)
    
    # get repeating field names
    repnames = repeatingfieldsnames(fields)
    
    try:
        first = repnames[0][0] % (1, )
    except IndexError, e:
        continue

    # get all comments of the first repeating field names
    firstnames = [repname[0] % (1, ) for repname in repnames]
    fcomments = [field for field in fields if bunchhelpers.onlylegalchar(field['field'][0]) in firstnames]
    fcomments = [dict(fcomment) for fcomment in fcomments]
    for cm in fcomments:
        fld = cm['field'][0]
        fld = bunchhelpers.onlylegalchar(fld)
        fld = bunchhelpers.replaceint(fld)
        cm['field'] = [fld]

    for i, cm in enumerate(comm[1:]):
        thefield = cm['field'][0]
        thefield = bunchhelpers.onlylegalchar(thefield)
        if thefield == first:
            break
    first_i = i + 1

    newfields = []
コード例 #3
0
ファイル: iddgaps5.py プロジェクト: JasonGlazer/eppy
def missingkeys_standard(commdct, skiplist=None):
    """put missing keys in commdct for standard objects
    return a list of keys where it is unable to do so
    commdct is not returned, but is updated"""
    if skiplist == None:
        skiplist = []
    # find objects where all the fields are not named
    gkeys = [dtls[i] for i in range(len(dtls)) if commdct[i].count({}) > 2]
    nofirstfields = []
    # operatie on those fields
    for key_txt in gkeys:
        if key_txt in skiplist:
            continue
        # print key_txt
        # for a function, pass comm as a variable
        key_i = dtls.index(key_txt.upper())
        comm = commdct[key_i]



        # get all fields
        fields = getfields(comm)
    
        # get repeating field names
        repnames = repeatingfieldsnames(fields)
    
        try:
            first = repnames[0][0] % (1, )
        except IndexError, e:
            nofirstfields.append(key_txt)
            continue
        # print first

        # get all comments of the first repeating field names
        firstnames = [repname[0] % (1, ) for repname in repnames]
        fcomments = [field for field in fields if bunchhelpers.onlylegalchar(field['field'][0]) in firstnames]
        fcomments = [dict(fcomment) for fcomment in fcomments]
        for cm in fcomments:
            fld = cm['field'][0]
            fld = bunchhelpers.onlylegalchar(fld)
            fld = bunchhelpers.replaceint(fld)
            cm['field'] = [fld]

        for i, cm in enumerate(comm[1:]):
            thefield = cm['field'][0]
            thefield = bunchhelpers.onlylegalchar(thefield)
            if thefield == first:
                break
        first_i = i + 1

        newfields = []
        for i in range(1, len(comm[first_i:]) / len(repnames) + 1):
            for fcomment in fcomments:
                nfcomment = dict(fcomment)
                fld = nfcomment['field'][0]
                fld = fld % (i, )
                nfcomment['field'] = [fld]
                newfields.append(nfcomment)

        for i, cm in enumerate(comm):
            if i < first_i:
                continue
            else:
                afield = newfields.pop(0)
                comm[i] = afield
        commdct[key_i] = comm