diff --git a/kicost/__main__.py b/kicost/__main__.py
index ea06262d7..2da22c71a 100644
--- a/kicost/__main__.py
+++ b/kicost/__main__.py
@@ -39,7 +39,7 @@
except ImportError:
pass # If the wxPython dependences are not installed and
# the user just want the KiCost CLI.
-from .distributors import distributor_dict
+from .distributors.global_vars import distributor_dict
from .eda_tools import eda_tool_dict
from . import __version__ # Version control by @xesscorp.
@@ -48,6 +48,18 @@
from .globals import *
+###############################################################################
+# Additional functions
+###############################################################################
+
+def kicost_gui_notdependences():
+ print('You don\'t have the wxPython dependence to run the GUI interface. Run once of the follow commands in terminal to install them:')
+ print('pip3 install -U wxPython # For Windows & macOS')
+
+ print('pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 wxPython # For Linux 16.04')
+ print('Or download from last version from ')
+ sys.exit(1)
+
###############################################################################
# Command-line interface.
###############################################################################
@@ -284,15 +296,3 @@ def main():
logger = logging.getLogger('kicost')
logger.log(logging.DEBUG-2, 'Elapsed time: %f seconds', time.time() - start_time)
-
-###############################################################################
-# Additional functions
-###############################################################################
-
-def kicost_gui_notdependences():
- print('You don\'t have the wxPython dependence to run the GUI interface. Run once of the follow commands in terminal to install them:')
- print('pip3 install -U wxPython # For Windows & macOS')
-
- print('pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 wxPython # For Linux 16.04')
- print('Or download from last version from ')
- sys.exit(1)
diff --git a/kicost/distributors/__init__.py b/kicost/distributors/__init__.py
index 666d7388e..4af5634ea 100644
--- a/kicost/distributors/__init__.py
+++ b/kicost/distributors/__init__.py
@@ -24,28 +24,36 @@
__author__ = 'XESS Corporation'
__email__ = 'info@xess.com'
-# Extra informations to by got by each part in the distributors.
-EXTRA_INFO_DIST = ['value', 'tolerance', 'footprint', 'power', 'current', 'voltage', 'frequency', 'temp_coeff', 'manf',
- 'size', 'op temp', 'orientation', 'color',
- 'datasheet', 'image', # Links.
- ]
-extra_info_dist_name_translations = {
- #TODO it will need to put here language translation after implementation of ISSUE #65?
- 'resistance': 'value',
- 'inductance': 'value',
- 'capacitance': 'value',
- 'manufacturer': 'manf',
- 'package': 'footprint',
- 'package / case': 'footprint',
- 'datasheets': 'datasheet',
- 'dimension': 'size',
- 'size / dimension': 'size',
- 'operating temperature': 'op temp',
- 'voltage - rated': 'voltage',
- 'Mating Orientation': 'orientation',
- 'coulor': 'color',
- 'wire gauge': 'wire',
-}
-
-# The global dictionary of distributor information starts out empty.
-distributor_dict = {}
+import os
+
+# The distributor module directories will be found in this directory.
+directory = os.path.dirname(__file__)
+
+# Search for the distributor modules and import them.
+for module in os.listdir(directory):
+
+ # Avoid importing non-directories.
+ abs_module = os.path.join(directory, module)
+ if not os.path.isdir(abs_module):
+ continue
+
+ # Avoid directories like __pycache__.
+ if module.startswith('__'):
+ continue
+
+ # Import the module.
+ tmp = __import__(module, globals(), locals(), [], level=1)
+ tmp_mod = getattr(tmp, module);
+ globals()["dist_"+module] = getattr(tmp_mod, "dist_"+module)
+
+from .global_vars import distributor_dict
+
+def init_distributor_dict():
+ # Clear distributor_dict, then let all distributor modules recreate their entries.
+ distributor_dict = {}
+ for x in globals():
+ if x.startswith("dist_"):
+ globals()[x].dist_init_distributor_dict()
+
+# Init distirbutor dict during import.
+init_distributor_dict()
diff --git a/kicost/distributors/digikey/__init__.py b/kicost/distributors/digikey/__init__.py
index e4a681d5f..c919c625a 100644
--- a/kicost/distributors/digikey/__init__.py
+++ b/kicost/distributors/digikey/__init__.py
@@ -5,31 +5,3 @@
from .digikey import *
-# Place information about this distributor into the distributor dictionary.
-from .. import distributor_dict
-distributor_dict.update(
- {
- 'digikey': {
- 'module': 'digikey', # The directory name containing this file.
- 'scrape': 'web', # Allowable values: 'web' or 'local'.
- 'label': 'Digi-Key', # Distributor label used in spreadsheet columns.
- 'order_cols': ['purch', 'part_num', 'refs'], # Sort-order for online orders.
- 'order_delimiter': ',', # Delimiter for online orders.
- # Formatting for distributor header in worksheet.
- 'wrk_hdr_format': {
- 'font_size': 14,
- 'font_color': 'white',
- 'bold': True,
- 'align': 'center',
- 'valign': 'vcenter',
- 'bg_color': '#CC0000' # Digi-Key red.
- },
- # Web site defitions.
- 'site': {
- 'url': 'https://www.digikey.com',
- 'currency': 'USD',
- 'locale': 'US'
- },
- }
- }
-)
diff --git a/kicost/distributors/digikey/digikey.py b/kicost/distributors/digikey/digikey.py
index 5863e8b7d..c45815808 100644
--- a/kicost/distributors/digikey/digikey.py
+++ b/kicost/distributors/digikey/digikey.py
@@ -30,12 +30,12 @@
import re, difflib
from bs4 import BeautifulSoup
import http.client # For web scraping exceptions.
-from .. import fake_browser
-from .. import EXTRA_INFO_DIST, extra_info_dist_name_translations
from ...globals import PartHtmlError
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE, DEBUG_HTTP_RESPONSES
-from .. import distributor, distributor_dict
+from .. import fake_browser
+from .. import distributor
+from ..global_vars import distributor_dict, EXTRA_INFO_DIST, extra_info_dist_name_translations
from urllib.parse import quote_plus as urlquote
@@ -46,6 +46,34 @@ def __init__(self, name, scrape_retries, throttle_delay):
super(dist_digikey, self).__init__(name, distributor_dict[name]['site']['url'],
scrape_retries, throttle_delay)
+ @staticmethod
+ def dist_init_distributor_dict():
+ distributor_dict.update(
+ {
+ 'digikey': {
+ 'module': 'digikey', # The directory name containing this file.
+ 'scrape': 'web', # Allowable values: 'web' or 'local'.
+ 'label': 'Digi-Key', # Distributor label used in spreadsheet columns.
+ 'order_cols': ['purch', 'part_num', 'refs'], # Sort-order for online orders.
+ 'order_delimiter': ',', # Delimiter for online orders.
+ # Formatting for distributor header in worksheet.
+ 'wrk_hdr_format': {
+ 'font_size': 14,
+ 'font_color': 'white',
+ 'bold': True,
+ 'align': 'center',
+ 'valign': 'vcenter',
+ 'bg_color': '#CC0000' # Digi-Key red.
+ },
+ # Web site defitions.
+ 'site': {
+ 'url': 'https://www.digikey.com',
+ 'currency': 'USD',
+ 'locale': 'US'
+ },
+ }
+ })
+
def dist_get_price_tiers(self, html_tree):
'''@brief Get the pricing tiers from the parsed tree of the Digikey product page.
@param html_tree `str()` html of the distributor part page.
diff --git a/kicost/distributors/distributor.py b/kicost/distributors/distributor.py
index e1c4f8526..931d9b06f 100644
--- a/kicost/distributors/distributor.py
+++ b/kicost/distributors/distributor.py
@@ -31,16 +31,17 @@
import logging
import time
from random import choice
-from ..eda_tools.eda_tools import order_refs # To better print the warnings about the parts.
+from .global_vars import distributor_dict
from . import fake_browser
+from ..eda_tools.eda_tools import order_refs # To better print the warnings about the parts.
+
import http.client # For web scraping exceptions.
from ..globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE # Debug configurations.
from ..globals import SEPRTR
from ..globals import PartHtmlError
-from . import distributor_dict
import os, re
@@ -58,6 +59,10 @@ def __init__(self, name, domain, scrape_retries, throttle_delay):
(self.domain, self.logger, self.scrape_retries, throttle_delay)
# Abstract methods, implemented in distributor specific modules
+ @staticmethod
+ def dist_init_distributor_dict():
+ raise NotImplementedError()
+
def dist_get_part_html_tree(self, pn, extra_search_terms, url, descend):
raise NotImplementedError()
diff --git a/kicost/distributors/farnell/__init__.py b/kicost/distributors/farnell/__init__.py
index c0203fa64..e0036133f 100644
--- a/kicost/distributors/farnell/__init__.py
+++ b/kicost/distributors/farnell/__init__.py
@@ -4,31 +4,3 @@
from .farnell import *
-# Place information about this distributor into the distributor dictionary.
-from .. import distributor_dict
-distributor_dict.update(
- {
- 'farnell': {
- 'module': 'farnell', # The directory name containing this file.
- 'scrape': 'web', # Allowable values: 'web' or 'local'.
- 'label': 'Farnell', # Distributor label used in spreadsheet columns.
- 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
- 'order_delimiter': ' ', # Delimiter for online orders.
- # Formatting for distributor header in worksheet.
- 'wrk_hdr_format': {
- 'font_size': 14,
- 'font_color': 'white',
- 'bold': True,
- 'align': 'center',
- 'valign': 'vcenter',
- 'bg_color': '#FF6600' # Farnell/E14 orange.
- },
- # Web site defitions.
- 'site': {
- 'url': 'https://it.farnell.com/',
- 'currency': 'USD',
- 'locale': 'US'
- },
- }
- }
-)
diff --git a/kicost/distributors/farnell/farnell.py b/kicost/distributors/farnell/farnell.py
index 7509d8186..0929252f7 100644
--- a/kicost/distributors/farnell/farnell.py
+++ b/kicost/distributors/farnell/farnell.py
@@ -30,12 +30,13 @@
import re, difflib
from bs4 import BeautifulSoup
import http.client # For web scraping exceptions.
-from .. import fake_browser
from ...globals import PartHtmlError
from ...globals import currency
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE, DEBUG_HTTP_RESPONSES
-from .. import distributor, distributor_dict
+from .. import fake_browser
+from .. import distributor
+from ..global_vars import distributor_dict
from urllib.parse import quote_plus as urlquote
@@ -46,6 +47,34 @@ def __init__(self, name, scrape_retries, throttle_delay):
super(dist_farnell, self).__init__(name, distributor_dict[name]['site']['url'],
scrape_retries, throttle_delay)
+ @staticmethod
+ def dist_init_distributor_dict():
+ distributor_dict.update(
+ {
+ 'farnell': {
+ 'module': 'farnell', # The directory name containing this file.
+ 'scrape': 'web', # Allowable values: 'web' or 'local'.
+ 'label': 'Farnell', # Distributor label used in spreadsheet columns.
+ 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
+ 'order_delimiter': ' ', # Delimiter for online orders.
+ # Formatting for distributor header in worksheet.
+ 'wrk_hdr_format': {
+ 'font_size': 14,
+ 'font_color': 'white',
+ 'bold': True,
+ 'align': 'center',
+ 'valign': 'vcenter',
+ 'bg_color': '#FF6600' # Farnell/E14 orange.
+ },
+ # Web site defitions.
+ 'site': {
+ 'url': 'https://it.farnell.com/',
+ 'currency': 'USD',
+ 'locale': 'US'
+ },
+ }
+ })
+
def dist_get_price_tiers(self, html_tree):
'''@brief Get the pricing tiers from the parsed tree of the farnell product page.
@param html_tree `str()` html of the distributor part page.
diff --git a/kicost/distributors/global_vars.py b/kicost/distributors/global_vars.py
new file mode 100644
index 000000000..e18412d5f
--- /dev/null
+++ b/kicost/distributors/global_vars.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+# MIT license
+#
+# Copyright (C) 2018 by XESS Corporation / Hildo Guillardi Junior
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+# The global dictionary of distributor information starts out empty.
+distributor_dict = {}
+
+# Extra informations to by got by each part in the distributors.
+EXTRA_INFO_DIST = ['value', 'tolerance', 'footprint', 'power', 'current', 'voltage', 'frequency', 'temp_coeff', 'manf',
+ 'size', 'op temp', 'orientation', 'color',
+ 'datasheet', 'image', # Links.
+ ]
+extra_info_dist_name_translations = {
+ #TODO it will need to put here language translation after implementation of ISSUE #65?
+ 'resistance': 'value',
+ 'inductance': 'value',
+ 'capacitance': 'value',
+ 'manufacturer': 'manf',
+ 'package': 'footprint',
+ 'package / case': 'footprint',
+ 'datasheets': 'datasheet',
+ 'dimension': 'size',
+ 'size / dimension': 'size',
+ 'operating temperature': 'op temp',
+ 'voltage - rated': 'voltage',
+ 'Mating Orientation': 'orientation',
+ 'coulor': 'color',
+ 'wire gauge': 'wire',
+}
diff --git a/kicost/distributors/local/__init__.py b/kicost/distributors/local/__init__.py
index e7181385b..4facc7a7b 100644
--- a/kicost/distributors/local/__init__.py
+++ b/kicost/distributors/local/__init__.py
@@ -5,25 +5,3 @@
from .local import *
-# Place information about this distributor into the distributor dictionary.
-from .. import distributor_dict
-distributor_dict.update(
- {
- 'local_template': {
- 'module': 'local', # The directory name containing this file.
- 'scrape': 'local', # Allowable values: 'web' or 'local'.
- 'label': 'Local', # Distributor label used in spreadsheet columns.
- 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
- 'order_delimiter': ' ', # Delimiter for online orders.
- # Formatting for distributor header in worksheet.
- 'wrk_hdr_format': {
- 'font_size': 14,
- 'font_color': 'white',
- 'bold': True,
- 'align': 'center',
- 'valign': 'vcenter',
- 'bg_color': '#008000' # Darker green.
- },
- }
- }
-)
diff --git a/kicost/distributors/local/local.py b/kicost/distributors/local/local.py
index 4bc35e640..b3788ffa5 100644
--- a/kicost/distributors/local/local.py
+++ b/kicost/distributors/local/local.py
@@ -36,6 +36,7 @@
from ...globals import SEPRTR as SEPRTR
from .. import distributor
+from ..global_vars import distributor_dict
from urllib.parse import urlsplit, urlunsplit
@@ -46,6 +47,28 @@ class dist_local(distributor.distributor):
def __init__(self, name, scrape_retries, throttle_delay):
super(dist_local, self).__init__(name, None, scrape_retries, throttle_delay)
+ @staticmethod
+ def dist_init_distributor_dict():
+ distributor_dict.update(
+ {
+ 'local_template': {
+ 'module': 'local', # The directory name containing this file.
+ 'scrape': 'local', # Allowable values: 'web' or 'local'.
+ 'label': 'Local', # Distributor label used in spreadsheet columns.
+ 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
+ 'order_delimiter': ' ', # Delimiter for online orders.
+ # Formatting for distributor header in worksheet.
+ 'wrk_hdr_format': {
+ 'font_size': 14,
+ 'font_color': 'white',
+ 'bold': True,
+ 'align': 'center',
+ 'valign': 'vcenter',
+ 'bg_color': '#008000' # Darker green.
+ },
+ }
+ })
+
@staticmethod
def create_part_html(parts, distributors, logger):
'''@brief Create HTML page containing info for local (non-webscraped) parts.
diff --git a/kicost/distributors/mouser/__init__.py b/kicost/distributors/mouser/__init__.py
index 97fcd1562..8d294555f 100644
--- a/kicost/distributors/mouser/__init__.py
+++ b/kicost/distributors/mouser/__init__.py
@@ -5,31 +5,3 @@
from .mouser import *
-# Place information about this distributor into the distributor dictionary.
-from .. import distributor_dict
-distributor_dict.update(
- {
- 'mouser': {
- 'module': 'mouser', # The directory name containing this file.
- 'scrape': 'web', # Allowable values: 'web' or 'local'.
- 'label': 'Mouser', # Distributor label used in spreadsheet columns.
- 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
- 'order_delimiter': ' ', # Delimiter for online orders.
- # Formatting for distributor header in worksheet.
- 'wrk_hdr_format': {
- 'font_size': 14,
- 'font_color': 'white',
- 'bold': True,
- 'align': 'center',
- 'valign': 'vcenter',
- 'bg_color': '#004A85' # Mouser blue.
- },
- # Web site defitions.
- 'site': {
- 'url': 'https://www.mouser.com/',
- 'currency': 'USD',
- 'locale': 'US'
- },
- }
- }
-)
diff --git a/kicost/distributors/mouser/mouser.py b/kicost/distributors/mouser/mouser.py
index e299147cb..d2dd26749 100644
--- a/kicost/distributors/mouser/mouser.py
+++ b/kicost/distributors/mouser/mouser.py
@@ -30,11 +30,12 @@
import re, difflib
from bs4 import BeautifulSoup
import http.client # For web scraping exceptions.
-from .. import fake_browser
from ...globals import PartHtmlError
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE, DEBUG_HTTP_RESPONSES
-from .. import distributor, distributor_dict
+from .. import fake_browser
+from .. import distributor
+from ..global_vars import distributor_dict
from urllib.parse import quote_plus as urlquote
@@ -44,6 +45,34 @@ def __init__(self, name, scrape_retries, throttle_delay):
scrape_retries, throttle_delay)
self.browser.add_cookie('.mouser.com', 'preferences', 'ps=www2&pl=en-US&pc_www2=USDe')
+ @staticmethod
+ def dist_init_distributor_dict():
+ distributor_dict.update(
+ {
+ 'mouser': {
+ 'module': 'mouser', # The directory name containing this file.
+ 'scrape': 'web', # Allowable values: 'web' or 'local'.
+ 'label': 'Mouser', # Distributor label used in spreadsheet columns.
+ 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
+ 'order_delimiter': ' ', # Delimiter for online orders.
+ # Formatting for distributor header in worksheet.
+ 'wrk_hdr_format': {
+ 'font_size': 14,
+ 'font_color': 'white',
+ 'bold': True,
+ 'align': 'center',
+ 'valign': 'vcenter',
+ 'bg_color': '#004A85' # Mouser blue.
+ },
+ # Web site defitions.
+ 'site': {
+ 'url': 'https://www.mouser.com/',
+ 'currency': 'USD',
+ 'locale': 'US'
+ },
+ }
+ })
+
def dist_get_price_tiers(self, html_tree):
'''@brief Get the pricing tiers from the parsed tree of the Mouser product page.
@param html_tree `str()` html of the distributor part page.
diff --git a/kicost/distributors/newark/__init__.py b/kicost/distributors/newark/__init__.py
index ec6b05197..79ad7f873 100644
--- a/kicost/distributors/newark/__init__.py
+++ b/kicost/distributors/newark/__init__.py
@@ -5,31 +5,3 @@
from .newark import *
-# Place information about this distributor into the distributor dictionary.
-from .. import distributor_dict
-distributor_dict.update(
- {
- 'newark': {
- 'module': 'newark', # The directory name containing this file.
- 'scrape': 'web', # Allowable values: 'web' or 'local'.
- 'label': 'Newark', # Distributor label used in spreadsheet columns.
- 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
- 'order_delimiter': ',', # Delimiter for online orders.
- # Formatting for distributor header in worksheet.
- 'wrk_hdr_format': {
- 'font_size': 14,
- 'font_color': 'white',
- 'bold': True,
- 'align': 'center',
- 'valign': 'vcenter',
- 'bg_color': '#A2AE06' # Newark/E14 olive green.
- },
- # Web site defitions.
- 'site': {
- 'url': 'https://www.newark.com/',
- 'currency': 'USD',
- 'locale': 'US'
- },
- }
- }
-)
diff --git a/kicost/distributors/newark/newark.py b/kicost/distributors/newark/newark.py
index 1e3a2176d..459ac992b 100644
--- a/kicost/distributors/newark/newark.py
+++ b/kicost/distributors/newark/newark.py
@@ -30,11 +30,12 @@
import re, difflib
from bs4 import BeautifulSoup
import http.client # For web scraping exceptions.
-from .. import fake_browser
from ...globals import PartHtmlError
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE, DEBUG_HTTP_RESPONSES
-from .. import distributor, distributor_dict
+from .. import fake_browser
+from .. import distributor
+from ..global_vars import distributor_dict
from urllib.parse import quote_plus as urlquote
@@ -43,6 +44,34 @@ def __init__(self, name, scrape_retries, throttle_delay):
super(dist_newark, self).__init__(name, distributor_dict[name]['site']['url'],
scrape_retries, throttle_delay)
+ @staticmethod
+ def dist_init_distributor_dict():
+ distributor_dict.update(
+ {
+ 'newark': {
+ 'module': 'newark', # The directory name containing this file.
+ 'scrape': 'web', # Allowable values: 'web' or 'local'.
+ 'label': 'Newark', # Distributor label used in spreadsheet columns.
+ 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
+ 'order_delimiter': ',', # Delimiter for online orders.
+ # Formatting for distributor header in worksheet.
+ 'wrk_hdr_format': {
+ 'font_size': 14,
+ 'font_color': 'white',
+ 'bold': True,
+ 'align': 'center',
+ 'valign': 'vcenter',
+ 'bg_color': '#A2AE06' # Newark/E14 olive green.
+ },
+ # Web site defitions.
+ 'site': {
+ 'url': 'https://www.newark.com/',
+ 'currency': 'USD',
+ 'locale': 'US'
+ },
+ }
+ })
+
def dist_get_price_tiers(self, html_tree):
'''@brief Get the pricing tiers from the parsed tree of the Newark product page.
@param html_tree `str()` html of the distributor part page.
diff --git a/kicost/distributors/rs/__init__.py b/kicost/distributors/rs/__init__.py
index 0b4b173d7..10dbaa9a0 100644
--- a/kicost/distributors/rs/__init__.py
+++ b/kicost/distributors/rs/__init__.py
@@ -4,31 +4,3 @@
from .rs import *
-# Place information about this distributor into the distributor dictionary.
-from .. import distributor_dict
-distributor_dict.update(
- {
- 'rs': {
- 'module': 'rs', # The directory name containing this file.
- 'scrape': 'web', # Allowable values: 'web' or 'local'.
- 'label': 'RS Components', # Distributor label used in spreadsheet columns.
- 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
- 'order_delimiter': ' ', # Delimiter for online orders.
- # Formatting for distributor header in worksheet.
- 'wrk_hdr_format': {
- 'font_size': 14,
- 'font_color': 'white',
- 'bold': True,
- 'align': 'center',
- 'valign': 'vcenter',
- 'bg_color': '#FF0000' # RS Components red.
- },
- # Web site defitions.
- 'site': {
- 'url': 'https://it.rs-online.com/',
- 'currency': 'USD',
- 'locale': 'UK'
- },
- }
- }
-)
diff --git a/kicost/distributors/rs/rs.py b/kicost/distributors/rs/rs.py
index e04e04c2a..56c733069 100644
--- a/kicost/distributors/rs/rs.py
+++ b/kicost/distributors/rs/rs.py
@@ -31,12 +31,13 @@
import re, difflib
from bs4 import BeautifulSoup
import http.client # For web scraping exceptions.
-from .. import fake_browser
from ...globals import PartHtmlError
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE, DEBUG_HTTP_RESPONSES
from ...globals import currency
-from .. import distributor, distributor_dict
+from .. import fake_browser
+from .. import distributor
+from ..global_vars import distributor_dict
from urllib.parse import quote_plus as urlquote
@@ -45,6 +46,34 @@ def __init__(self, name, scrape_retries, throttle_delay):
super(dist_rs, self).__init__(name, distributor_dict[name]['site']['url'],
scrape_retries, throttle_delay)
+ @staticmethod
+ def dist_init_distributor_dict():
+ distributor_dict.update(
+ {
+ 'rs': {
+ 'module': 'rs', # The directory name containing this file.
+ 'scrape': 'web', # Allowable values: 'web' or 'local'.
+ 'label': 'RS Components', # Distributor label used in spreadsheet columns.
+ 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
+ 'order_delimiter': ' ', # Delimiter for online orders.
+ # Formatting for distributor header in worksheet.
+ 'wrk_hdr_format': {
+ 'font_size': 14,
+ 'font_color': 'white',
+ 'bold': True,
+ 'align': 'center',
+ 'valign': 'vcenter',
+ 'bg_color': '#FF0000' # RS Components red.
+ },
+ # Web site defitions.
+ 'site': {
+ 'url': 'https://it.rs-online.com/',
+ 'currency': 'USD',
+ 'locale': 'UK'
+ },
+ }
+ })
+
def dist_get_price_tiers(self, html_tree):
'''@brief Get the pricing tiers from the parsed tree of the RS Components product page.
@param html_tree `str()` html of the distributor part page.
diff --git a/kicost/distributors/tme/__init__.py b/kicost/distributors/tme/__init__.py
index 5ecfdfb47..7fca743b6 100644
--- a/kicost/distributors/tme/__init__.py
+++ b/kicost/distributors/tme/__init__.py
@@ -5,31 +5,3 @@
from .tme import *
-# Place information about this distributor into the distributor dictionary.
-from .. import distributor_dict
-distributor_dict.update(
- {
- 'tme': {
- 'module': 'tme', # The directory name containing this file.
- 'scrape': 'web', # Allowable values: 'web' or 'local'.
- 'label': 'TME', # Distributor label used in spreadsheet columns.
- 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
- 'order_delimiter': ' ', # Delimiter for online orders.
- # Formatting for distributor header in worksheet.
- 'wrk_hdr_format': {
- 'font_size': 14,
- 'font_color': 'white',
- 'bold': True,
- 'align': 'center',
- 'valign': 'vcenter',
- 'bg_color': '#0C4DA1' # TME blue
- },
- # Web site defitions.
- 'site': {
- 'url': 'https://www.tme.eu/en/',
- 'currency': 'USD',
- 'locale': 'UK'
- },
- }
- }
-)
diff --git a/kicost/distributors/tme/tme.py b/kicost/distributors/tme/tme.py
index 031c643cd..bea7a13eb 100644
--- a/kicost/distributors/tme/tme.py
+++ b/kicost/distributors/tme/tme.py
@@ -35,7 +35,8 @@
from ...globals import PartHtmlError
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE, DEBUG_HTTP_RESPONSES
-from .. import distributor, distributor_dict
+from .. import distributor
+from ..global_vars import distributor_dict
from urllib.parse import quote_plus as urlquote
@@ -44,6 +45,34 @@ def __init__(self, name, scrape_retries, throttle_delay):
super(dist_tme, self).__init__(name, distributor_dict[name]['site']['url'],
scrape_retries, throttle_delay)
+ @staticmethod
+ def dist_init_distributor_dict():
+ distributor_dict.update(
+ {
+ 'tme': {
+ 'module': 'tme', # The directory name containing this file.
+ 'scrape': 'web', # Allowable values: 'web' or 'local'.
+ 'label': 'TME', # Distributor label used in spreadsheet columns.
+ 'order_cols': ['part_num', 'purch', 'refs'], # Sort-order for online orders.
+ 'order_delimiter': ' ', # Delimiter for online orders.
+ # Formatting for distributor header in worksheet.
+ 'wrk_hdr_format': {
+ 'font_size': 14,
+ 'font_color': 'white',
+ 'bold': True,
+ 'align': 'center',
+ 'valign': 'vcenter',
+ 'bg_color': '#0C4DA1' # TME blue
+ },
+ # Web site defitions.
+ 'site': {
+ 'url': 'https://www.tme.eu/en/',
+ 'currency': 'USD',
+ 'locale': 'UK'
+ },
+ }
+ })
+
def __ajax_details(self, pn):
'''@brief Load part details from TME using XMLHttpRequest.
@param pn `str()` part number
diff --git a/kicost/eda_tools/altium/altium.py b/kicost/eda_tools/altium/altium.py
index c63cb988a..4c2ff0cf5 100644
--- a/kicost/eda_tools/altium/altium.py
+++ b/kicost/eda_tools/altium/altium.py
@@ -37,7 +37,7 @@
import logging
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE # Debug configurations.
from ...globals import SEPRTR
-from ...kicost import distributor_dict
+from ...distributors.global_vars import distributor_dict
from ..eda_tools import field_name_translations, remove_dnp_parts
from ..eda_tools import PART_REF_REGEX_NOT_ALLOWED
diff --git a/kicost/eda_tools/csv/generic_csv.py b/kicost/eda_tools/csv/generic_csv.py
index cd9c9ab7d..a5210a3f3 100644
--- a/kicost/eda_tools/csv/generic_csv.py
+++ b/kicost/eda_tools/csv/generic_csv.py
@@ -36,7 +36,7 @@
import logging
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE # Debug configurations.
from ..eda_tools import field_name_translations, remove_dnp_parts, split_refs
-from ...kicost import distributor_dict
+from ...distributors.global_vars import distributor_dict
# Add to deal with the generic CSV header purchase list.
field_name_translations.update(
diff --git a/kicost/eda_tools/eda_tools.py b/kicost/eda_tools/eda_tools.py
index 6b0c0f9fb..0c94a7136 100644
--- a/kicost/eda_tools/eda_tools.py
+++ b/kicost/eda_tools/eda_tools.py
@@ -30,7 +30,7 @@
import re, os # Regular expression parser and matches.
from ..globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE # Debug configurations.
from ..globals import SEPRTR
-from ..kicost import distributor_dict
+from ..distributors.global_vars import distributor_dict
from . import eda_tool_dict # EDA dictionary with the features.
__all__ = ['file_eda_match', 'partgroup_qty', 'groups_sort', 'order_refs', 'subpartqty_split', 'group_parts']
diff --git a/kicost/eda_tools/kicad/kicad.py b/kicost/eda_tools/kicad/kicad.py
index bbdf0a783..5c1b5aab1 100644
--- a/kicost/eda_tools/kicad/kicad.py
+++ b/kicost/eda_tools/kicad/kicad.py
@@ -33,7 +33,7 @@
from bs4 import BeautifulSoup
from ...globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE
from ...globals import SEPRTR
-from ...kicost import distributor_dict
+from ...distributors.global_vars import distributor_dict
from ..eda_tools import field_name_translations, remove_dnp_parts
diff --git a/kicost/kicost.py b/kicost/kicost.py
index d5ef67575..62e7022e2 100644
--- a/kicost/kicost.py
+++ b/kicost/kicost.py
@@ -50,28 +50,8 @@
from .globals import *
# Import information about various distributors.
-from .distributors import distributor_dict
-from .distributors import distributor, fake_browser
-
-# The distributor module directories will be found in this directory.
-directory = os.path.dirname(__file__) + "/distributors"
-
-# Search for the distributor modules and import them.
-for module in os.listdir(directory):
-
- # Avoid importing non-directories.
- abs_module = os.path.join(directory, module)
- if not os.path.isdir(abs_module):
- continue
-
- # Avoid directories like __pycache__.
- if module.startswith('__'):
- continue
-
- # Import the module.
- tmp = __import__("distributors."+module, globals(), locals(), [], level=1)
- tmp_mod = getattr(tmp, module);
- globals()["dist_"+module] = getattr(tmp_mod, "dist_"+module)
+from .distributors import *
+from .distributors.global_vars import distributor_dict
# Import information for various EDA tools.
from .eda_tools import eda_modules
diff --git a/kicost/kicost_gui.py b/kicost/kicost_gui.py
index d2f552b7f..4a4cca482 100644
--- a/kicost/kicost_gui.py
+++ b/kicost/kicost_gui.py
@@ -43,7 +43,9 @@
from . import __version__ # Version control by @xesscorp.
from .kicost import * # kicost core functions.
-from .distributors import distributor_dict, fake_browser # Use the configurations alredy made to get KiCost last version.
+from .distributors import fake_browser # Use the configurations alredy made to get KiCost last version.
+from .distributors import init_distributor_dict
+from .distributors.global_vars import distributor_dict
from .eda_tools import eda_tool_dict
from .eda_tools.eda_tools import file_eda_match
@@ -795,6 +797,7 @@ def str_to_arg(commands):
except Exception as e:
print(e)
print('Elapsed time: {} seconds'.format(time.time() - start_time) )
+ init_distributor_dict()
#self.m_gauge_process.SetValue(100)
return
diff --git a/kicost/spreadsheet.py b/kicost/spreadsheet.py
index 7159d8cfd..6199204f7 100644
--- a/kicost/spreadsheet.py
+++ b/kicost/spreadsheet.py
@@ -36,7 +36,7 @@
from . import __version__ # Version control by @xesscorp.
from .globals import SEPRTR
from .globals import logger, DEBUG_OVERVIEW, DEBUG_DETAILED, DEBUG_OBSESSIVE
-from .distributors import distributor_dict # Distributors names and definitions to use in the spreadsheet.
+from .distributors.global_vars import distributor_dict # Distributors names and definitions to use in the spreadsheet.
from .eda_tools.eda_tools import partgroup_qty, order_refs, PART_REF_REGEX
__all__ = ['create_spreadsheet']