def setUp(self): array_test, list_test = 'arrayParsing_test', 'listParsing_test' text_test, global_test = 'textParsing_test', 'global_test' array_error_test, array_error_test2 = 'arrayParsing_error_test', 'arrayParsing_error2_test' my_template = "{{hostname}}\n{{VLAN_error}}\n{{VLAN_error2}}\n{{VLAN}}\n{{VLAN!((VLAN!104:Name)):Gateway}}" self.workbook = dict() self.workbook['VLAN'] = ArrayParsing( get_sheet_test(array_test + '.xlsx')) self.workbook['VLAN_error'] = ArrayParsing( get_sheet_test(array_error_test + '.xlsx')) self.workbook['VLAN_error2'] = ArrayParsing( get_sheet_test(array_error_test2 + '.xlsx')) self.workbook[list_test] = ListParsing( get_sheet_test(list_test + '.xlsx')) self.workbook[text_test] = TextParsing( get_sheet_test(text_test + '.xlsx')) self.workbook['Global'] = ArrayParsing( get_sheet_test(global_test + '.xlsx')) self.equipment = Equipment('HOST1', my_template, self.workbook) self.equipment.unresolved = 1 self.equipment.resolved = 2
def main(excel_file, template_file, directory): wb = get_excel_workbook(excel_file) sheet_names = wb.sheet_names() workbook = dict() template = open_file(template_file) for sheet in sheet_names: xl_sheet = wb.sheet_by_name(sheet) if (xl_sheet.cell(0, 0).value == 'Function' and xl_sheet.cell(0, 1).value == 'Variable' and xl_sheet.cell(0, 2).value == 'Value'): workbook[sheet] = ListParsing(xl_sheet) elif xl_sheet.cell(0, 0).value == 'Text': workbook[sheet] = TextParsing(xl_sheet) elif sheet == 'Interfaces': workbook[sheet] = Interface(xl_sheet) else: workbook[sheet] = ArrayParsing(xl_sheet) if not directory: directory = os.path.dirname(template_file) is_directory = False version_number = 1 while is_directory is False: directory_name = ''.join(['scripts-', os.path.splitext(os.path.basename(excel_file))[0], '-v', str(version_number)]) if os.path.isdir(os.path.join(directory, directory_name)) is False: directory = os.path.join(directory, directory_name) os.mkdir(directory) is_directory = True version_number += 1 list_of_equipments = list() for hostname in workbook['Global'].get_all_indexes(): equipment = Equipment(hostname, template, workbook) list_of_equipments.append(equipment) equipment.save_script_as(directory, hostname)
def setUp(self): self.sheet = ArrayParsing(get_sheet_test('arrayParsing_test.xlsx'))