def getSentenceSplit(self): try: config = ConfigObj(os.path.join(os.path.expanduser('~'), "gromoteur", ".settings", "gro.cfg"), encoding="UTF-8") config.BOM = True if verbose: print( "read", os.path.join(os.path.expanduser('~'), "gromoteur", ".settings", "gro.cfg")) return re.compile(config["configuration"]["sentenceSplit"], re.M + re.U) except Exception as e: try: config = ConfigObj(os.path.join("lib", "gro.cfg"), encoding="UTF-8") config.BOM = True if verbose: print("read", os.path.join("lib", "gro.cfg")) return re.compile(config["configuration"]["sentenceSplit"], re.M + re.U) except Exception as e: if verbose: print("can't read config file: gro.cfg", e) return re.compile(defaultSentenceSplit, re.M + re.U)
def saveWiz(wiz): filename=str(os.path.join(os.path.expanduser('~'),"gromoteur",".settings",str(wiz.configName.text())+".gro.cfg" )) config = ConfigObj(encoding="UTF-8") config.BOM=True config["spider configuration"]={} for o in wiz.stringObjectList: oname=str(o.objectName()) try:config["spider configuration"][oname] = str(o.text()) except: if verbose: print("problem saving",oname,o) # for o in wiz.specialStringObjectList: # oname=unicode(o.objectName()) # try:config["spider configuration"][oname] = ' '+unicode(o.text())+' ' # except: # if verbose: print "problem saving",oname,o for o in wiz.checkObjectList: oname=str(o.objectName()) if oname=="__qt__passive_wizardbutton6":oname="expert" if o.isChecked(): config["spider configuration"][oname] = "yes" else: config["spider configuration"][oname] = "no" try: if o.isChecked(): config["spider configuration"][oname] = "yes" else: config["spider configuration"][oname] = "no" except: if verbose: print("problem saving",oname,o, o.isChecked(), config["spider configuration"][oname]) for o in wiz.valueObjectList: oname=str(o.objectName()) try: config["spider configuration"][oname] = str(o.value()) except: if verbose: print("problem saving",oname,o) for o in wiz.comboObjectList: oname=str(o.objectName()) if oname == "language": if o.currentIndex()==0: txt = "any language" else: txt = o.currentText() else: txt = o.currentText() try: config["spider configuration"][oname] = str(txt) except: if verbose: print("problem saving",oname,o) config.filename=filename config.write()
def test_reset_a_configobj(): something = object() cfg = ConfigObj() cfg['something'] = something cfg['section'] = {'something': something} cfg.filename = 'fish' cfg.raise_errors = something cfg.list_values = something cfg.create_empty = something cfg.file_error = something cfg.stringify = something cfg.indent_type = something cfg.encoding = something cfg.default_encoding = something cfg.BOM = something cfg.newlines = something cfg.write_empty_values = something cfg.unrepr = something cfg.initial_comment = something cfg.final_comment = something cfg.configspec = something cfg.inline_comments = something cfg.comments = something cfg.defaults = something cfg.default_values = something cfg.reset() assert cfg.filename is None assert cfg.raise_errors is False assert cfg.list_values is True assert cfg.create_empty is False assert cfg.file_error is False assert cfg.interpolation is True assert cfg.configspec is None assert cfg.stringify is True assert cfg.indent_type is None assert cfg.encoding is None assert cfg.default_encoding is None assert cfg.unrepr is False assert cfg.write_empty_values is False assert cfg.inline_comments == {} assert cfg.comments == {} assert cfg.defaults == [] assert cfg.default_values == {} assert cfg == ConfigObj() assert repr(cfg) == 'ConfigObj({})'
def fillWiz(configName, wiz, useDefault=False): """ puts all the values from config in the right place""" filename=str(os.path.join(os.path.expanduser('~'),"gromoteur",".settings",str(configName)+".gro.cfg" )) if os.path.exists(filename) and not useDefault: try: config = ConfigObj(filename,encoding="UTF-8") config.BOM=True if verbose : print("read", filename) except Exception as e: if verbose : print("can't read config file:",filename,e) else: config = ConfigObj(str("gro.cfg.default"),encoding="UTF-8") config.BOM=True for o in wiz.stringObjectList: oname=str(o.objectName()) try: o.setText(config["spider configuration"][oname]) except Exception as e: if verbose : print("stringObjectList,strange thing in the config file:",oname,e) # for o in wiz.specialStringObjectList: # oname=unicode(o.objectName()) # try: o.setText(config["spider configuration"][oname].strip()) # except Exception, e: # if verbose : print "comboObjectList,strange thing in the config file:",oname,e for o in wiz.checkObjectList: oname=str(o.objectName()) if oname=="__qt__passive_wizardbutton6":oname="expert" try: o.setChecked(config["spider configuration"][oname]=="yes") except Exception as e: if verbose : print("checkObjectList,strange thing in the config file:",oname,e) for o in wiz.valueObjectList: oname=str(o.objectName()) try: try: o.setValue(int(config["spider configuration"][oname])) except: o.setValue(-1) except Exception as e: if verbose : print("valueObjectList,strange thing in the config file:",oname,e) for o in wiz.comboObjectList: oname=str(o.objectName()) try: if oname == "language" and config["spider configuration"]["language"] == "any language": o.setCurrentIndex(0) else: try: o.setCurrentIndex(o.findText(config["spider configuration"][oname])) except Exception as e: if verbose : print("comboObjectList, strange thing in the config file:",oname,e) except: print("ooh",o) # special: if wiz.startWithURL.isChecked() : wiz.startWithURL.click() if wiz.startWithUrlFile.isChecked() : wiz.startWithUrlFile.click() if wiz.startWithSearchEngine.isChecked() : wiz.startWithSearchEngine.click()