def generateHeaders(self): # Verify settings rex = re.compile(".*\\.xml$", re.IGNORECASE) if not self.xml_value.get(): tkinter.messagebox.showerror('Error Generating Headers','An XML message definition file must be specified.') return if not self.out_value.get(): tkinter.messagebox.showerror('Error Generating Headers', 'An output directory must be specified.') return if os.path.isdir(self.out_value.get()): if not tkinter.messagebox.askokcancel('Overwrite Headers?','The output directory \'{0}\' already exists. Headers may be overwritten if they already exist.'.format(self.out_value.get())): return # Generate headers opts = mavgen.Opts(self.out_value.get(), wire_protocol=self.protocol_value.get(), language=self.language_value.get(), validate=self.validate_value.get(), error_limit=error_limit); args = [self.xml_value.get()] try: mavgen.mavgen(opts,args) tkinter.messagebox.showinfo('Successfully Generated Headers', 'Headers generated successfully.') except Exception as ex: exStr = formatErrorMessage(str(ex)); tkinter.messagebox.showerror('Error Generating Headers','{0!s}'.format(exStr)) return
def generateHeaders(self): # Verify settings rex = re.compile(".*\\.xml$", re.IGNORECASE) if not self.xml_value.get(): tkinter.messagebox.showerror( 'Error Generating Headers', 'An XML message definition file must be specified.') return if not self.out_value.get(): tkinter.messagebox.showerror( 'Error Generating Headers', 'An output directory must be specified.') return if os.path.isdir(self.out_value.get()): if not tkinter.messagebox.askokcancel( 'Overwrite Headers?', 'The output directory \'{0}\' already exists. Headers may be overwritten if they already exist.' .format(self.out_value.get())): return # Generate headers opts = mavgen.Opts(self.out_value.get(), wire_protocol=self.protocol_value.get(), language=self.language_value.get(), validate=self.validate_value.get(), error_limit=error_limit) args = [self.xml_value.get()] try: mavgen.mavgen(opts, args) tkinter.messagebox.showinfo('Successfully Generated Headers', 'Headers generated successfully.') except Exception as ex: exStr = formatErrorMessage(str(ex)) tkinter.messagebox.showerror('Error Generating Headers', '{0!s}'.format(exStr)) return
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) class options: """ a class to simulate the options of mavgen OptionsParser""" def __init__(self, lang, output, wire_protocol): self.language = lang self.wire_protocol = wire_protocol self.output = output protocols = [ '0.9', '1.0' ] for protocol in protocols : xml_directory = './message_definitions/v'+protocol print "xml_directory is", xml_directory xml_file_names = glob.glob(xml_directory+'/*.xml') for xml_file in xml_file_names: print "xml file is ", xml_file opts = options(lang = "C", output = "C/include_v"+protocol, \ wire_protocol=protocol) args = [] args.append(xml_file) mavgen(opts, args) xml_file_base = os.path.basename(xml_file) xml_file_base = re.sub("\.xml","", xml_file_base) print "xml_file_base is", xml_file_base opts = options(lang = "python", \ output="python/mavlink_"+xml_file_base+"_v"+protocol+".py", \ wire_protocol=protocol) mavgen(opts,args)