def processargs(self): if self.kwargs.has_key("config"): self.config = self.kwargs["config"] else: self.config = spiderClasses.Config() self.LocalConfigFilename = None self.pathVar = StringVar() if self.config != None: self.dialoglist = [] self.dirlist = [] else: self.config = spiderClasses.Config() self.dirCancel = 0
def form2config(self): " get values from form, put in a Config object " C = spiderClasses.Config() C.Title = self.title.getvalue() C.Image = self.image.getvalue() C.helpurl = self.helpurl.getvalue() C.path = [self.pathVar.get()] C.Dialogs = self.config.Dialogs C.Dirs = self.config.Dirs return C
def mkconfig(src, ftypes, xmlout): " make a Spire config (not an xml config) " if not os.path.exists(src): displayError("Unable to find %s" % src) return if type(ftypes) != type(["list"]): ftypes = [ftypes] GB.outstream("Reading files and directories under %s" % src) C = spiderClasses.Config() # make a new instance C.path = [src] dlist = read_dirtree(src, ftypes) C.Dirs = dlist[1] print "back from readdirtree. dlist:" print dlist # dlist: ['prj', [ file, file, [dir], [dir], ...] # each of the 1st level dirs under the project dir # has its own dialog olddir = os.getcwd() dlist[0] = '.' # top-level project directory is generic, can have any name projectdir = dlist[0] print "projectdir: %s" % projectdir #if not chdir(projectdir): #return filelist = dlist[1] dialoglist = [] for item in filelist: if type(item) == type(["list"]): dirname = item[0] dirlist = item[1] if not chdir(dirname): print "can't change to %s" % dirname continue dialoglist.append(dirname) ddgg = dir2dialog(item) print "dialog" print ddgg C.Dialogs[item[0]] = ddgg chdir("..") C.Dialogs['dialogList'] = dialoglist # set the new config as the project config if hasProject(): GB.C = C # save it as xml file if xmlout != "": C.save2xml(xmlout) #saveXMLConfig(file=xmlout, config=C) chdir(olddir)
def readXMLConfig(XMLfile=None, setproject=1): """ read a spire XML configuration file: returns a Config object """ if XMLfile == None or not os.path.exists(XMLfile): if os.path.exists(GG.sysprefs.configFile): XMLfile = GG.sysprefs.configFile else: XMLfile = defaultConfig if XMLfile == None or XMLfile == "": GB.errstream( "spiderConfig.readXMLConfig: unable to locate a valid config file." ) return try: dom = xml.dom.minidom.parse(XMLfile) except: GB.errstream("spiderConfig.readXMLConfig: unable to parse %s" % (XMLfile)) displayError("unable to parse %s" % (XMLfile)) return 0 C = spiderClasses.Config() # create an empty instance of Config title, image, helpurl, parms, database = getMainParameters(dom) if title != "": C.Title = title if image != "": C.Image = image if helpurl != "": C.helpurl = helpurl #helpurl = str(helpurl) #if helpurl != "": # GG.HelpURL = helpurl # GG.sysprefs.helpURL = helpurl C.useParameterFile = parms C.useDatabase = database C.path = getLocations(dom, XMLfile) C.Dialogs = getDialogs(dom) C.Dirs = getDirectories(dom) # see if config has optional <Parameters> tag p = getParameters(dom) if len(p) > 0: C.parms = p # a list of [key value comment] lists # <Parameters> are just default settings for a new project, # they are saved in params file, not in Configuration. dom.unlink() # free up the memory if len(C.path) > 0 and len(C.Dialogs) > 0 and len(C.Dirs) > 0: if setproject: GB.C = C GB.outstream("configuration loaded from %s" % XMLfile) updateMainMenus() if hasProject(): saveConfig() return C else: GB.outstream("No configuration loaded: required xml tags are empty") if not C.path: GB.outstream("Unable to parse <Locations>") elif not C.Dialogs: GB.outstream("Unable to parse <Dialogs>") elif not C.Dirs: GB.outstream("Unable to parse <Directories>") return 0
def newconfig(self): self.config = spiderClasses.Config() self.config.Title = "" self.config.Image = "" self.config.path = [""] self.setValues()