def __init__(self, fname="", prefs=None): """Initialiser for the genericNetlist class Keywords: fname -- The name of the generic netlist file to open (Optional) """ self.design = None self.components = [] self.libparts = [] self.libraries = [] self.nets = [] # The entire tree is loaded into self.tree self.tree = [] self._curr_element = None if not prefs: prefs = BomPref() #default values self.prefs = prefs if fname != "": self.load(fname)
def __init__(self, prefs=None): self.components = [] self.fields = dict.fromkeys(ColumnList._COLUMNS_DEFAULT) #columns loaded from KiCad if not prefs: prefs = BomPref() self.prefs = prefs
def WriteBoM(filename, groups, net, headings = columns.ColumnList._COLUMNS_DEFAULT, prefs=None): filename = os.path.abspath(filename) #no preferences supplied, use defaults if not prefs: prefs = BomPref() #remove any headings that appear in the ignore[] list headings = [h for h in headings if not h.lower() in [i.lower() for i in prefs.ignore]] #if no extension is given, assume .csv (and append!) if len(filename.split('.')) < 2: filename += ".csv" #make a temporary copy of the output file if prefs.backup != False: TmpFileCopy(filename, prefs.backup) ext = filename.split('.')[-1].lower() result = False #CSV file writing if ext in ["csv","tsv","txt"]: if WriteCSV(filename, groups, net, headings, prefs): print("CSV Output -> {fn}".format(fn=filename)) result = True else: print("Error writing CSV output") elif ext in ["htm","html"]: #check if prettyhtml is enabled or not if prefs.prettyhtml: if HTMLPretty(filename, groups, net, headings, prefs): print("HTML Output -> {fn}".format(fn=filename)) result = True else: print("Error writing HTML output") else: if WriteHTML(filename, groups, net, headings, prefs): print("HTML Output -> {fn}".format(fn=filename)) result = True else: print("Error writing HTML output") elif ext in ["xml"]: if WriteXML(filename, groups, net, headings, prefs): print("XML Output -> {fn}".format(fn=filename)) result = True else: print("Error writing XML output") else: print("Unsupported file extension: {ext}".format(ext=ext)) return result
def __init__(self, xml_element, prefs=None): self.element = xml_element self.libpart = None if not prefs: prefs = BomPref() self.prefs = prefs # Set to true when this component is included in a component group self.grouped = False
say("Input:", input_file) # Look for a config file! # bom.ini by default ini = os.path.abspath(os.path.join(os.path.dirname(input_file), "bom.ini")) # Default value config_file = ini # User can overwrite with a specific config file if args.cfg: config_file = os.path.abspath( os.path.join(os.path.dirname(input_file), args.cfg)) # Read preferences from file. If file does not exists, default preferences will be used pref = BomPref() have_cfile = os.path.exists(config_file) if have_cfile: pref.Read(config_file) say("Config:", config_file) # Pass available modules pref.xlsxwriter_available = xlsxwriter_available # Pass various command-line options through pref.verbose = verbose if args.number is not None: pref.boards = args.number pref.separatorCSV = args.separator
def WriteBoM(filename, groups, net, headings=columns.ColumnList._COLUMNS_DEFAULT, prefs=None): """ Write BoM to file filename = output file path groups = [list of ComponentGroup groups] headings = [list of headings to display in the BoM file] prefs = BomPref object """ filename = os.path.abspath(filename) # No preferences supplied, use defaults if not prefs: prefs = BomPref() # Remove any headings that appear in the ignore[] list headings = [ h for h in headings if not h.lower() in [i.lower() for i in prefs.ignore] ] # If no extension is given, assume .csv (and append!) if len(filename.split('.')) < 2: filename += ".csv" # Make a temporary copy of the output file if prefs.backup is not False: TmpFileCopy(filename, prefs.backup) ext = filename.split('.')[-1].lower() result = False # CSV file writing if ext in ["csv", "tsv", "txt"]: if WriteCSV(filename, groups, net, headings, prefs): print("CSV Output -> {fn}".format(fn=filename)) result = True else: print("Error writing CSV output") elif ext in ["htm", "html"]: if WriteHTML(filename, groups, net, headings, prefs): print("HTML Output -> {fn}".format(fn=filename)) result = True else: print("Error writing HTML output") elif ext in ["xml"]: if WriteXML(filename, groups, net, headings, prefs): print("XML Output -> {fn}".format(fn=filename)) result = True else: print("Error writing XML output") elif ext in ["xlsx"] and prefs.xlsxwriter_available: if WriteXLSX(filename, groups, net, headings, prefs): print("XLSX Output -> {fn}".format(fn=filename)) result = True else: print("Error writing XLSX output") else: print("Unsupported file extension: {ext}".format(ext=ext)) return result
def WriteBoM(filename, groups, net, headings=columns.ColumnList._COLUMNS_DEFAULT, prefs=None): filename = os.path.abspath(filename) #no preferences supplied, use defaults if not prefs: prefs = BomPref() #remove any headings that appear in the ignore[] list headings = [ h for h in headings if not h.lower() in [i.lower() for i in prefs.ignore] ] # Remove any columns that have no entries if prefs.removeEmptyColumns: entries = [] for group in groups: row = group.getRow(headings) for heading, field in zip(headings, row): if len(field) > 0 and heading not in entries: entries.append(heading) for field in copy.copy(headings): if field not in entries: headings.remove(field) #if no extension is given, assume .csv (and append!) if len(filename.split('.')) < 2: filename += ".csv" #make a temporary copy of the output file if prefs.backup != False: TmpFileCopy(filename, prefs.backup) ext = filename.split('.')[-1].lower() result = False #CSV file writing if ext in ["csv", "tsv", "txt"]: if WriteCSV(filename, groups, net, headings, prefs): print("CSV Output -> {fn}".format(fn=filename)) result = True else: print("Error writing CSV output") elif ext in ["htm", "html"]: if WriteHTML(filename, groups, net, headings, prefs): print("HTML Output -> {fn}".format(fn=filename)) result = True else: print("Error writing HTML output") elif ext in ["xml"]: if WriteXML(filename, groups, net, headings, prefs): print("XML Output -> {fn}".format(fn=filename)) result = True else: print("Error writing XML output") elif ext in ["xlsx"]: if WriteXLSX(filename, groups, net, headings, prefs): print("XLSX Output -> {fn}".format(fn=filename)) result = True else: print("Error writing XLSX output") else: print("Unsupported file extension: {ext}".format(ext=ext)) return result
input_file = os.path.abspath(input_file) say("Input:", input_file) #look for a config file! #bom.ini by default ini = os.path.abspath(os.path.join(os.path.dirname(input_file), "bom.ini")) config_file = ini #default value #user can overwrite with a specific config file if args.cfg: config_file = args.cfg #read preferences from file. If file does not exists, default preferences will be used pref = BomPref() have_cfile = os.path.exists(config_file) if have_cfile: pref.Read(config_file) say("Config:", config_file) #pass available modules pref.xlsxwriter_available = xlsxwriter_available #pass various command-line options through pref.verbose = verbose if args.number is not None: pref.boards = args.number pref.separatorCSV = args.separator
input_file = os.path.abspath(input_file) say("Input:",input_file) #look for a config file! #bom.ini by default ini = os.path.abspath(os.path.join(os.path.dirname(input_file), "bom.ini")) config_file = ini #default value #user can overwrite with a specific config file if args.cfg: config_file = args.cfg #read preferences from file. If file does not exists, default preferences will be used pref = BomPref() have_cfile = os.path.exists(config_file) if have_cfile: pref.Read(config_file) say("Config:",config_file) #pass various command-line options through pref.verbose = verbose if args.number is not None: pref.boards = args.number pref.separatorCSV = args.separator if args.variant is not None: pref.pcbConfig = args.variant print("PCB variant:", pref.pcbConfig)
input_file = os.path.abspath(input_file) say("Input:",input_file) #look for a config file! #bom.ini by default ini = os.path.abspath(os.path.join(os.path.dirname(input_file), "bom.ini")) config_file = ini #default value #user can overwrite with a specific config file if args.cfg: config_file = args.cfg #read preferences from file. If file does not exists, default preferences will be used pref = BomPref() have_cfile = os.path.exists(config_file) if have_cfile: pref.Read(config_file) say("Config:",config_file) #pass various command-line options through pref.verbose = verbose if args.number is not None: pref.boards = args.number pref.separatorCSV = args.separator if args.variant is not None: pref.pcbConfig = args.variant print("PCB variant:", pref.pcbConfig)