(configpath)
| 729 | pass |
| 730 | |
| 731 | def parse_config(configpath): |
| 732 | if not (CLINICAL_MODE and configpath == 'config.ini'): |
| 733 | fullpath = os.path.join(get_data_dir(), configpath) |
| 734 | if not os.path.isfile(fullpath): |
| 735 | rewrite_configfile(configpath, overwrite=False) |
| 736 | |
| 737 | # The following is a routine to overwrite older config files with the new one. |
| 738 | oldconfigfile = open(fullpath, 'r+') |
| 739 | while oldconfigfile: |
| 740 | line = oldconfigfile.readline() |
| 741 | if line == '': # EOF reached. string 'generated by Brain Workshop' not found |
| 742 | oldconfigfile.close() |
| 743 | rewrite_configfile(configpath, overwrite=True) |
| 744 | break |
| 745 | if line.find('generated by Brain Workshop') > -1: |
| 746 | splitline = line.split() |
| 747 | version = splitline[5] |
| 748 | if version < CONFIG_OVERWRITE_IF_OLDER_THAN: |
| 749 | oldconfigfile.close() |
| 750 | os.rename(fullpath, fullpath + '.' + version + '.bak') |
| 751 | rewrite_configfile(configpath, overwrite=True) |
| 752 | break |
| 753 | oldconfigfile.close() |
| 754 | |
| 755 | try: |
| 756 | config = ConfigParser.ConfigParser() |
| 757 | config.read(os.path.join(get_data_dir(), configpath)) |
| 758 | except Exception as e: |
| 759 | debug_msg(e) |
| 760 | if configpath != 'config.ini': |
| 761 | quit_with_error(_('Unable to load config file: %s') % |
| 762 | os.path.join(get_data_dir(), configpath)) |
| 763 | |
| 764 | defaultconfig = ConfigParser.ConfigParser() |
| 765 | if sys.version_info >= (3,): |
| 766 | defaultconfig.read_file(StringIO(CONFIGFILE_DEFAULT_CONTENTS)) |
| 767 | else: |
| 768 | defaultconfig.readfp(StringIO.StringIO(CONFIGFILE_DEFAULT_CONTENTS)) |
| 769 | |
| 770 | def try_eval(text): # this is a one-use function for config parsing |
| 771 | try: return eval(text) |
| 772 | except: return text |
| 773 | |
| 774 | cfg = dotdict() |
| 775 | if CLINICAL_MODE and CONFIGFILE == 'config.ini': configs = (defaultconfig,) |
| 776 | else: configs = (defaultconfig, config) |
| 777 | for config in configs: # load defaultconfig first, in case of incomplete user's config.ini |
| 778 | config_items = [(k.upper(), try_eval(v)) for k, v in config.items('DEFAULT')] |
| 779 | cfg.update(config_items) |
| 780 | |
| 781 | if not 'CHANCE_OF_INTERFERENCE' in cfg: |
| 782 | cfg.CHANCE_OF_INTERFERENCE = cfg.DEFAULT_CHANCE_OF_INTERFERENCE |
| 783 | rtrn = get_argv('--statsfile') |
| 784 | if rtrn: |
| 785 | cfg.STATSFILE = rtrn |
| 786 | return cfg |
| 787 | |
| 788 | def rewrite_configfile(configfile, overwrite=False): |
no test coverage detected