Пример #1
0
class Columns(object):
    def __init__(self):
        self.attr = Attribute(lenVar=4)

    def columns(self, file):
        lines = open(file).readlines()
        clearLines = map(
            l672, filter(all3(isNotRem, isNotBlank, isNotEjectOrSkip), lines))
        joinLines = []
        holder = []
        for l in clearLines:
            holder.append(l if not holder else l.strip())
            if l.endswith('.'):
                joinLines.append(" ".join(holder))
                holder = []
        lines = joinLines

        addColumns = []
        filler = 0
        redefines = False
        lvlAnt = 0

        for lin in lines:

            line = lin[:-1]
            wrd, wrds = words(line)

            if not wrds[0].isdigit():
                continue

            level = int(wrds[0])

            if redefines:
                if level > lvlAnt:
                    continue
            redefines = False

            if 'REDEFINES' in wrds:
                lvlAnt = level
                redefines = True
                continue

            if 'PIC' not in wrds:
                continue

            dataName = wrds[1].lower().replace('-', '_')
            if dataName == 'filler':
                continue
            picture = line.split('PIC')[1].split()
            pic = picture[0]
            usage = picture[1] if len(
                picture) > 1 and picture[1] != 'VALUE' else None
            occurs = picture[2:] if len(
                picture) > 2 and picture[2] == 'OCCURS' else None
            type, length, decimals = self.attr.attribute_json(
                pic, usage, occurs)

            tCol = '{}"field": "{}", "type": "{}", "length": "{}", "decimals":  "{}"{}\n'.format(
                '{', dataName, type, length, decimals, '}')
            addColumns.append(tCol)
        return addColumns
Пример #2
0
from attribute import Attribute
attr = Attribute()
line = '03  C-G-C-RB            PIC S9(14)V(4)  COMP-3.'
pic = line.split('PIC')[1].replace('.', '').split()
att = attr.attribute_json(pic[0], pic[1])
print att
line = '03  C-G-C-RB            PIC S9(4)  COMP.'
pic = line.split('PIC')[1].replace('.', '').split()
att = attr.attribute_json(pic[0], pic[1])
print att
line = '03  C-G-C-RB            PIC X(24).'
pic = line.split('PIC')[1].replace('.', '').split()
att = attr.attribute_json(pic[0])
print att
Пример #3
0
class Columns(object):
    def __init__(self):
        self.attr = Attribute(lenVar=4)

    def columns(self, file, fmt='json', signal=True):
        self.fmt = fmt
        basename = os.path.basename(file).split('.')[0]
        file = open(file).readlines()
        lines = Homogenize(file)

        addColumns = []
        filler = 0
        redefines = False
        lvlAnt = 0

        for line in lines:

            match = CobolPatterns.row_pattern.match(line.strip())

            if not match:
                continue

            match = match.groupdict()

            if not match['level']:
                continue

            line = line[:-1]
            if self.fmt != 'json':
                line = ' ' * 6 + line

            level = int(match['level'])

            if redefines:
                if level > lvlAnt:
                    continue
            redefines = False

            if match['redefines']:
                lvlAnt = level
                redefines = True
                continue

            if not match['pic']:
                if self.fmt != 'json':
                    addColumns.append(line + '.\n')
                continue

            dataname = match['name'].replace('-', '_').lower()
            if dataname == 'filler':
                filler += 1
                dataname = '{}_{}_{:02}'.format(basename.lower(), dataname,
                                                filler)

            if self.fmt == 'json':
                type, length, decimals, sign = self.attr.attribute_json(
                    match['pic'], match['usage'], match['occurs'], signal)

                jCol = (
                    '{}"field": "{}", "type": "{}", "length": {}, "decimals": {}, "sign": '
                    '{}{}\n').format('{', dataname, type, length, decimals,
                                     sign, '}')
                addColumns.append(jCol)
            else:
                lCol = line.replace(line.split('PIC')[1].strip(), match['pic'])
                sign = '.\n'
                if match['pic'][0] == 'S':
                    if signal:
                        sign = ' SIGN TRAILING SEPARATE.\n'
                    else:
                        lCol = re.sub('PIC\s+S', 'PIC  ', lCol)
                    if len(lCol) > 73 - len(sign):
                        addColumns.append(lCol + '\n')
                        addColumns.append('{:>72}'.format(sign))
                    else:
                        addColumns.append(lCol + sign)
                else:
                    addColumns.append(lCol + sign)
        return addColumns
Пример #4
0
class Columns(object):

    def __init__(self):
        self.attr = Attribute(lenVar=4)

    def columns(self, file):
        lines = open(file).readlines()
        clearLines = map(l672, filter(all3(isNotRem, isNotBlank, isNotEjectOrSkip), lines))
        joinLines = []
        holder = []
        for l in clearLines:
            holder.append(l if not holder else l.strip())
            if l.endswith('.'):
                joinLines.append(" ".join(holder))
                holder = []
        lines = joinLines

        addColumns = []
        filler = 0
        redefines = False
        lvlAnt = 0

        for lin in lines:

            line = lin[:-1]
            wrd, wrds = words(line)

            if not wrds[0].isdigit():
                continue

            level = int(wrds[0])

            if redefines:
                if level > lvlAnt:
                    continue
            redefines = False

            if 'REDEFINES' in wrds:
                lvlAnt = level
                redefines = True
                continue

            if 'PIC' not in wrds:
                continue

            dataName = wrds[1].lower().replace('-','_')
            if dataName == 'filler':
                continue
            picture = line.split('PIC')[1].split()
            pic = picture[0]
            usage = picture[1] if len(picture) > 1 and picture[1] != 'VALUE' else None
            occurs = picture[2:] if len(picture) > 2 and picture[2] == 'OCCURS' else None
            type, length, decimals = self.attr.attribute_json(pic, usage, occurs)

            tCol = '{}"field": "{}", "type": "{}", "length": "{}", "decimals":  "{}"{}\n'.format('{',
                                                                                               dataName,
                                                                                               type,
                                                                                               length,
                                                                                               decimals,
                                                                                               '}')
            addColumns.append(tCol)
        return addColumns
Пример #5
0
class Columns(object):
    def __init__(self):
        self.attr = Attribute(lenVar=4)

    def columns(self, file, fmt='json', signal=True):
        self.fmt = fmt
        basename = os.path.basename(file).split('.')[0]
        file = open(file).readlines()
        lines = Homogenize(file)

        addColumns = []
        filler = 0
        redefines = False
        lvlAnt = 0

        for lin in lines:

            line = lin[:-1]
            if self.fmt != 'json':
                line = ' ' * 6 + line

            wrd, wrds = words(line)

            if not wrds[0].isdigit():
                continue

            level = int(wrds[0])

            if redefines:
                if level > lvlAnt:
                    continue
            redefines = False

            if 'REDEFINES' in wrds:
                lvlAnt = level
                redefines = True
                continue

            if 'PIC' not in wrds:
                if self.fmt != 'json':
                    addColumns.append(line + '.\n')
                continue

            dataname = wrds[1].lower().replace('-', '_')
            if dataname == 'filler':
                filler += 1
                dataname = '{}_{}_{:02}'.format(basename.lower(), dataname,
                                                filler)

            picture = line.split('PIC')[1].split()
            pic = picture[0]
            usage = picture[1] if len(
                picture) > 1 and picture[1] != 'VALUE' else None
            occurs = picture[2:] if len(
                picture) > 2 and picture[2] == 'OCCURS' else None
            if self.fmt == 'json':
                type, length, decimals, sign = self.attr.attribute_json(
                    pic, usage, occurs, signal)

                jCol = (
                    '{}"field": "{}", "type": "{}", "length": "{}", "decimals": "{}", "sign": '
                    '"{}"{}\n').format('{', dataname, type, length, decimals,
                                       sign, '}')
                addColumns.append(jCol)
            else:
                splt_pic = line.split('PIC')[1]
                repl_pic = splt_pic.replace(' USAGE ', '').replace(
                    'COMP-3', '').replace('COMP', '').rstrip()
                lCol = line.replace(splt_pic, repl_pic)
                sign = '.\n'
                if pic[0] == 'S':
                    if signal:
                        sign = ' SIGN TRAILING SEPARATE.\n'
                    else:
                        lCol = re.sub('PIC\s+S', 'PIC  ', lCol)
                    if len(lCol) > 73 - len(sign):
                        addColumns.append(lCol + '\n')
                        addColumns.append('{:>72}'.format(sign))
                    else:
                        addColumns.append(lCol + sign)
                else:
                    addColumns.append(lCol + sign)
        return addColumns