From 40d38417360e7cd6602932e54c8b0e5fd3519355 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 30 Sep 2017 23:21:32 +0200 Subject: o Preventing ConfigParser from lower casing the keys in the ini file. Thanks to https://stackoverflow.com/a/19359720/245614. o Using different colors for the different log levels. --- src/ee/digikey/__init__.py | 13 +++++++++---- src/ee/tools/__init__.py | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py index 23569f9..3b1c52c 100644 --- a/src/ee/digikey/__init__.py +++ b/src/ee/digikey/__init__.py @@ -91,8 +91,7 @@ class DigikeyProduct(object): def __hash__(self): return self.part_number.__hash__() - def to_ini(self): - c = configparser.ConfigParser() + def to_ini(self, c: configparser.ConfigParser): c["overview"] = {}; overview = c["overview"] overview["part_number"] = self.part_number @@ -313,7 +312,8 @@ class DigikeyRepository(object): return p def save(self, product: DigikeyProduct): - y = product.to_ini() + c = self._make_configparser() + y = product.to_ini(c) filename = self.mpn_to_path(product.mpn) mk_parents(filename) with open(filename, "w") as f: @@ -322,8 +322,13 @@ class DigikeyRepository(object): def load_all(self): [self._load(path) for path in glob.glob(self._path + "/*.ini")] - def _load(self, path): + def _make_configparser(self): c = configparser.ConfigParser() + c.optionxform = str + return c + + def _load(self, path): + c = self._make_configparser() c.read(path) p = DigikeyProduct.from_ini(self._digikey, c) self._products[p.mpn] = p diff --git a/src/ee/tools/__init__.py b/src/ee/tools/__init__.py index 136bdf1..68e3adc 100644 --- a/src/ee/tools/__init__.py +++ b/src/ee/tools/__init__.py @@ -30,10 +30,10 @@ class Log(object): print(color(msg, "orange")) def info(self, msg): - print(color(msg, "orange")) + print(color(msg, "white")) def debug(self, msg): - print(color(msg, "orange")) + print(color(msg, "grey")) log = Log() -- cgit v1.2.3