Index: build/alarmMapping.py =================================================================== diff -u -rca9cd0f4809f448d5622f991d46b88cd497a88c8 -r773623f0a40dbfcd86f8f6940c60200c08e33f33 --- build/alarmMapping.py (.../alarmMapping.py) (revision ca9cd0f4809f448d5622f991d46b88cd497a88c8) +++ build/alarmMapping.py (.../alarmMapping.py) (revision 773623f0a40dbfcd86f8f6940c60200c08e33f33) @@ -2,32 +2,46 @@ import sys from openpyxl import load_workbook +import json +# Load JSON file content into data dictionary +def load_input_format(): + with open('alarms_format.json') as json_file: + dic = json.load(json_file) + + return dic + + +dic_data_format = load_input_format() + # Default source and destination values for a local run -src = "Alarms.xlsx" -dst = "/home/denali/Projects/application/resources/settings/Alarms/Alarms.conf" +#src = "Alarms.xlsx" +#dst = "/home/denali/Projects/application/resources/settings/Alarms/Alarms.conf" try: # Source is the first input argument # Destination is the second input argument # NOTE: try and except was used to make sure when this script is run locally, it can be called without passing any # input arguments even as empty strings. In case of an exception do nothing and just pass. - src = sys.argv[1] + src = sys.argv[1] dst = sys.argv[2] except: + print("No argv[] parameters defined, using values from JSON file") + src = dic_data_format['source_data'] + dst = dic_data_format['destination'] pass + exl = load_workbook(src) if 'Alarms' in exl.sheetnames: alarms = exl['Alarms' ] else: print('Alarms sheet not found') - -col_alarms_id = 14 #9 -col_alarms_title = 8 #5 -col_alarms_message = 10 #6 +col_alarms_id = dic_data_format['col_alarms_id'] #9 +col_alarms_title = dic_data_format['col_alarms_title'] #8 +col_alarms_message = dic_data_format['col_alarms_message'] #10 # it has been assumed that for each alarm multiple lines of instruction will follow. # there are a lot of other options to get instruction but the output CSV format/structure is important. @@ -37,15 +51,16 @@ # # -col_instruction_title = 5 # just as an example -col_instruction_image = 6 # just as an example +col_instruction_title = dic_data_format['col_instruction_title'] #5 +col_instruction_image = dic_data_format['col_instruction_image'] #6 conf_content = "" -row = 2 # firs row is title +row = dic_data_format['row_starting_data'] #2 first row is title header val_alarm_id_prv = None val_alarm_id_cur = alarms.cell(row=row, column=col_alarms_id ).value val_alarm_id_hdr = True + while val_alarm_id_cur != None: if val_alarm_id_hdr: conf_content += "[{}]\n" .format(val_alarm_id_cur ) @@ -73,11 +88,11 @@ val_alarm_id_cur = alarms.cell(row=row, column=col_alarms_id ).value val_alarm_id_hdr = val_alarm_id_cur != val_alarm_id_prv val_alarm_id_prv = val_alarm_id_cur + if val_alarm_id_hdr: conf_content += '\n' cnf = open(dst, "w") cnf.write(conf_content) cnf.close() -