def main(): from optparse import OptionParser usage = """ %prog [options] import-file export-file import-file: *.dbc|*.dbf|*.kcd|*.arxml|*.json|*.xls(x)|*.sym export-file: *.dbc|*.dbf|*.kcd|*.arxml|*.json|*.xls(x)|*.sym following formats are available at this installation: \n""" for suppFormat, features in canmatrix.formats.supportedFormats.items(): usage += suppFormat + "\t" if 'load' in features: usage += "import" usage += "\t" if 'dump' in features: usage += "export" usage += "\n" parser = OptionParser(usage=usage) # parser.add_option("-d", "--debug", # dest="debug", default=False, # help="print debug messages to stdout") parser.add_option("-v", dest="verbosity", action="count", help="Output verbosity", default=0) parser.add_option( "-s", dest="silent", action="store_true", help="don't print status messages to stdout. (only errors)", default=False) parser.add_option( "-f", dest="force_output", help= "enforce output format, ignoring output file extension (e.g., -f csv") parser.add_option( "", "--deleteZeroSignals", action="store_true", dest="deleteZeroSignals", default=False, help= "delete zero length signals (signals with 0 bit length) from matrix\ndefault False" ) parser.add_option( "", "--deleteSignalAttributes", dest="deleteSignalAttributes", default=None, help= "delete attributes from all signals\nExample --deleteSignalAttributes GenMsgCycle,CycleTime" ) parser.add_option( "", "--deleteFrameAttributes", dest="deleteFrameAttributes", default=None, help= "delete attributes from all frames\nExample --deleteFrameAttributes GenMsgCycle,CycleTime" ) parser.add_option( "", "--deleteObsoleteDefines", action="store_true", dest="deleteObsoleteDefines", default=False, help= "delete defines from all Boardunits, frames and Signals\nExample --deleteObsoleteDefines" ) parser.add_option( "", "--recalcDLC", dest="recalcDLC", default=False, help= "recalculate dlc; max: use maximum of stored and calculated dlc; force: force new calculated dlc" ) parser.add_option( "", "--arxmlIgnoreClusterInfo", action="store_true", dest="arxmlIgnoreClusterInfo", default=False, help= "Ignore any can cluster info from arxml; Import all frames in one matrix\ndefault 0" ) parser.add_option( "", "--arxmlExportVersion", dest="arVersion", default="3.2.3", help= "Set output AUTOSAR version\ncurrently only 3.2.3 and 4.1.0 are supported\ndefault 3.2.3" ) parser.add_option( "", "--dbcImportEncoding", dest="dbcImportEncoding", default="iso-8859-1", help= "Import charset of dbc (relevant for units), maybe utf-8\ndefault iso-8859-1" ) parser.add_option( "", "--dbcImportCommentEncoding", dest="dbcImportCommentEncoding", default="iso-8859-1", help="Import charset of Comments in dbc\ndefault iso-8859-1") parser.add_option( "", "--dbcExportEncoding", dest="dbcExportEncoding", default="iso-8859-1", help= "Export charset of dbc (relevant for units), maybe utf-8\ndefault iso-8859-1" ) parser.add_option( "", "--dbcExportCommentEncoding", dest="dbcExportCommentEncoding", default="iso-8859-1", help="Export charset of comments in dbc\ndefault iso-8859-1") parser.add_option( "", "--dbfImportEncoding", dest="dbfImportEncoding", default="iso-8859-1", help="Import charset of dbf, maybe utf-8\ndefault iso-8859-1") parser.add_option( "", "--dbfExportEncoding", dest="dbfExportEncoding", default="iso-8859-1", help="Export charset of dbf, maybe utf-8\ndefault iso-8859-1") parser.add_option( "", "--symImportEncoding", dest="symImportEncoding", default="iso-8859-1", help="Import charset of sym format, maybe utf-8\ndefault iso-8859-1") parser.add_option( "", "--symExportEncoding", dest="symExportEncoding", default="iso-8859-1", help="Export charset of sym format, maybe utf-8\ndefault iso-8859-1") parser.add_option( "", "--xlsMotorolaBitFormat", dest="xlsMotorolaBitFormat", default="msbreverse", help= "Excel format for startbit of motorola codescharset signals\nValid values: msb, lsb, msbreverse\n default msbreverse" ) parser.add_option("", "--jsonExportCanard", dest="jsonCanard", action="store_true", default=False, help="Export Canard compatible json format") parser.add_option("", "--jsonExportAll", dest="jsonAll", action="store_true", default=False, help="Export more data to json format") parser.add_option( "", "--ecus", dest="ecus", default=None, help="Copy only given ECUs (comma separated list) to target matrix") parser.add_option( "", "--frames", dest="frames", default=None, help="Copy only given Frames (comma separated list) to target matrix") parser.add_option( "", "--merge", dest="merge", default=None, help= "merge additional can databases.\nSyntax: --merge filename[:ecu=SOMEECU][:frame=FRAME1][:frame=FRAME2],filename2" ) parser.add_option( "", "--deleteEcu", dest="deleteEcu", default=None, help= "delete Ecu form databases. (comma separated list)\nSyntax: --deleteEcu=myEcu,mySecondEcu" ) parser.add_option( "", "--renameEcu", dest="renameEcu", default=None, help= "rename Ecu form databases. (comma separated list)\nSyntax: --renameEcu=myOldEcu:myNewEcu,mySecondEcu:mySecondNewEcu" ) parser.add_option( "", "--deleteFrame", dest="deleteFrame", default=None, help= "delete Frame form databases. (comma separated list)\nSyntax: --deleteFrame=myFrame1,mySecondFrame" ) parser.add_option( "", "--renameFrame", dest="renameFrame", default=None, help= "rename Frame form databases. (comma separated list)\nSyntax: --renameFrame=myOldFrame:myNewFrame,mySecondFrame:mySecondNewFrame" ) parser.add_option( "", "--deleteSignal", dest="deleteSignal", default=None, help= "delete Signal form databases. (comma separated list)\nSyntax: --deleteSignal=mySignal1,mySecondSignal" ) parser.add_option( "", "--renameSignal", dest="renameSignal", default=None, help= "rename Signal form databases. (comma separated list)\nSyntax: --renameSignal=myOldSignal:myNewSignal,mySecondSignal:mySecondNewSignal" ) (cmdlineOptions, args) = parser.parse_args() if len(args) < 2: parser.print_help() sys.exit(1) infile = args[0] outfileName = args[1] verbosity = cmdlineOptions.verbosity if cmdlineOptions.silent: # only print error messages, ignore verbosity flag verbosity = -1 set_log_level(logger, verbosity) convert(infile, outfileName, **cmdlineOptions.__dict__)
import sys sys.path.append('..') import canmatrix.convert import canmatrix.formats import copy import os import re import shutil import subprocess from canmatrix.log import setup_logger, set_log_level logger = setup_logger('root') set_log_level(logger, -1) export_types = [] import_types = [] for canFormat, features in canmatrix.formats.supportedFormats.items(): if "dump" in features: export_types.append(canmatrix.formats.extensionMapping[canFormat]) if "load" in features: import_types.append(canmatrix.formats.extensionMapping[canFormat]) # for f in os.listdir('../canmatrix'): # m = re.match('^export(.*).py$', f) # if m is not None and m.group(1) != 'all': # export_types.append(m.group(1)) # m = re.match('^import(.*).py$', f)
import canmatrix.convert import canmatrix.formats import copy import os import re import shutil import subprocess if sys.version_info > (3, 2): if shutil.which("diff") is None: print ("ERROR: this test needs the tool 'diff' in your path to work") sys.exit() from canmatrix.log import setup_logger, set_log_level logger = setup_logger() set_log_level(logger, -1) export_types = [] import_types = [] for canFormat, features in canmatrix.formats.supportedFormats.items(): if "dump" in features: export_types.append(canmatrix.formats.extensionMapping[canFormat]) if "load" in features: import_types.append(canmatrix.formats.extensionMapping[canFormat]) # for f in os.listdir('../canmatrix'): # m = re.match('^export(.*).py$', f) # if m is not None and m.group(1) != 'all': # export_types.append(m.group(1)) # m = re.match('^import(.*).py$', f)