Пример #1
0
def writeVariant(variant, subdirectory):
    if variant is not None:
        pref.pcbConfig = variant.strip().split(',')

    print("PCB variant: ", ", ".join(pref.pcbConfig))

    # Write preference file back out (first run will generate a file with default preferences)
    if not have_cfile:
        pref.Write(config_file)
        say("Writing preferences file %s" % (config_file, ))

    # Individual components
    components = []

    # Component groups
    groups = []

    # Read out the netlist
    net = netlist(input_file, prefs=pref)

    # Extract the components
    components = net.getInterestingComponents()

    # Group the components
    groups = net.groupComponents(components)

    columns = ColumnList(pref.corder)

    # Read out all available fields
    for g in groups:
        for f in g.fields:
            columns.AddColumn(f)

    # Don't add 'boards' column if only one board is specified
    if pref.boards <= 1:
        columns.RemoveColumn(ColumnList.COL_GRP_BUILD_QUANTITY)
        say("Removing:", ColumnList.COL_GRP_BUILD_QUANTITY)

    # Finally, write the BoM out to file
    if write_to_bom:
        output_file = args.output

        if output_file is None:
            output_file = input_file.replace(".xml", ".csv")

        output_path, output_name = os.path.split(output_file)
        output_name, output_ext = os.path.splitext(output_name)

        # KiCad BOM dialog by default passes "%O" without an extension. Append our default
        if not isExtensionSupported(output_ext):
            output_ext = ".csv"

        # Make replacements to custom file_name.
        file_name = pref.outputFileName

        file_name = file_name.replace("%O", output_name)
        file_name = file_name.replace("%v", net.getVersion())
        if variant is not None:
            file_name = file_name.replace("%V", pref.variantFileNameFormat)
            file_name = file_name.replace("%V", variant)
        else:
            file_name = file_name.replace("%V", "")

        if args.subdirectory is not None:
            output_path = os.path.join(output_path, args.subdirectory)
            if not os.path.exists(os.path.abspath(output_path)):
                os.makedirs(os.path.abspath(output_path))

        output_file = os.path.join(output_path, file_name + output_ext)
        output_file = os.path.abspath(output_file)

        say("Output:", output_file)

        return WriteBoM(output_file, groups, net, columns.columns, pref)
Пример #2
0
#read out the netlist
net = netlist(input_file, prefs=pref)

#extract the components
components = net.getInterestingComponents()

#group the components
groups = net.groupComponents(components)

columns = ColumnList(pref.corder)

#read out all available fields
for g in groups:
    for f in g.fields:
        columns.AddColumn(f)

#don't add 'boards' column if only one board is specified
if pref.boards <= 1:
    columns.RemoveColumn(ColumnList.COL_GRP_BUILD_QUANTITY)
    say("Removing:", ColumnList.COL_GRP_BUILD_QUANTITY)

#todo
write_to_bom = True
result = True

#Finally, write the BoM out to file
if write_to_bom:

    output_file = args.output