objdictgen/eds_utils.py
changeset 580 2ae92a99ac10
parent 550 3486df466565
child 692 6818cc935ab1
equal deleted inserted replaced
577:0bb82be64630 580:2ae92a99ac10
   172                         # First case, value starts with "0x" or "-0x", then it's an hexadecimal value
   172                         # First case, value starts with "0x" or "-0x", then it's an hexadecimal value
   173                         if value.startswith("0x") or value.startswith("-0x"):
   173                         if value.startswith("0x") or value.startswith("-0x"):
   174                             try:
   174                             try:
   175                                 computed_value = int(value, 16)
   175                                 computed_value = int(value, 16)
   176                             except:
   176                             except:
   177                                 raise SyntaxError, "\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   177                                 raise SyntaxError, _("\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   178                         elif value.isdigit() or value.startswith("-") and value[1:].isdigit():
   178                         elif value.isdigit() or value.startswith("-") and value[1:].isdigit():
   179                             # Second case, value is a number and starts with "0" or "-0", then it's an octal value
   179                             # Second case, value is a number and starts with "0" or "-0", then it's an octal value
   180                             if value.startswith("0") or value.startswith("-0"):
   180                             if value.startswith("0") or value.startswith("-0"):
   181                                 computed_value = int(value, 8)
   181                                 computed_value = int(value, 8)
   182                             # Third case, value is a number and don't start with "0", then it's a decimal value
   182                             # Third case, value is a number and don't start with "0", then it's a decimal value
   191                         nodename_result = nodename_model.match(keyname.upper())
   191                         nodename_result = nodename_model.match(keyname.upper())
   192                         nodedcfname_result = nodedcfname_model.match(keyname.upper())
   192                         nodedcfname_result = nodedcfname_model.match(keyname.upper())
   193                         
   193                         
   194                         if keyname.upper() == "NETNAME":
   194                         if keyname.upper() == "NETNAME":
   195                             if not is_string(computed_value):
   195                             if not is_string(computed_value):
   196                                 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   196                                 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   197                             topology["Name"] = computed_value
   197                             topology["Name"] = computed_value
   198                         elif keyname.upper() == "NODES":
   198                         elif keyname.upper() == "NODES":
   199                             if not is_integer(computed_value):
   199                             if not is_integer(computed_value):
   200                                 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   200                                 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   201                             topology["Number"] = computed_value
   201                             topology["Number"] = computed_value
   202                         elif keyname.upper() == "EDSBASENAME":
   202                         elif keyname.upper() == "EDSBASENAME":
   203                             if not is_string(computed_value):
   203                             if not is_string(computed_value):
   204                                 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   204                                 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   205                             topology["Path"] = computed_value
   205                             topology["Path"] = computed_value
   206                         elif nodepresent_result:
   206                         elif nodepresent_result:
   207                             if not is_boolean(computed_value):
   207                             if not is_boolean(computed_value):
   208                                 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   208                                 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   209                             nodeid = int(nodepresent_result.groups()[0])
   209                             nodeid = int(nodepresent_result.groups()[0])
   210                             if nodeid not in topology["Nodes"].keys():
   210                             if nodeid not in topology["Nodes"].keys():
   211                                 topology["Nodes"][nodeid] = {}
   211                                 topology["Nodes"][nodeid] = {}
   212                             topology["Nodes"][nodeid]["Present"] = computed_value
   212                             topology["Nodes"][nodeid]["Present"] = computed_value
   213                         elif nodename_result:
   213                         elif nodename_result:
   214                             if not is_string(value):
   214                             if not is_string(value):
   215                                 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   215                                 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   216                             nodeid = int(nodename_result.groups()[0])
   216                             nodeid = int(nodename_result.groups()[0])
   217                             if nodeid not in topology["Nodes"].keys():
   217                             if nodeid not in topology["Nodes"].keys():
   218                                 topology["Nodes"][nodeid] = {}
   218                                 topology["Nodes"][nodeid] = {}
   219                             topology["Nodes"][nodeid]["Name"] = computed_value
   219                             topology["Nodes"][nodeid]["Name"] = computed_value
   220                         elif nodedcfname_result:
   220                         elif nodedcfname_result:
   221                             if not is_string(computed_value):
   221                             if not is_string(computed_value):
   222                                 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   222                                 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   223                             nodeid = int(nodedcfname_result.groups()[0])
   223                             nodeid = int(nodedcfname_result.groups()[0])
   224                             if nodeid not in topology["Nodes"].keys():
   224                             if nodeid not in topology["Nodes"].keys():
   225                                 topology["Nodes"][nodeid] = {}
   225                                 topology["Nodes"][nodeid] = {}
   226                             topology["Nodes"][nodeid]["DCFName"] = computed_value
   226                             topology["Nodes"][nodeid]["DCFName"] = computed_value
   227                         else:
   227                         else:
   228                             raise SyntaxError, "Keyname \"%s\" not recognised for section \"[%s]\""%(keyname, section_name)
   228                             raise SyntaxError, _("Keyname \"%s\" not recognised for section \"[%s]\"")%(keyname, section_name)
   229                         
   229                         
   230                 # All lines that are not empty and are neither a comment neither not a valid assignment
   230                 # All lines that are not empty and are neither a comment neither not a valid assignment
   231                 elif assignment.strip() != "":
   231                 elif assignment.strip() != "":
   232                     raise SyntaxError, "\"%s\" is not a valid CPJ line"%assignment.strip()
   232                     raise SyntaxError, _("\"%s\" is not a valid CPJ line")%assignment.strip()
   233         
   233         
   234             if "Number" not in topology.keys():
   234             if "Number" not in topology.keys():
   235                 raise SyntaxError, "\"Nodes\" keyname in \"[%s]\" section is missing"%section_name
   235                 raise SyntaxError, _("\"Nodes\" keyname in \"[%s]\" section is missing")%section_name
   236         
   236         
   237             if topology["Number"] != len(topology["Nodes"]):
   237             if topology["Number"] != len(topology["Nodes"]):
   238                 raise SyntaxError, "\"Nodes\" value not corresponding to number of nodes defined"
   238                 raise SyntaxError, _("\"Nodes\" value not corresponding to number of nodes defined")
   239             
   239             
   240             for nodeid, node in topology["Nodes"].items():
   240             for nodeid, node in topology["Nodes"].items():
   241                 if "Present" not in node.keys():
   241                 if "Present" not in node.keys():
   242                     raise SyntaxError, "\"Node%dPresent\" keyname in \"[%s]\" section is missing"%(nodeid, section_name)
   242                     raise SyntaxError, _("\"Node%dPresent\" keyname in \"[%s]\" section is missing")%(nodeid, section_name)
   243             
   243             
   244             networks.append(topology)
   244             networks.append(topology)
   245             
   245             
   246         # In other case, there is a syntax problem into CPJ file
   246         # In other case, there is a syntax problem into CPJ file
   247         else:
   247         else:
   248             raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name
   248             raise SyntaxError, _("Section \"[%s]\" is unrecognized")%section_name
   249     
   249     
   250     return networks
   250     return networks
   251 
   251 
   252 # Function that parse an EDS file and returns a dictionary of the informations
   252 # Function that parse an EDS file and returns a dictionary of the informations
   253 def ParseEDSFile(filepath):
   253 def ParseEDSFile(filepath):
   273         if section_name.upper() in SECTION_KEYNAMES:
   273         if section_name.upper() in SECTION_KEYNAMES:
   274             # Verify that entry is not already defined
   274             # Verify that entry is not already defined
   275             if section_name.upper() not in eds_dict:
   275             if section_name.upper() not in eds_dict:
   276                 eds_dict[section_name.upper()] = values
   276                 eds_dict[section_name.upper()] = values
   277             else:
   277             else:
   278                 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
   278                 raise SyntaxError, _("\"[%s]\" section is defined two times")%section_name
   279         # Second case, section name is an index name 
   279         # Second case, section name is an index name 
   280         elif index_result:
   280         elif index_result:
   281             # Extract index number
   281             # Extract index number
   282             index = int(index_result.groups()[0], 16)
   282             index = int(index_result.groups()[0], 16)
   283             # If index hasn't been referenced before, we add an entry into the dictionary
   283             # If index hasn't been referenced before, we add an entry into the dictionary
   286                 eds_dict[index]["subindexes"] = {}
   286                 eds_dict[index]["subindexes"] = {}
   287             elif eds_dict[index].keys() == ["subindexes"]:
   287             elif eds_dict[index].keys() == ["subindexes"]:
   288                 values["subindexes"] = eds_dict[index]["subindexes"]
   288                 values["subindexes"] = eds_dict[index]["subindexes"]
   289                 eds_dict[index] = values
   289                 eds_dict[index] = values
   290             else:
   290             else:
   291                 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
   291                 raise SyntaxError, _("\"[%s]\" section is defined two times")%section_name
   292             is_entry = True
   292             is_entry = True
   293         # Third case, section name is a subindex name 
   293         # Third case, section name is a subindex name 
   294         elif subindex_result:
   294         elif subindex_result:
   295             # Extract index and subindex number
   295             # Extract index and subindex number
   296             index, subindex = [int(value, 16) for value in subindex_result.groups()]
   296             index, subindex = [int(value, 16) for value in subindex_result.groups()]
   299             if index not in eds_dict:
   299             if index not in eds_dict:
   300                 eds_dict[index] = {"subindexes" : {}}
   300                 eds_dict[index] = {"subindexes" : {}}
   301             if subindex not in eds_dict[index]["subindexes"]:
   301             if subindex not in eds_dict[index]["subindexes"]:
   302                 eds_dict[index]["subindexes"][subindex] = values
   302                 eds_dict[index]["subindexes"][subindex] = values
   303             else:
   303             else:
   304                 raise SyntaxError, "\"[%s]\" section is defined two times"%section_name
   304                 raise SyntaxError, _("\"[%s]\" section is defined two times")%section_name
   305             is_entry = True
   305             is_entry = True
   306         # Third case, section name is a subindex name 
   306         # Third case, section name is a subindex name 
   307         elif index_objectlinks_result:
   307         elif index_objectlinks_result:
   308             pass
   308             pass
   309         # In any other case, there is a syntax problem into EDS file
   309         # In any other case, there is a syntax problem into EDS file
   310         else:
   310         else:
   311             raise SyntaxError, "Section \"[%s]\" is unrecognized"%section_name
   311             raise SyntaxError, _("Section \"[%s]\" is unrecognized")%section_name
   312         
   312         
   313         for assignment in assignments:
   313         for assignment in assignments:
   314             # Escape any comment
   314             # Escape any comment
   315             if assignment.startswith(";"):
   315             if assignment.startswith(";"):
   316                 pass
   316                 pass
   328                     if value.upper().startswith("$NODEID"):
   328                     if value.upper().startswith("$NODEID"):
   329                         try:
   329                         try:
   330                             test = int(value.upper().replace("$NODEID+", ""), 16)
   330                             test = int(value.upper().replace("$NODEID+", ""), 16)
   331                             computed_value = "\"%s\""%value
   331                             computed_value = "\"%s\""%value
   332                         except:
   332                         except:
   333                             raise SyntaxError, "\"%s\" is not a valid formula for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   333                             raise SyntaxError, _("\"%s\" is not a valid formula for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   334                     # Second case, value starts with "0x", then it's an hexadecimal value
   334                     # Second case, value starts with "0x", then it's an hexadecimal value
   335                     elif value.startswith("0x") or value.startswith("-0x"):
   335                     elif value.startswith("0x") or value.startswith("-0x"):
   336                         try:
   336                         try:
   337                             computed_value = int(value, 16)
   337                             computed_value = int(value, 16)
   338                         except:
   338                         except:
   339                             raise SyntaxError, "\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   339                             raise SyntaxError, _("\"%s\" is not a valid value for attribute \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   340                     elif value.isdigit() or value.startswith("-") and value[1:].isdigit():
   340                     elif value.isdigit() or value.startswith("-") and value[1:].isdigit():
   341                         # Third case, value is a number and starts with "0", then it's an octal value
   341                         # Third case, value is a number and starts with "0", then it's an octal value
   342                         if value.startswith("0") or value.startswith("-0"):
   342                         if value.startswith("0") or value.startswith("-0"):
   343                             computed_value = int(value, 8)
   343                             computed_value = int(value, 8)
   344                         # Forth case, value is a number and don't start with "0", then it's a decimal value
   344                         # Forth case, value is a number and don't start with "0", then it's a decimal value
   352                     if computed_value != "":
   352                     if computed_value != "":
   353                         # If entry is an index or a subindex
   353                         # If entry is an index or a subindex
   354                         if is_entry:
   354                         if is_entry:
   355                             # Verify that keyname is a possible attribute
   355                             # Verify that keyname is a possible attribute
   356                             if keyname.upper() not in ENTRY_ATTRIBUTES:
   356                             if keyname.upper() not in ENTRY_ATTRIBUTES:
   357                                 raise SyntaxError, "Keyname \"%s\" not recognised for section \"[%s]\""%(keyname, section_name)
   357                                 raise SyntaxError, _("Keyname \"%s\" not recognised for section \"[%s]\"")%(keyname, section_name)
   358                             # Verify that value is valid
   358                             # Verify that value is valid
   359                             elif not ENTRY_ATTRIBUTES[keyname.upper()](computed_value):
   359                             elif not ENTRY_ATTRIBUTES[keyname.upper()](computed_value):
   360                                 raise SyntaxError, "Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\""%(value, keyname, section_name)
   360                                 raise SyntaxError, _("Invalid value \"%s\" for keyname \"%s\" of section \"[%s]\"")%(value, keyname, section_name)
   361                             else:
   361                             else:
   362                                 values[keyname.upper()] = computed_value
   362                                 values[keyname.upper()] = computed_value
   363                         else:
   363                         else:
   364                             values[keyname.upper()] = computed_value
   364                             values[keyname.upper()] = computed_value
   365             # All lines that are not empty and are neither a comment neither not a valid assignment
   365             # All lines that are not empty and are neither a comment neither not a valid assignment
   366             elif assignment.strip() != "":
   366             elif assignment.strip() != "":
   367                 raise SyntaxError, "\"%s\" is not a valid EDS line"%assignment.strip()
   367                 raise SyntaxError, _("\"%s\" is not a valid EDS line")%assignment.strip()
   368         
   368         
   369         # If entry is an index or a subindex
   369         # If entry is an index or a subindex
   370         if is_entry:
   370         if is_entry:
   371             # Verify that entry has an ObjectType
   371             # Verify that entry has an ObjectType
   372             values["OBJECTTYPE"] = values.get("OBJECTTYPE", 7)
   372             values["OBJECTTYPE"] = values.get("OBJECTTYPE", 7)
   379             required = set(ENTRY_TYPES[values["OBJECTTYPE"]]["require"])
   379             required = set(ENTRY_TYPES[values["OBJECTTYPE"]]["require"])
   380             # Verify that parameters defined contains all the parameters required
   380             # Verify that parameters defined contains all the parameters required
   381             if not keys.issuperset(required):
   381             if not keys.issuperset(required):
   382                 missing = required.difference(keys)._data.keys()
   382                 missing = required.difference(keys)._data.keys()
   383                 if len(missing) > 1:
   383                 if len(missing) > 1:
   384                     attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in missing])
   384                     attributes = _("Attributes %s are")%_(", ").join(["\"%s\""%attribute for attribute in missing])
   385                 else:
   385                 else:
   386                     attributes = "Attribute \"%s\" is"%missing[0]
   386                     attributes = _("Attribute \"%s\" is")%missing[0]
   387                 raise SyntaxError, "Error on section \"[%s]\":\n%s required for a%s entry"%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
   387                 raise SyntaxError, _("Error on section \"[%s]\":\n%s required for a %s entry")%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
   388             # Verify that parameters defined are all in the possible parameters
   388             # Verify that parameters defined are all in the possible parameters
   389             if not keys.issubset(possible):
   389             if not keys.issubset(possible):
   390                 unsupported = keys.difference(possible)._data.keys()
   390                 unsupported = keys.difference(possible)._data.keys()
   391                 if len(unsupported) > 1:
   391                 if len(unsupported) > 1:
   392                     attributes = "Attributes %s are"%", ".join(["\"%s\""%attribute for attribute in unsupported])
   392                     attributes = _("Attributes %s are")%_(", ").join(["\"%s\""%attribute for attribute in unsupported])
   393                 else:
   393                 else:
   394                     attributes = "Attribute \"%s\" is"%unsupported[0]
   394                     attributes = _("Attribute \"%s\" is")%unsupported[0]
   395                 raise SyntaxError, "Error on section \"[%s]\":\n%s unsupported for a%s entry"%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
   395                 raise SyntaxError, _("Error on section \"[%s]\":\n%s unsupported for a %s entry")%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
   396             
   396             
   397             VerifyValue(values, section_name, "ParameterValue")
   397             VerifyValue(values, section_name, "ParameterValue")
   398             VerifyValue(values, section_name, "DefaultValue")
   398             VerifyValue(values, section_name, "DefaultValue")
   399             
   399             
   400     return eds_dict
   400     return eds_dict
   410                 values[param.upper()] = {0 : False, 1 : True}[values[param.upper()]]
   410                 values[param.upper()] = {0 : False, 1 : True}[values[param.upper()]]
   411             else:
   411             else:
   412                 if not isinstance(values[param.upper()], (IntType, LongType)) and values[param.upper()].upper().find("$NODEID") == -1:
   412                 if not isinstance(values[param.upper()], (IntType, LongType)) and values[param.upper()].upper().find("$NODEID") == -1:
   413                     raise
   413                     raise
   414         except:
   414         except:
   415             raise SyntaxError, "Error on section \"[%s]\":\n%s incompatible with DataType"%(section_name, param)
   415             raise SyntaxError, _("Error on section \"[%s]\":\n%s incompatible with DataType")%(section_name, param)
   416 
   416 
   417 
   417 
   418 # Function that write an EDS file after generate it's content
   418 # Function that write an EDS file after generate it's content
   419 def WriteFile(filepath, content):
   419 def WriteFile(filepath, content):
   420     # Open file in write mode
   420     # Open file in write mode
   635         content = GenerateFileContent(node, filepath)
   635         content = GenerateFileContent(node, filepath)
   636         # Write file
   636         # Write file
   637         WriteFile(filepath, content)
   637         WriteFile(filepath, content)
   638         return None
   638         return None
   639     except ValueError, message:
   639     except ValueError, message:
   640         return "Unable to generate EDS file\n%s"%message
   640         return _("Unable to generate EDS file\n%s")%message
   641     
   641     
   642 # Function that generate the CPJ file content for the nodelist
   642 # Function that generate the CPJ file content for the nodelist
   643 def GenerateCPJContent(nodelist):
   643 def GenerateCPJContent(nodelist):
   644     nodes = nodelist.SlaveNodes.keys()
   644     nodes = nodelist.SlaveNodes.keys()
   645     nodes.sort()
   645     nodes.sort()
   679                     Node.SetProfile(Mapping)
   679                     Node.SetProfile(Mapping)
   680                     Node.SetSpecificMenu(AddMenuEntries)
   680                     Node.SetSpecificMenu(AddMenuEntries)
   681                 except:
   681                 except:
   682                     pass
   682                     pass
   683         # Read all entries in the EDS dictionary 
   683         # Read all entries in the EDS dictionary 
   684         for entry, values in eds_dict.items():
   684         for entry, values in eds_dict.iteritems():
   685             # All sections with a name in keynames are escaped
   685             # All sections with a name in keynames are escaped
   686             if entry in SECTION_KEYNAMES:
   686             if entry in SECTION_KEYNAMES:
   687                 pass
   687                 pass
   688             else:
   688             else:
   689                 # Extract informations for the entry
   689                 # Extract informations for the entry
   694                     # First case, entry is a DOMAIN or VAR
   694                     # First case, entry is a DOMAIN or VAR
   695                     if values["OBJECTTYPE"] in [2, 7]:
   695                     if values["OBJECTTYPE"] in [2, 7]:
   696                         if values["OBJECTTYPE"] == 2:
   696                         if values["OBJECTTYPE"] == 2:
   697                             values["DATATYPE"] = values.get("DATATYPE", 0xF)
   697                             values["DATATYPE"] = values.get("DATATYPE", 0xF)
   698                             if values["DATATYPE"] != 0xF:
   698                             if values["DATATYPE"] != 0xF:
   699                                 raise SyntaxError, "Domain entry 0x%4.4X DataType must be 0xF(DOMAIN) if defined"%entry
   699                                 raise SyntaxError, _("Domain entry 0x%4.4X DataType must be 0xF(DOMAIN) if defined")%entry
   700                         # Add mapping for entry
   700                         # Add mapping for entry
   701                         Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 1)
   701                         Node.AddMappingEntry(entry, name = values["PARAMETERNAME"], struct = 1)
   702                         # Add mapping for first subindex
   702                         # Add mapping for first subindex
   703                         Node.AddMappingEntry(entry, 0, values = {"name" : values["PARAMETERNAME"], 
   703                         Node.AddMappingEntry(entry, 0, values = {"name" : values["PARAMETERNAME"], 
   704                                                                  "type" : values["DATATYPE"], 
   704                                                                  "type" : values["DATATYPE"], 
   772                             # Find default value for value type of the subindex
   772                             # Find default value for value type of the subindex
   773                             else:
   773                             else:
   774                                 value = GetDefaultValue(Node, entry, subindex)
   774                                 value = GetDefaultValue(Node, entry, subindex)
   775                             Node.AddEntry(entry, subindex, value)
   775                             Node.AddEntry(entry, subindex, value)
   776                     else:
   776                     else:
   777                         raise SyntaxError, "Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute"%entry
   777                         raise SyntaxError, _("Array or Record entry 0x%4.4X must have a \"SubNumber\" attribute")%entry
   778         return Node
   778         return Node
   779     except SyntaxError, message:
   779     except SyntaxError, message:
   780         return "Unable to import EDS file\n%s"%message
   780         return _("Unable to import EDS file\n%s")%message
   781 
   781 
   782 #-------------------------------------------------------------------------------
   782 #-------------------------------------------------------------------------------
   783 #                             Main Function
   783 #                             Main Function
   784 #-------------------------------------------------------------------------------
   784 #-------------------------------------------------------------------------------
   785 
   785