def print_color(txt, func_color=darkgreen, underline=False): try: if underline: print(easydev.underline(func_color(txt))) else: print(func_color(txt)) except: print(txt)
def print_color(txt, func_color, underline=False): import easydev try: if underline: print(easydev.underline(func_color(txt))) else: print(func_color(txt)) except: print(txt)
def read_user_config_file_and_update_params(self): """Read the configuration file and update parameters Read the configuration file (file with extension cfg and name of your app). Section and option found will be used to update the :attr:`params`. If a set of section/option is not correct (not in the :attr:`params`) then it is ignored. The :attr:`params` is a dictionary with keys being labelled as <section>.<option> For instance, the key "cache.on" should be written in the configuration file as:: [cache] on = True where True is the expected value. """ try: self.config_parser.read(self.user_config_file_path) except IOError: msg = "Welcome to %s" % self.name.capitalize() print(underline(msg)) print("It looks like you do not have a configuration file.") print("We are creating one with default values in %s ." % self.user_config_file_path) print("Done") self.create_default_config_file() # now, update the params attribute if needed for section in self.config_parser.sections(): dic = self.config_parser.section2dict(section) for key in dic.keys(): value = dic[key] newkey = section + '.' + key if newkey in self.params.keys(): # the type should be self.params[newkey][1] cast = self.params[newkey][1] # somehow if isinstance(value, cast) is True: self.params[newkey][0] = value else: print( "Warning:: found an incorrect type while parsing {} file. In section '{}', the option '{}' should be a {}. Found value {}. Trying a cast..." .format(self.user_config_file_path, section, key, cast, value)) self.params[newkey][0] = cast(value) else: print( "Warning:: found invalid option or section in %s (ignored):" % self.user_config_file_path) print(" %s %s" % (section, option))
def read_user_config_file_and_update_params(self): """Read the configuration file and update parameters Read the configuration file (file with extension cfg and name of your app). Section and option found will be used to update the :attr:`params`. If a set of section/option is not correct (not in the :attr:`params`) then it is ignored. The :attr:`params` is a dictionary with keys being labelled as <section>.<option> For instance, the key "cache.on" should be written in the configuration file as:: [cache] on = True where True is the expected value. """ try: self.config_parser.read(self.user_config_file_path) except IOError: msg = "Welcome to %s" % self.name.capitalize() print(underline(msg)) print("It looks like you do not have a configuration file.") print("We are creating one with default values in %s ." % self.user_config_file_path) print("Done") self.create_default_config_file() # now, update the params attribute if needed for section in self.config_parser.sections(): dic = self.config_parser.section2dict(section) for key in dic.keys(): value = dic[key] newkey = section + '.' + key if newkey in self.params.keys(): # the type should be self.params[newkey][1] cast = self.params[newkey][1] # somehow if isinstance(value, cast) is True: self.params[newkey][0] = value else: print("Warning:: found an incorrect type while parsing {} file. In section '{}', the option '{}' should be a {}. Found value {}. Trying a cast...".format(self.user_config_file_path, section, key, cast, value)) self.params[newkey][0] = cast(value) else: print("Warning:: found invalid option or section in %s (ignored):" % self.user_config_file_path) print(" %s %s" % (section, option))
def _underline(self, msg): import easydev return easydev.underline(msg)