Пример #1
0
def main(args):
    conf_curr = {}
    conf_prev = {}
    chapters = {}
    outfile = 'config.xlsx'
    excludes = []

    opts, args = getopt.getopt(args, 'o:x:')
    for k, v in opts:
        if k == '-o':
            outfile = v
        elif k == '-x':
            excludes = v.split(',')

    for arg in args:
        if ESR_CURRENT in arg:
            print('%s -> %s' % (ESR_CURRENT, arg))
            conf_curr = adlib.load_as_dict(arg)
        elif ESR_PREVIOUS in arg:
            print('%s -> %s' % (ESR_PREVIOUS, arg))
            conf_prev = adlib.load_as_dict(arg)
        elif CHAPTERS_CSV in arg:
            print('Loading', os.path.basename(arg))
            chapters = load_chapters(arg)

    with xlsxwriter.Workbook(outfile) as wb:
        generate_xlsx(wb, conf_curr, conf_prev, chapters, excludes)

    print('Generated:', wb.filename)
def generate_xlsx(workbook, confs, verification_chapters, exclude_worksheets):
    formats = create_formats(workbook)
    prev_conf = confs[ESR_PREVIOUS.upper()]

    for title, sources in WORKBOOKS:
        if title in exclude_worksheets:
            continue

        sheet = ConfigurationSheet(
            confs,
            formats,
            workbook.add_worksheet(title),
        )
        sheet.write_header()

        row_index = 1
        for source in sources:
            # We always output items based on sources for the current version.
            # In other words, the "current version" needs to define all deprecated/obsolete items
            # if they still need to be visible in the output sheet.
            base_items = adlib.load(os.path.join(BASEDIR, ESR_CURRENT, source))
            prev_items = adlib.load_as_dict(os.path.join(BASEDIR, ESR_PREVIOUS, source))

            sheet.merge_category_heading(row_index, base_items)

            for item in base_items:
                sheet.try_merge_item_heading(row_index, item)

                for option in item['options']:
                    row = ConfigurationRow(
                        sheet,
                        row_index,
                        item,
                        option,
                        source,
                        prev_conf,
                        prev_items,
                        verification_chapters,
                    )
                    row.write()
                    row_index += 1

        sheet.write_legend(row_index + 1)
def main(args):
    conf = {}
    chapters = {}
    outfile = 'config.xlsx'
    excludes = []

    opts, args = getopt.getopt(args, 'o:x:p:c:d:')
    for k, v in opts:
        if k == '-o':
            outfile = v
        elif k == '-x':
            excludes = v.split(',')
        elif k == '-p':
            conf[ESR_PREVIOUS.upper()] = v
        elif k == '-c':
            conf[ESR_CURRENT.upper()] = v
        elif k == '-d':
            parts = v.split(':', 1)
            conf[parts[0]] = parts[1]

    for arg in args:
        if ESR_PREVIOUS in arg and not ESR_PREVIOUS.upper() in conf:
            print('%s -> %s' % (ESR_PREVIOUS, arg))
            conf[ESR_PREVIOUS.upper()] = arg
        elif ESR_CURRENT in arg and not ESR_CURRENT.upper() in conf:
            print('%s -> %s' % (ESR_CURRENT, arg))
            conf[ESR_CURRENT.upper()] = arg
        elif CHAPTERS_CSV in arg:
            print('Loading', os.path.basename(arg))
            chapters = load_chapters(arg)

    for label, path in conf.items():
        conf[label] = adlib.load_as_dict(path)

    with xlsxwriter.Workbook(outfile) as wb:
        generate_xlsx(wb, conf, chapters, excludes)

    print('Generated:', wb.filename)
def main(args):
    confs   = {}
    outfile = 'config.xlsx'
    exclude_worksheets = []

    opts, args = getopt.getopt(args, 'o:x:p:c:d:')
    for key, value in opts:
        if key == '-o':
            outfile = value
        elif key == '-x':
            exclude_worksheets = value.split(',')
        elif key == '-p':
            confs[ESR_PREVIOUS.upper()] = value
        elif key == '-c':
            confs[ESR_CURRENT.upper()] = value
        elif key == '-d':
            parts = value.split(':', 1)
            confs[parts[0]] = parts[1]

    verification_chapters = {}
    for arg in args:
        if ESR_PREVIOUS in arg and not ESR_PREVIOUS.upper() in confs:
            print('%s -> %s' % (ESR_PREVIOUS, arg))
            confs[ESR_PREVIOUS.upper()] = arg
        elif ESR_CURRENT in arg and not ESR_CURRENT.upper() in confs:
            print('%s -> %s' % (ESR_CURRENT, arg))
            confs[ESR_CURRENT.upper()] = arg
        elif CHAPTERS_CSV in arg:
            print('Loading', os.path.basename(arg))
            verification_chapters = load_verification_chapters(arg)

    for version, path in confs.items():
        confs[version] = adlib.load_as_dict(path)

    with xlsxwriter.Workbook(outfile) as workbook:
        generate_xlsx(workbook, confs, verification_chapters, exclude_worksheets)

    print('Generated:', workbook.filename)
Пример #5
0
def generate_xlsx(wb, conf_curr, conf_prev, chapters, excludes):
    formats = create_formats(wb)

    for title, files in WORKBOOK_DEF:
        if title in excludes:
            continue

        sheet = wb.add_worksheet(title)
        write_header(sheet, formats)

        row = 1
        for fn in files:
            curr = adlib.load(os.path.join(BASEDIR, ESR_CURRENT, fn))
            prev = adlib.load_as_dict(os.path.join(BASEDIR, ESR_PREVIOUS, fn))
            sheet.merge_range(row, 0, row + count_options(curr) - 1, 0, '')

            for item in curr:
                if len(item['opts']) > 1:
                    sheet.merge_range(row, 1, row + len(item['opts']) - 1, 1,
                                      '')
                    sheet.merge_range(row, 2, row + len(item['opts']) - 1, 2,
                                      '')

                for opt in item['opts']:
                    selected = ''
                    status = ''
                    chapter = ''
                    fmt = formats['default']
                    item_fmt = formats['default']
                    opt_id = opt['opt_id']

                    if is_deprecated(item['item_title']):
                        item_fmt = formats['deprecated']
                        fmt = formats['deprecated']
                    elif is_deprecated(opt['opt_title']):
                        fmt = formats['deprecated']
                    elif opt_id in conf_curr:
                        selected = 'y'
                        chapter = chapters.get(opt_id, '省略')
                        if opt_id not in conf_prev:
                            fmt, status = formats['selected_changed'], '新規'
                        elif conf_prev[opt_id] != conf_curr[opt_id]:
                            fmt, status = formats['selected_changed'], '変更あり'
                        else:
                            fmt, status = formats['selected'], ''

                    sheet.write(row, 0, fn, formats['default'])
                    sheet.write(row, 1, int(item['item_no']), item_fmt)
                    sheet.write(row, 2, item['item_title'], item_fmt)
                    sheet.write(row, 3, selected, fmt)
                    sheet.write(row, 4, int(opt['opt_no']), fmt)
                    sheet.write(row, 5, opt['opt_title'], fmt)
                    sheet.write(row, 6, opt['conf'].strip(), fmt)
                    sheet.write(row, 7, conf_curr.get(opt_id, ''), fmt)
                    sheet.write(row, 8, status, fmt)
                    sheet.write(row, 9, chapter, formats['default'])
                    sheet.write(row, 10, '', formats['noborder'])
                    sheet.write(row, 11, prev.get(opt_id, ''), fmt)
                    sheet.write(row, 12, conf_prev.get(opt_id, ''), fmt)
                    row += 1
        write_legend(sheet, formats, row + 1)
def generate_xlsx(wb, conf, chapters, excludes):
    formats = create_formats(wb)
    prev_conf = conf[ESR_PREVIOUS.upper()]

    for title, files in WORKBOOK_DEF:
        if title in excludes:
            continue

        sheet = wb.add_worksheet(title)
        write_header(sheet, formats, conf)

        row = 1
        for fn in files:
            curr = adlib.load(os.path.join(BASEDIR, ESR_CURRENT, fn))
            prev = adlib.load_as_dict(os.path.join(BASEDIR, ESR_PREVIOUS, fn))
            sheet.merge_range(row, 0, row + count_options(curr) - 1, 0, '')

            for item in curr:
                if len(item['opts']) > 1:
                    sheet.merge_range(row, 1, row + len(item['opts']) - 1, 1, '')
                    sheet.merge_range(row, 2, row + len(item['opts']) - 1, 2, '')

                for opt in item['opts']:
                    status = ''
                    chapter = ''
                    fmt = formats['default']
                    item_fmt = formats['default']
                    opt_id = opt['opt_id']

                    applied_prev_conf = prev_conf.get(opt_id, {'conf':''})['conf']
                    template_curr_conf = opt['conf'].strip()
                    template_prev_conf = prev.get(opt_id, {'conf':''})['conf']

                    if is_deprecated(item['item_title']):
                        item_fmt = formats['deprecated']

                    col_count = 5
                    base_conf = prev_conf
                    applied_base_conf = applied_prev_conf
                    for key, variation_conf in conf.items():
                        if key == key == ESR_PREVIOUS.upper():
                            continue

                        variation_status = ''
                        variation_fmt = ''
                        applied_variation_conf = variation_conf.get(opt_id, {'conf':''})['conf']

                        if is_deprecated(item['item_title']) or is_deprecated(opt['opt_title']):
                            variation_fmt = formats['deprecated']
                        elif opt_id in variation_conf:
                            chapter = chapters.get(opt_id, '省略')
                            if opt_id not in base_conf:
                                variation_fmt, variation_status = formats['selected_changed'], '新規'
                            elif sanitize_conf(applied_base_conf) != sanitize_conf(applied_variation_conf):
                                variation_fmt, variation_status = formats['selected_changed'], '変更あり'
                            else:
                                variation_fmt, variation_status = formats['selected'], ''
                        elif base_conf == prev_conf:
                            if sanitize_conf(template_curr_conf) != sanitize_conf(template_prev_conf):
                              chapter = chapters.get(opt_id, '省略')
                              if template_prev_conf == '':
                                  variation_fmt, variation_status = formats['changed'], '新規(未設定)'
                              else:
                                  variation_fmt, variation_status = formats['changed'], '変更あり(未設定)'
                        else:
                            if sanitize_conf(applied_base_conf) != sanitize_conf(applied_variation_conf):
                                variation_status = '削除'

                        if base_conf == prev_conf:
                          fmt = variation_fmt

                        sheet.write(row, col_count+1, applied_variation_conf, variation_fmt)
                        sheet.write(row, col_count+2, variation_status, variation_fmt)
                        col_count+=2
                        base_conf = variation_conf
                        applied_base_conf = applied_variation_conf

                    sheet.write(row, 0, fn, formats['default']) # A
                    sheet.write(row, 1, int(item['item_no']), item_fmt) # B
                    sheet.write(row, 2, item['item_title'], item_fmt) # C
                    sheet.write(row, 3, int(opt['opt_no']), fmt) # D
                    sheet.write(row, 4, opt['opt_title'], fmt) # E
                    sheet.write(row, 5, template_curr_conf, fmt) # F

                    sheet.write(row, col_count+1, chapter, formats['default'])
                    sheet.write(row, col_count+2, '', formats['noborder'])
                    sheet.write(row, col_count+3, template_prev_conf, fmt)
                    sheet.write(row, col_count+4, applied_prev_conf, fmt)
                    row += 1
        write_legend(sheet, formats, row+1)