def qualityAssuranceTest2(self, parent): """ Test the top level config file for valid and invalid inputs """ # from QALib.QAUtil import QAUtil # util = QAUtil() # Create a top level config file import tempfile from ConfigParser import SafeConfigParser as parser # Create the module file modParser = parser() testDict = {"GUI":[("widget", "ctkCollapsibleButton"), ("name", "test1"), ("text", "Test1"), ("layout", "vertical"), ("children", "child1, child2, child3")], "child1":[("widget", "QFrame"), ("layout", "horizontal"), ("children", "child11, child12")], "child2":[("widget", "QFrame"), ("layout", "vertical"), ("children", "child21, child21, child12")], "child3":[("widget", "QPushButton"), ("text", "child3"), ("name", "child3"), ("clicked", "printButton('%(name)s')")], "child11":[("widget", "QPushButton"), ("text", "child11"), ("name", "child11"), ("clicked", "printButton('%(name)s')")], "child12":[("widget", "QFrame"), ("layout", "vertical"), ("children", "child3, child3, child3")], "child21":[("widget", "QFrame"), ("layout", "form"), ("children", "child3, child3, child3, child3")]} for section, options in testDict.items(): modParser.add_section(section) for option, value in options: modParser.set(section, option, value) with tempfile.NamedTemporaryFile(delete=False) as modTemp: modParser.write(modTemp) modFile = modTemp.name print modFile # Create top file topParser = parser() section = "Module1" topParser.add_section(section) topParser.set(section, "Name", "Supercalafragalisticexpialidoshous") topParser.set(section, "Module", modFile) topParser.set(section, "Database", "test1_schema.ini") topParser.set(section, "Logic", "test1.py") with tempfile.NamedTemporaryFile(delete=False) as topTemp: topParser.write(topTemp) topFile = topTemp.name print topFile # Create the widget widget = QualityAssuranceWidget(parent, topFile)
#!/usr/bin/env python #encoding=utf-8 ''' Author: osa开源团队 Description: osa_alert.ini文件解析模块 Create Date: 2011-07-20 ''' from __future__ import with_statement from ConfigParser import SafeConfigParser as parser _parser = parser() class osaParser(object): ''' @ osa .ini文件解析类 ''' def __init__(self, ini, oparser=_parser): with open(ini) as fobj: oparser.readfp(fobj) self._ini = ini self._oparser = oparser def getValue(self, sec='global', key=None): if self._oparser.has_option(sec, key): return self._oparser.get(sec, key) return self._oparser.get('global', key)
#!/usr/bin/env python """Demonstrate 'import as'""" import re as regex from ConfigParser import SafeConfigParser as parser print "regex:", regex.__file__ print "parser:", parser()
#!/usr/bin/env python #encoding=utf-8 ''' Author: osa开源团队 Description: osa_alert.ini文件解析模块 Create Date: 2011-07-20 ''' from __future__ import with_statement from ConfigParser import SafeConfigParser as parser _parser = parser() class osaParser(object): ''' @ osa .ini文件解析类 ''' def __init__(self, ini, oparser = _parser): with open(ini) as fobj: oparser.readfp(fobj) self._ini = ini self._oparser = oparser def getValue(self, sec='global', key=None): if self._oparser.has_option(sec, key): return self._oparser.get(sec, key)
def parse_ini(inpt = "./settings/main.ini" ): """ :param inpt: :return: """ out = {} p = parser() p.read(inpt) #print(parser.sections()) indata = p['indata'] out["working_directory"] = indata.get("working_directory",".") field_name = indata.get("field_name","") if not field_name: raise ValueError("input field_name is mandatory") else: out["field_name"]=field_name data_extraction = p['data_extraction'] out["mean"] = data_extraction.getboolean("mean", False) #the band combinations to use in format [(1,2),(1,3),....]; use * for all combinations; [] for no combinations out["band_combinations"] = data_extraction.get("band_combinations","[]") # a percentage of pixels to consider during polygons to raster intersection (>0); use 100 if no subset pixel_subset = data_extraction.getint("pixel_subset", 100) if pixel_subset == 100: pixel_subset = None else: out["pixel_subset"] = pixel_subset # the single band combination to use for charting the NDI in format [(1,2)]; only one combination is now possible out["NDI_chart_combinations"] = data_extraction.get("NDI_chart_combinations" , "[(7,5)]") #the nodatavalue to assign when polygons falls outside the raster (this works when mean == True) out["nodatavalue"] = data_extraction.get("nodatavalue", None) #this is not necessary anymore because now the heralick paths are in thejson file #haralick = p['haralick'] #folder tha will contain the input image for heralick #out["hara_dir"] = haralick.get("hara_dir","." ) # heralick image suffix format (comma separated list) #out["haralick_format"] = haralick.get("haralick_format","tif") #simple, advanced, higher? #out["haralick_image_type"] = haralick.get("haralick_image_type","simple") #folder tha will contain the input ndi images for heralick #out["hara_ndi_dir"] = haralick.get("hara_ndi_dir" ,"." ) # heralick ndi image suffix format (comma separated list) #out["haralick_ndi_format"] =haralick.get("haralick_ndi_format" , "tif") #simple, advanced, higher? #out["haralick_ndi_type"] = haralick.get("haralick_ndi_type","simple") skll = p['skll'] out["skll_dir"] = skll.get("skll_dir","." ) boruta = p['boruta'] out["boruta_dir"] = boruta.get("boruta_dir","." ) classification = p['classification'] #percentage of validation data out["validation_data"] = classification.getint("validation_data", 25) # classified raster name prefix out["out_name"] = classification.get("out_name", "classify.tif") #tile size used during classification out["tile_size"] = classification.getint("tile_size", 1024) ipyparallel = p['ipyparallel'] out["parallelize"] = ipyparallel.getboolean('parallelize', False) out["engine_messages"] = ipyparallel.getboolean('engine_messages', False) out["max_processes"] = ipyparallel.getint("max_processes", 4) return out