def new_plugin_wizard(directory=None): """ Start the wizard to create a new plugin in the current working directory. """ if directory is None: print("This wizard will create a new plugin for you in the current directory.") directory = os.getcwd() else: print("This wizard will create a new plugin for you in '%s'." % directory) if os.path.exists(directory) and not os.path.isdir(directory): print("Error: The path '%s' exists but it isn't a directory" % directory) sys.exit(1) name = ask( "What should the name of your new plugin be?", validation_regex=r'^[a-zA-Z][a-zA-Z0-9 _-]*$' ).strip() module_name = name.lower().replace(' ', '_') directory_name = name.lower().replace(' ', '-') class_name = "".join([s.capitalize() for s in name.lower().split(' ')]) description = ask( "What may I use as a short (one-line) description of your plugin?" ) if PY2: default_python_version = "2+" else: default_python_version = "3" python_version = ask( "Which python version will your plugin work with? 2, 2+ or 3? I will default to " "{version} if you leave this blank.".format(version=default_python_version), valid_responses=['2', '2+', '3', ''] ) if python_version.strip() == "": python_version = default_python_version errbot_min_version = ask( "Which minimum version of errbot will your plugin work with? " "Leave blank to support any version or input CURRENT to select the " "current version (%s)" % VERSION ).strip() if errbot_min_version.upper() == "CURRENT": errbot_min_version = VERSION errbot_max_version = ask( "Which maximum version of errbot will your plugin work with? " "Leave blank to support any version or input CURRENT to select the " "current version (%s)" % VERSION ).strip() if errbot_max_version.upper() == "CURRENT": errbot_max_version = VERSION plug = ConfigParser() plug["Core"] = { "Name": name, "Module": module_name, } plug["Documentation"] = { "Description": description, } plug["Python"] = { "Version": python_version, } plug["Errbot"] = {} if errbot_min_version != "": plug["Errbot"]["Min"] = errbot_min_version if errbot_max_version != "": plug["Errbot"]["Max"] = errbot_max_version plugin_path = directory plugfile_path = os.path.join(plugin_path, module_name+".plug") pyfile_path = os.path.join(plugin_path, module_name+".py") try: if PY3 or (PY2 and not os.path.isdir(plugin_path)): os.makedirs(plugin_path, mode=0o700) except IOError as e: if e.errno != errno.EEXIST: raise if os.path.exists(plugfile_path) or os.path.exists(pyfile_path): ask( "Warning: A plugin with this name was already found at {path}\n" "If you continue, these will be overwritten.\n" "Press Ctrl+C to abort now or type in 'overwrite' to confirm overwriting of these files." "".format( path=os.path.join(directory, module_name+".{py,plug}") ), valid_responses=["overwrite"], ) with open(plugfile_path, 'w') as f: plug.write(f) with open(pyfile_path, 'w') as f: f.write(render_plugin(locals())) print("Success! You'll find your new plugin at '%s'" % plugfile_path) print("(Don't forget to include a LICENSE file if you are going to publish your plugin)")
class LayerFileReader(LayerReader): def __init__(self, lcfname): ''' Constructor ''' super(LayerFileReader, self).__init__(lcfname) self.cp = ConfigParser() self.lcfilename = LU.standardiseLayerConfigName(self.lcfname) self._readConfigFile(self.lcfilename) def isCurrent(self): '''TF test to decide whether to init''' return self.lcfilename and self._fileexists() and len( self.cp.sections()) > 0 def close(self): self.cp = None self.lcfilename = None self.lcfname = None def _fileexists(self): return os.path.exists(self.lcfilename) def buildConfigLayer(self, res): '''Just write a file in conf with the name <driver>.layer.properties''' ###This should eb a UTF8 write, but only works as ASCII #open(self.filename,'w').write(str(res)) with codecs.open(self.lcfilename, 'w', 'utf-8') as lconf: lconf.write(res) self._readConfigFile(self.lcfilename) def _readConfigFile(self, fn): '''Reads named config file''' #Split off so you can override the config file on the same reader object if needed try: with codecs.open(fn, 'r', 'utf-8') as cf: self.cp.readfp(cf) except ParsingError as pe: ldslog.error( '{0} file corrupt. Please correct the error; {1} OR delete and rebuild' .format(fn, str(pe))) raise @override(LayerReader) def findLayerIdByName(self, name): '''Reverse lookup of section by associated name, finds first occurance only''' lid = filter(lambda n: name == self.cp.get(n, 'name'), self.cp.sections()) return lid[0] if len(lid) > 0 else None @override(LayerReader) def getLayerNames(self, refresh=False): '''Returns sections from properties file''' lcnames = [] for sec in self.cp.sections(): lcn = self.cp.get(sec, 'name') lcc = self.cp.get(sec, 'category') lcnames += [ (sec if type(sec) == unicode else unicode(sec, 'utf8'), lcn if type(lcn) == unicode else unicode(lcn, 'utf8'), (lcc if type(lcc) == unicode else unicode( lcc, 'utf8')).split(',')), ] return lcnames @override(LayerReader) def readLayerProperty(self, layer, key): try: if isinstance(layer, tuple) or isinstance(layer, list): value = () for l in layer: value += (LU.assessNone(self.cp.get(l, key)), ) else: value = LU.assessNone(self.cp.get(layer, key)) except: '''return a default value otherwise none which would also be a default for some keys''' #the logic here may be a bit suss, if the property is blank return none but if there is an error assume a default is needed? return {'pkey': 'ID', 'name': layer, 'geocolumn': 'SHAPE'}.get(key) return value def _readSingleLayerProperty(self, layer, key): return LU.assessNone(self.cp.get(layer, key)) @override(LayerReader) def writeLayerProperty(self, layer, field, value): '''Write changes to layer config table''' #if value: value = value.strip() try: if (isinstance(layer, tuple) or isinstance(layer, list)) and ( isinstance(value, tuple) or isinstance(value, list)): for l, v in zip(layer, value): self.cp.set(l, field, v.strip() if v else '') else: self.cp.set(layer, field, value.strip() if value else '') with codecs.open(self.lcfilename, 'w', 'utf-8') as configfile: self.cp.write(configfile) #ldslog.debug("Check "+str(field)+" for layer "+str(layer)+" is set to "+str(value)+" : GetField="+self.cp.get(layer, field)) except Exception as e: ldslog.warn('Problem writing LM date to layer config file. ' + str(e)) @override(LayerReader) def readLayerParameters(self, id): #def readLayerSchemaConfig(self,layer): '''Full Layer config reader. Returns the config values for the whole layer or makes sensible guesses for defaults''' from LDSUtilities import LayerConfEntry # # try: # defn = self.cp.get(layer, 'sql') # #if the user has gone to the trouble of defining their own schema in SQL just return that # return (defn,None,None,None,None,None,None,None,None) # except: # pass '''optional but one way to record the type and name of a column is to save a string tuple (name,type) and parse this at build time''' try: pkey = self.cp.get(id, 'pkey') except NoOptionError: ldslog.warn( "LayerSchema: No Primary Key Column defined, default to 'ID'") pkey = 'ID' '''names are/can-be stored so we can reverse search by layer name''' try: name = self.cp.get(id, 'name') except NoOptionError: ldslog.warn( "LayerSchema: No Name saved in config for this layer, returning ID" ) name = id if name is None: name = id '''names are/can-be stored so we can reverse search by layer name''' try: group = LU.assessNone(self.cp.get(id, 'category')) except NoOptionError: ldslog.warn("Group List: No Groups defined for this layer") group = None if not group: pass try: gcol = self.cp.get(id, 'geocolumn') except NoOptionError: ldslog.warn( "LayerSchema: No Geo Column defined, default to 'SHAPE'") gcol = 'SHAPE' #i dont think we need this anymore using the new logic, if gcol->spatial, if pkey->unique # try: # index = self.cp.get(layer, 'index') # except NoOptionError: # ldslog.warn("LayerSchema: No Index Column/Specification defined, default to None") # index = None try: epsg = self.cp.get(id, 'epsg') except NoOptionError: #print "No Projection Transformation defined"#don't really need to state the default occurance epsg = None try: lmod = self.cp.get(id, 'lastmodified') except NoOptionError: ldslog.warn( "LayerSchema: No Last-Modified date recorded, successful update will write current time here" ) lmod = None try: disc = self.cp.get(id, 'discard') except NoOptionError: disc = None try: cql = self.cp.get(id, 'cql') except NoOptionError: cql = None return LayerConfEntry(id, pkey, name, group, gcol, epsg, lmod, disc, cql) @override(LayerReader) def readAllLayerParameters(self): '''Gets all LC entries as a list of LCEs using readLayerParameters''' lcel = [] for ln in self.getLayerNames(): lcel += [ self.readLayerParameters(ln), ] return lcel
class GUIPrefsReader(object): ''' Reader for GUI prefs. To save re inputting every time ''' PREFS_SEC = 'prefs' GUI_PREFS = '../conf/gui.prefs' def __init__(self): ''' Constructor ''' self.dvalue = None self.dselect = 'dest' #v:x111|MYGROUP, myconf.conf, 2193, 2013-01-01, 2013-01-02 self.plist = ('lgvalue', 'uconf', 'epsg', 'fd', 'td') self.cp = ConfigParser() self.fn = os.path.join(os.path.dirname(__file__), self.GUI_PREFS) with codecs.open(self.fn, 'r', 'utf-8') as cf: self.cp.readfp(cf) def read(self): '''Read stored DS value and return this and its matching params''' try: with codecs.open(self.fn, 'r', 'utf-8') as cf: self.cp.readfp(cf) self.dvalue = self.cp.get(self.PREFS_SEC, self.dselect) if LU.assessNone(self.dvalue) is None: return (None, ) * (len(self.plist) + 1) except NoSectionError as nse: #if no sec init sec and opt and ret nones ldslog.warn('Error getting GUI prefs section :: ' + str(nse)) if not self._initSection(self.PREFS_SEC): raise self._initOption(self.PREFS_SEC, self.dselect) return (None, ) * (len(self.plist) + 1) except NoOptionError as noe: #if no opt init opt and ret nones ldslog.warn('Error getting GUI prefs :: ' + str(noe)) if not self._initOption(self.PREFS_SEC, self.dselect): raise return (None, ) * (len(self.plist) + 1) #if dval is okay ret it and res of a read of that sec return (self.dvalue, ) + self.readsec(self.dvalue) def readall(self): '''Reads entire grp into dict''' gpra = {} secs = self.cp.sections() secs.remove(self.PREFS_SEC) for sec in secs: gpra[sec] = self.readsec(sec) return gpra def getDestinations(self): return self.cp.sections() def readsec(self, section): #options per DS type rlist = () for p in self.plist: try: rlist += (self.cp.get(section, p), ) except NoSectionError as nse: #if not ds sec init sec then init opt ldslog.warn('Error getting GUI ' + section + ' :: ' + str(nse)) if not self._initSection(section): raise self._initOption(section, p) rlist += (None, ) except NoOptionError as noe: #if no opt init the opt ldslog.warn('Error getting GUI ' + section + ' pref, ' + p + ' :: ' + str(noe)) if not self._initOption(section, p): raise rlist += (None, ) return rlist def writeline(self, field, value): #not the best solution since depends on a current gpr and a recent read/write. if self.dvalue: self.writesecline(self.dvalue, field, value) def writesecline(self, section, field, value): try: self.cp.set(section, field, value if LU.assessNone(value) else '') with codecs.open(self.fn, 'w', 'utf-8') as configfile: self.cp.write(configfile) ldslog.debug(str(section) + ':' + str(field) + '=' + str(value)) except Exception as e: ldslog.warn('Problem writing GUI prefs. {} - sfv={}'.format( e, (section, field, value))) def write(self, rlist): self.dvalue = rlist[0] if self.cp.has_section(self.PREFS_SEC): self.cp.set(self.PREFS_SEC, self.dselect, self.dvalue) else: self.cp.add_section(self.PREFS_SEC) self.cp.set(self.PREFS_SEC, self.dselect, self.dvalue) for pr in zip(self.plist, rlist[1:]): if not self.cp.has_section(self.dvalue): self.cp.add_section(self.dvalue) try: if LU.assessNone(pr[1]): self.cp.set(self.dvalue, pr[0], pr[1]) ldslog.debug(self.dvalue + ':' + pr[0] + '=' + pr[1]) except Exception as e: ldslog.warn('Problem writing GUI prefs. ' + str(e)) with codecs.open(self.fn, 'w', 'utf-8') as configfile: self.cp.write(configfile) def _initSection(self, section): checksec = LU.standardiseDriverNames(section) if checksec: self.cp.add_section(checksec) return True elif section == self.PREFS_SEC: self.cp.add_section(section) return True return False def _initOption(self, section, option): if option in self.plist + (self.dselect, ): self.writesecline(section, option, None) return True return False @classmethod def validate(): '''Make sure a guipref file is valid, check pref points to alt least one valid DST''' filename = os.path.join(os.path.dirname(__file__), GUIPrefsReader.GUI_PREFS) gp = GUIPrefsReader(filename) #validate UC check it has a valid dest named and configured p = gp.cp.get('prefs', 'dest') return gp.cp.has_section(p)
def new_plugin_wizard(directory=None): """ Start the wizard to create a new plugin in the current working directory. """ if directory is None: print( "This wizard will create a new plugin for you in the current directory." ) directory = os.getcwd() else: print("This wizard will create a new plugin for you in '%s'." % directory) if os.path.exists(directory) and not os.path.isdir(directory): print("Error: The path '%s' exists but it isn't a directory" % directory) sys.exit(1) name = ask("What should the name of your new plugin be?", validation_regex=r'^[a-zA-Z][a-zA-Z0-9 _-]*$').strip() module_name = name.lower().replace(' ', '_') directory_name = name.lower().replace(' ', '-') class_name = "".join([s.capitalize() for s in name.lower().split(' ')]) description = ask( "What may I use as a short (one-line) description of your plugin?") if PY2: default_python_version = "2+" else: default_python_version = "3" python_version = ask( "Which python version will your plugin work with? 2, 2+ or 3? I will default to " "{version} if you leave this blank.".format( version=default_python_version), valid_responses=['2', '2+', '3', '']) if python_version.strip() == "": python_version = default_python_version errbot_min_version = ask( "Which minimum version of errbot will your plugin work with? " "Leave blank to support any version or input CURRENT to select the " "current version (%s)" % VERSION).strip() if errbot_min_version.upper() == "CURRENT": errbot_min_version = VERSION errbot_max_version = ask( "Which maximum version of errbot will your plugin work with? " "Leave blank to support any version or input CURRENT to select the " "current version (%s)" % VERSION).strip() if errbot_max_version.upper() == "CURRENT": errbot_max_version = VERSION plug = ConfigParser() plug["Core"] = { "Name": name, "Module": module_name, } plug["Documentation"] = { "Description": description, } plug["Python"] = { "Version": python_version, } plug["Errbot"] = {} if errbot_min_version != "": plug["Errbot"]["Min"] = errbot_min_version if errbot_max_version != "": plug["Errbot"]["Max"] = errbot_max_version plugin_path = directory plugfile_path = os.path.join(plugin_path, module_name + ".plug") pyfile_path = os.path.join(plugin_path, module_name + ".py") try: if PY3 or (PY2 and not os.path.isdir(plugin_path)): os.makedirs(plugin_path, mode=0o700) except IOError as e: if e.errno != errno.EEXIST: raise if os.path.exists(plugfile_path) or os.path.exists(pyfile_path): ask( "Warning: A plugin with this name was already found at {path}\n" "If you continue, these will be overwritten.\n" "Press Ctrl+C to abort now or type in 'overwrite' to confirm overwriting of these files." "".format(path=os.path.join(directory, module_name + ".{py,plug}")), valid_responses=["overwrite"], ) with open(plugfile_path, 'w') as f: plug.write(f) with open(pyfile_path, 'w') as f: f.write(render_plugin(locals())) print("Success! You'll find your new plugin at '%s'" % plugfile_path) print( "(Don't forget to include a LICENSE file if you are going to publish your plugin)" )
class LayerFileReader(LayerReader): def __init__(self,lcfname): ''' Constructor ''' super(LayerFileReader,self).__init__(lcfname) self.cp = ConfigParser() self.lcfilename = LU.standardiseLayerConfigName(self.lcfname) self._readConfigFile(self.lcfilename) def isCurrent(self): '''TF test to decide whether to init''' return self.lcfilename and self._fileexists() and len(self.cp.sections())>0 def close(self): self.cp = None self.lcfilename = None self.lcfname = None def _fileexists(self): return os.path.exists(self.lcfilename) def buildConfigLayer(self,res): '''Just write a file in conf with the name <driver>.layer.properties''' ###This should eb a UTF8 write, but only works as ASCII #open(self.filename,'w').write(str(res)) with codecs.open(self.lcfilename,'w','utf-8') as lconf: lconf.write(res) self._readConfigFile(self.lcfilename) def _readConfigFile(self,fn): '''Reads named config file''' #Split off so you can override the config file on the same reader object if needed try: with codecs.open(fn,'r','utf-8') as cf: self.cp.readfp(cf) except ParsingError as pe: ldslog.error('{0} file corrupt. Please correct the error; {1} OR delete and rebuild'.format(fn,str(pe))) raise @override(LayerReader) def findLayerIdByName(self,name): '''Reverse lookup of section by associated name, finds first occurance only''' lid = filter(lambda n: name==self.cp.get(n,'name'),self.cp.sections()) return lid[0] if len(lid)>0 else None @override(LayerReader) def getLayerNames(self,refresh=False): '''Returns sections from properties file''' lcnames = [] for sec in self.cp.sections(): lcn = self.cp.get(sec, 'name') lcc = self.cp.get(sec,'category') lcnames += [(sec if type(sec)==unicode else unicode(sec,'utf8'), lcn if type(lcn)==unicode else unicode(lcn,'utf8'), (lcc if type(lcc)==unicode else unicode(lcc,'utf8')).split(',')),] return lcnames @override(LayerReader) def readLayerProperty(self,layer,key): try: if isinstance(layer,tuple) or isinstance(layer,list): value = () for l in layer: value += (LU.assessNone(self.cp.get(l, key)),) else: value = LU.assessNone(self.cp.get(layer, key)) except: '''return a default value otherwise none which would also be a default for some keys''' #the logic here may be a bit suss, if the property is blank return none but if there is an error assume a default is needed? return {'pkey':'ID','name':layer,'geocolumn':'SHAPE'}.get(key) return value def _readSingleLayerProperty(self,layer,key): return LU.assessNone(self.cp.get(layer, key)) @override(LayerReader) def writeLayerProperty(self,layer,field,value): '''Write changes to layer config table''' #if value: value = value.strip() try: if (isinstance(layer,tuple) or isinstance(layer,list)) and (isinstance(value,tuple) or isinstance(value,list)): for l,v in zip(layer,value): self.cp.set(l,field,v.strip() if v else '') else: self.cp.set(layer,field,value.strip() if value else '') with codecs.open(self.lcfilename, 'w','utf-8') as configfile: self.cp.write(configfile) #ldslog.debug("Check "+str(field)+" for layer "+str(layer)+" is set to "+str(value)+" : GetField="+self.cp.get(layer, field)) except Exception as e: ldslog.warn('Problem writing LM date to layer config file. '+str(e)) @override(LayerReader) def readLayerParameters(self,id): #def readLayerSchemaConfig(self,layer): '''Full Layer config reader. Returns the config values for the whole layer or makes sensible guesses for defaults''' from LDSUtilities import LayerConfEntry # # try: # defn = self.cp.get(layer, 'sql') # #if the user has gone to the trouble of defining their own schema in SQL just return that # return (defn,None,None,None,None,None,None,None,None) # except: # pass '''optional but one way to record the type and name of a column is to save a string tuple (name,type) and parse this at build time''' try: pkey = self.cp.get(id, 'pkey') except NoOptionError: ldslog.warn("LayerSchema: No Primary Key Column defined, default to 'ID'") pkey = 'ID' '''names are/can-be stored so we can reverse search by layer name''' try: name = self.cp.get(id, 'name') except NoOptionError: ldslog.warn("LayerSchema: No Name saved in config for this layer, returning ID") name = id if name is None: name = id '''names are/can-be stored so we can reverse search by layer name''' try: group = LU.assessNone(self.cp.get(id, 'category')) except NoOptionError: ldslog.warn("Group List: No Groups defined for this layer") group = None if not group: pass try: gcol = self.cp.get(id, 'geocolumn') except NoOptionError: ldslog.warn("LayerSchema: No Geo Column defined, default to 'SHAPE'") gcol = 'SHAPE' #i dont think we need this anymore using the new logic, if gcol->spatial, if pkey->unique # try: # index = self.cp.get(layer, 'index') # except NoOptionError: # ldslog.warn("LayerSchema: No Index Column/Specification defined, default to None") # index = None try: epsg = self.cp.get(id, 'epsg') except NoOptionError: #print "No Projection Transformation defined"#don't really need to state the default occurance epsg = None try: lmod = self.cp.get(id, 'lastmodified') except NoOptionError: ldslog.warn("LayerSchema: No Last-Modified date recorded, successful update will write current time here") lmod = None try: disc = self.cp.get(id, 'discard') except NoOptionError: disc = None try: cql = self.cp.get(id, 'cql') except NoOptionError: cql = None return LayerConfEntry(id,pkey,name,group,gcol,epsg,lmod,disc,cql) @override(LayerReader) def readAllLayerParameters(self): '''Gets all LC entries as a list of LCEs using readLayerParameters''' lcel = [] for ln in self.getLayerNames(): lcel += [self.readLayerParameters(ln),] return lcel
class GUIPrefsReader(object): ''' Reader for GUI prefs. To save re inputting every time ''' PREFS_SEC = 'prefs' GUI_PREFS = '../conf/gui.prefs' def __init__(self): ''' Constructor ''' self.dvalue = None self.dselect = 'dest' #v:x111|MYGROUP, myconf.conf, 2193, 2013-01-01, 2013-01-02 self.plist = ('lgvalue','uconf','epsg','fd','td') self.cp = ConfigParser() self.fn = os.path.join(os.path.dirname(__file__),self.GUI_PREFS) with codecs.open(self.fn,'r','utf-8') as cf: self.cp.readfp(cf) def read(self): '''Read stored DS value and return this and its matching params''' try: with codecs.open(self.fn, 'r','utf-8') as cf: self.cp.readfp(cf) self.dvalue = self.cp.get(self.PREFS_SEC, self.dselect) if LU.assessNone(self.dvalue) is None: return (None,)*(len(self.plist)+1) except NoSectionError as nse: #if no sec init sec and opt and ret nones ldslog.warn('Error getting GUI prefs section :: '+str(nse)) if not self._initSection(self.PREFS_SEC): raise self._initOption(self.PREFS_SEC,self.dselect) return (None,)*(len(self.plist)+1) except NoOptionError as noe: #if no opt init opt and ret nones ldslog.warn('Error getting GUI prefs :: '+str(noe)) if not self._initOption(self.PREFS_SEC,self.dselect): raise return (None,)*(len(self.plist)+1) #if dval is okay ret it and res of a read of that sec return (self.dvalue,)+self.readsec(self.dvalue) def readall(self): '''Reads entire grp into dict''' gpra = {} secs = self.cp.sections() secs.remove(self.PREFS_SEC) for sec in secs: gpra[sec] = self.readsec(sec) return gpra def getDestinations(self): return self.cp.sections() def readsec(self,section): #options per DS type rlist = () for p in self.plist: try: rlist += (self.cp.get(section, p),) except NoSectionError as nse: #if not ds sec init sec then init opt ldslog.warn('Error getting GUI '+section+' :: '+str(nse)) if not self._initSection(section): raise self._initOption(section, p) rlist += (None,) except NoOptionError as noe: #if no opt init the opt ldslog.warn('Error getting GUI '+section+' pref, '+p+' :: '+str(noe)) if not self._initOption(section,p): raise rlist += (None,) return rlist def writeline(self,field,value): #not the best solution since depends on a current gpr and a recent read/write. if self.dvalue: self.writesecline(self.dvalue,field,value) def writesecline(self,section,field,value): try: self.cp.set(section,field,value if LU.assessNone(value) else '') with codecs.open(self.fn, 'w','utf-8') as configfile: self.cp.write(configfile) ldslog.debug(str(section)+':'+str(field)+'='+str(value)) except Exception as e: ldslog.warn('Problem writing GUI prefs. {} - sfv={}'.format(e,(section,field,value))) def write(self,rlist): self.dvalue = rlist[0] if self.cp.has_section(self.PREFS_SEC): self.cp.set(self.PREFS_SEC,self.dselect,self.dvalue) else: self.cp.add_section(self.PREFS_SEC) self.cp.set(self.PREFS_SEC,self.dselect,self.dvalue) for pr in zip(self.plist,rlist[1:]): if not self.cp.has_section(self.dvalue): self.cp.add_section(self.dvalue) try: if LU.assessNone(pr[1]): self.cp.set(self.dvalue,pr[0],pr[1]) ldslog.debug(self.dvalue+':'+pr[0]+'='+pr[1]) except Exception as e: ldslog.warn('Problem writing GUI prefs. '+str(e)) with codecs.open(self.fn, 'w','utf-8') as configfile: self.cp.write(configfile) def _initSection(self,section): checksec = LU.standardiseDriverNames(section) if checksec: self.cp.add_section(checksec) return True elif section == self.PREFS_SEC: self.cp.add_section(section) return True return False def _initOption(self,section,option): if option in self.plist+(self.dselect,): self.writesecline(section,option,None) return True return False @classmethod def validate(): '''Make sure a guipref file is valid, check pref points to alt least one valid DST''' filename = os.path.join(os.path.dirname(__file__),GUIPrefsReader.GUI_PREFS) gp = GUIPrefsReader(filename) #validate UC check it has a valid dest named and configured p = gp.cp.get('prefs', 'dest') return gp.cp.has_section(p)