def convert(infile, outfileName, **options): dbs = {} print("Importing " + infile + " ... ") if infile[-3:] == 'dbc': dbs[""] = im.importDbc(infile, **options) elif infile[-3:] == 'dbf': dbs[""] = im.importDbf(infile, **options) elif infile[-3:] == 'sym': dbs[""] = im.importSym(infile, **options) elif infile[-3:] == 'kcd': dbs[""] = im.importKcd(infile) elif infile[-3:] == 'xls': dbs[""] = im.importXls(infile, **options) elif infile[-4:] == 'xlsx' : dbs[""] = im.importXlsx(infile, **options) elif infile[-5:] == 'arxml': dbs = im.importArxml(infile, **options) elif infile[-4:] == 'yaml': dbs[""] = im.importYaml(infile) else: sys.stderr.write('\nFile not recognized: ' + infile + "\n") print("done\n") print("Exporting " + outfileName + " ... ") for name in dbs: db = dbs[name] print(name) print("%d Frames found" % (db._fl._list.__len__())) if len(name) > 0: path = os.path.split(outfileName) outfile = os.path.join(path[0], name + "_" + path[1]) else: outfile = outfileName if outfile[-3:] == 'dbc': ex.exportDbc(db, outfile, **options) elif outfile[-3:] == 'dbf': ex.exportDbf(db, outfile, **options) elif outfile[-3:] == 'sym': ex.exportSym(db, outfile, **options) elif outfile[-3:] == 'kcd': ex.exportKcd(db, outfile) elif outfile[-4:] == 'xlsx': ex.exportXlsx(db, outfile, **options) elif outfile[-3:] == 'xls': ex.exportXls(db, outfile, **options) elif outfile[-4:] == 'json': ex.exportJson(db, outfile) elif outfile[-5:] == 'arxml': ex.exportArxml(db, outfile) elif outfile[-4:] == 'yaml': ex.exportYaml(db, outfile) elif outfile[-3:] == 'csv': ex.exportCsv(db, outfile) else: sys.stderr.write('File not recognized: ' + outfileName + "\n") print("done")
def convert(infile, outfileName, **options): import canmatrix.exportall as ex import canmatrix.importall as im dbs = {} logger.info("Importing " + infile + " ... ") if infile[-3:] == 'dbc': dbs[""] = im.importDbc(infile, **options) elif infile[-3:] == 'dbf': dbs[""] = im.importDbf(infile, **options) elif infile[-3:] == 'sym': dbs[""] = im.importSym(infile, **options) elif infile[-3:] == 'kcd': dbs[""] = im.importKcd(infile) elif infile[-3:] == 'xls': dbs[""] = im.importXls(infile, **options) elif infile[-4:] == 'xlsx' : dbs[""] = im.importXlsx(infile, **options) elif infile[-5:] == 'arxml': dbs = im.importArxml(infile, **options) elif infile[-4:] == 'yaml': dbs[""] = im.importYaml(infile) else: logger.error('\nFile not recognized: ' + infile + "\n") logger.info("done\n") logger.info("Exporting " + outfileName + " ... ") for name in dbs: db = dbs[name] if 'deleteZeroSignals' in options and options['deleteZeroSignals']: db.deleteZeroSignals() if 'recalcDLC' in options and options['recalcDLC']: db.recalcDLC(options['recalcDLC']) logger.info(name) logger.info("%d Frames found" % (db._fl._list.__len__())) if len(name) > 0: path = os.path.split(outfileName) outfile = os.path.join(path[0], name + "_" + path[1]) else: outfile = outfileName # Get output file extension fileext = '' if 'force_output' in options and options['force_output']: # Provided by the command line fileext = options['force_output'] else: # Get extension from output filename fileext = os.path.splitext(outfile)[1] # Strip leading '.' from extension, of exists fileext = fileext[1:] if fileext.startswith('.') else fileext if fileext == 'dbc': ex.exportDbc(db, outfile, **options) elif fileext == 'dbf': ex.exportDbf(db, outfile, **options) elif fileext == 'sym': ex.exportSym(db, outfile, **options) elif fileext == 'kcd': ex.exportKcd(db, outfile) elif fileext == 'xlsx': ex.exportXlsx(db, outfile, **options) elif fileext == 'xls': ex.exportXls(db, outfile, **options) elif fileext == 'json': ex.exportJson(db, outfile) elif fileext == 'arxml': ex.exportArxml(db, outfile) elif fileext == 'yaml': ex.exportYaml(db, outfile) elif fileext == 'csv': ex.exportCsv(db, outfile) else: logger.error('File not recognized: ' + outfileName + "\n") logger.info("done")