Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Set '.xml' as the default file extension, treating this exception
# allow other files extension and formats.
try:
if os.path.splitext(args.input[i])[1] == '':
args.input[i] += '.xml'
elif os.path.splitext(args.input[i])[1] == '.csv':
args.eda[i] = 'csv'
except IndexError:
pass
# Remove all the distributor from the list for not scrape any web site.
if args.no_price:
dist_list = None
else:
if not args.include:
dist_list = list(distributor_dict.keys())
else:
dist_list = args.include
for d in args.exclude:
dist_list.remove(d)
logger.log(DEBUG_OBSESSIVE, 'Started KiCost v.{} on {}({}) Python {}.{}.{}'.format(
__version__,
platform.platform(),
platform.architecture()[0],
sys.version_info.major,
sys.version_info.minor,
sys.version_info.micro)
)
#try:
kicost(in_file=args.input, eda_name=args.eda,
def set_properties(self):
''' @brief Set the current proprieties of the graphical elements.'''
# Current distributors module recognized.
distributors_list = sorted([ distributor_dict[d]['label']['name'] for d in distributor_dict.keys() if distributor_dict[d]['type']!='local'])
self.m_checkList_dist.Clear()
for d in distributors_list: # Make this for wxPy3 compatibility, not allow include a list.
self.m_checkList_dist.Append(d)
#self.m_checkList_dist.Append(distributors_list)
for idx in range(len(distributors_list)):
self.m_checkList_dist.Check(idx,True) # All start checked (after is modified by the configuration file).
# Current EDA tools module recognized.
eda_names = sorted([ eda_dict[eda]['label'] for eda in eda_dict.keys() ])
self.m_listBox_edatool.Clear()
for s in eda_names: # Make this for wxPy3 compatibility, not allow include a list.
self.m_listBox_edatool.Append(s)
#self.m_listBox_edatool.Append(eda_names)
# Get all the currencies present.
loc = locale.getdefaultlocale()[0]
def kicost(in_file, eda_name, out_filename,
user_fields, ignore_fields, group_fields, translate_fields,
variant,
dist_list=list(distributor_dict.keys()),
collapse_refs=True, supress_cat_url=True, currency=DEFAULT_CURRENCY):
''' @brief Run KiCost.
Take a schematic input file and create an output file with a cost spreadsheet in xlsx format.
@param in_file `list(str())` List of the names of the input BOM files.
@param eda_name `list(str())` of the EDA modules to be used to open the `in_file`list.
@param out_filename `str()` XLSX output file name.
@param user_fields `list()` of the user fields to be included on the spreadsheet global part.
@param ignore_fields `list()` of the fields to be ignored on the read EDA modules.
@param group_fields `list()` of the fields to be grouped/merged on the function group parts that
are not grouped by default.
@param translate_fields `list()` of the fields to translate to translate or remove (if `~` present).
@param variant `list(str())` of regular expression to the BOM variant of each file in `in_file`.
@param dist_list `list(str())` to be scraped, if empty will be scraped with all distributors
modules. If `None`, no web/local distributors will be scraped.
xl_rowcol_to_cell(row, start_col + columns['qty']['col']-1)
),
wrk_formats['part_format'])
else:
wks.write(row, start_col + columns['qty']['col'],
qty.format('BoardQty'), wrk_formats['part_format'])
except KeyError:
pass
# Gather the cell references for calculating minimum unit price and part availability.
dist_unit_prices = []
dist_qty_avail = []
dist_qty_purchased = []
dist_code_avail = []
dist_ext_prices = []
for dist in list(distributor_dict.keys()):
# Get the currencies used among all distributors.
used_currencies.append(part.currency[dist])
# Get the name of the data range for this distributor.
dist_data_rng = '{}_part_data'.format(dist)
# Get the contents of the unit price cell for this part (row) and distributor (column+offset).
dist_unit_prices.append(
'INDIRECT(ADDRESS(ROW(),COLUMN({})+2))'.format(dist_data_rng))
# Get the contents of the quantity purchased cell for this part and distributor
# unless the unit price is not a number in which case return 0.
dist_qty_purchased.append(
'IF(ISNUMBER(INDIRECT(ADDRESS(ROW(),COLUMN({0})+2))),INDIRECT(ADDRESS(ROW(),COLUMN({0})+1)),0)'.format(dist_data_rng))
if args.unsetup:
from .kicost_config import kicost_unsetup
kicost_unsetup()
return
# Set up logging.
if args.debug is not None:
log_level = logging.DEBUG + 1 - args.debug
elif args.quiet is True:
log_level = logging.ERROR
else:
log_level = logging.WARNING
logging.basicConfig(level=log_level, format='%(message)s')
if args.show_dist_list:
print('Distributor list:', *sorted(list(distributor_dict.keys())))
return
if args.show_eda_list:
#eda_names = [o[0] for o in inspect.getmembers(eda_tools_imports) if inspect.ismodule(o[1])]
#print('EDA supported list:', ', '.join(eda_names))
print('EDA supported list:', *sorted(list(eda_dict.keys())))
return
# Set up spreadsheet output file.
if args.output == None:
# If no output file is given...
if args.input != None:
# Send output to spreadsheet with name of input file.
# Compose a name with the multiple BOM input file names.
args.output = output_filename(args.input)
else:
# Send output to spreadsheet with name of this application.
unit_price_range=unit_price_range,
qty_range=xl_range(PART_INFO_FIRST_ROW, qty_col,
PART_INFO_LAST_ROW, qty_col)),
wrk_formats['total_cost_currency'])
# Add total of the spreadsheet, this can be equal or bigger than
# than the sum of the above totals, because, in the case of partial
# or fractional quantity of one part or subpart, the total quantity
# column 'qty' will be the ceil of the sum of the other ones.
total_cost_row = start_row -1 # Change the position of the total price cell.
wks.write(total_cost_row, total_cost_col, '=SUM({sum_range})'.format(
sum_range=xl_range(PART_INFO_FIRST_ROW, total_cost_col,
PART_INFO_LAST_ROW, total_cost_col)),
wrk_formats['total_cost_currency'])
# Add the total purchase and others purchase informations.
if distributor_dict.keys():
next_line = row + 1
wks.write(next_line, start_col + columns['unit_price']['col'],
'Total Purchase:', wrk_formats['total_cost_label'])
wks.write_comment(next_line, start_col + columns['unit_price']['col'],
'This is the total of your cart across all distributors.')
wks.write(next_line, start_col + columns['ext_price']['col'],
'=SUM({})'.format(','.join(dist_ext_prices)),
wrk_formats['total_cost_currency'])
# Purchase general description, it may be used to distinguish carts of different projects.
next_line = next_line + 1
wks.write(next_line, start_col + columns['unit_price']['col'],
'Purchase description:', wrk_formats['description'])
wks.write_comment(next_line, start_col + columns['unit_price']['col'],
'This description will be added to all purchased parts label and may be used to distinguish the component of different projects.')
WORKBOOK.define_name('PURCHASE_DESCRIPTION',
'={wks_name}!{cell_ref}'.format(