etisserant@0: #!/usr/bin/env python etisserant@0: # -*- coding: utf-8 -*- etisserant@0: etisserant@0: #This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: # etisserant@0: #Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD etisserant@0: # etisserant@0: #See COPYING file for copyrights details. etisserant@0: # etisserant@0: #This library is free software; you can redistribute it and/or etisserant@0: #modify it under the terms of the GNU Lesser General Public etisserant@0: #License as published by the Free Software Foundation; either etisserant@0: #version 2.1 of the License, or (at your option) any later version. etisserant@0: # etisserant@0: #This library is distributed in the hope that it will be useful, etisserant@0: #but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: #Lesser General Public License for more details. etisserant@0: # etisserant@0: #You should have received a copy of the GNU Lesser General Public etisserant@0: #License along with this library; if not, write to the Free Software etisserant@0: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: etisserant@0: import getopt,sys,os etisserant@0: from types import * etisserant@0: etisserant@0: from nodemanager import * etisserant@0: laurent@580: _ = lambda x: x laurent@580: etisserant@0: def usage(): laurent@580: print _("\nUsage of objdictgen.py :") etisserant@0: print "\n %s XMLFilePath CFilePath\n"%sys.argv[0] etisserant@0: etisserant@0: try: etisserant@0: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) etisserant@0: except getopt.GetoptError: etisserant@0: # print help information and exit: etisserant@0: usage() etisserant@0: sys.exit(2) etisserant@0: etisserant@0: for o, a in opts: etisserant@0: if o in ("-h", "--help"): etisserant@0: usage() etisserant@0: sys.exit() etisserant@0: etisserant@0: fileIn = "" etisserant@0: fileOut = "" etisserant@0: if len(args) == 2: etisserant@0: fileIn = args[0] etisserant@0: fileOut = args[1] etisserant@0: else: etisserant@0: usage() etisserant@0: sys.exit() etisserant@0: etisserant@0: if __name__ == '__main__': etisserant@0: if fileIn != "" and fileOut != "": baf@283: manager = NodeManager() etisserant@0: if os.path.isfile(fileIn): laurent@580: print _("Parsing input file") etisserant@93: result = manager.OpenFileInCurrent(fileIn) lbessard@512: if not isinstance(result, (StringType, UnicodeType)): etisserant@0: Node = result etisserant@0: else: etisserant@0: print result etisserant@0: sys.exit(-1) etisserant@0: else: laurent@580: print _("%s is not a valid file!")%fileIn etisserant@0: sys.exit(-1) laurent@580: print _("Writing output file") greg@199: result = manager.ExportCurrentToCFile(fileOut) lbessard@512: if isinstance(result, (UnicodeType, StringType)): etisserant@0: print result etisserant@0: sys.exit(-1) laurent@580: print _("All done") etisserant@0: