def CheckSyntax(self): # first, verify the correctness of our mdb syntax file. sc = pyini.IniSyntaxChecker(self.DescriptionSyntaxFile, self.SyntaxFile) sc.SyntaxCheck() # now verify the correctness of our passed in mdb database self.MachineParser = pyini.IniParser() for ff in os.listdir(self.mdbDirectory): if not(ff.endswith(".ini")): continue filePath = simlib.BuildPath(simenv.MDB_PATH, ff) self.MachineParser.UpdateFromIni(filePath, True) # load the cdb database, which at the moment has no syntax file and convert any blocks to lists self.ConfigParser = pyini.IniParser(self.cdbFilename) self.ConvertBlocks() if self.udbFilename != None: # import new sections to the machine database, but not the config database. self.MachineParser.UpdateFromIni(self.udbFilename, True) self.ConfigParser.UpdateFromIni(self.udbFilename) syntaxChecker = pyini.IniSyntaxChecker(self.SyntaxFile, self.MachineParser, True) syntaxChecker.SyntaxCheck() self.MachineParser.UpdateFromDict(simenv.OptionsManager.MDBKeys)
def command_table(cmds): table = [] for cmd in cmds: binary = sim.known_commands[cmd] if sys.modules[binary].usage_strings.has_key(cmd): usage = sys.modules[binary].usage_strings[cmd] else: usage = "" table.append([":doc:`/_auto/commands/" + cmd + "`", usage]) f = open("_auto/commands/%s.rst" % cmd, "w") print >> f, ".. _command_" + cmd + ":" print >> f print >> f, cmd print >> f, "================================================" print >> f print >> f, "*" + usage + "*" print >> f if simenv.CommandDoc.has_key(cmd): print >> f, simenv.CommandDoc[cmd] if simenv.CommandOptions.has_key(cmd): print >> f, "Options" print >> f, "-------" # print >>f, ".. list-table::" # print >>f, "" opts_p = simenv.CommandOptions[cmd] if type(opts_p) == list: opts = opts_p elif type(opts_p) == str: opts = pyini.IniParser("../../etc/options/" + opts_p).GetSections() else: print "Command options for %s of bad type %s" % ( cmd, str(type(opts_p))) sys.exit(1) print >> f, ".. program:: sim %s" % cmd print >> f for opt in opts: s = ini.GetSectionAsDict(opt) # print >>f, " * - "+s["long"].value # print >>f, " - "+s["desc"].value print >> f, ".. cmdoption:: %s" % (s["long"].value), if "argformat" in s: print >> f, s["argformat"].value else: print >> f print >> f print >> f, " %s" % s["desc"].value print >> f f.close return table
def ini_initializeDestination(self, value): fullPath = simlib.BuildPath(simenv.BASE_PATH, value) self.ini_FullPath = fullPath if self.ParentTree != None: if self.ParentTree.DestType == 'ini': if self.ParentTree.ini_FullPath == self.ini_FullPath: self.ini_DestParser = self.ParentTree.ini_DestParser return self.ini_DestParser = pyini.IniParser(self.ini_FullPath)
def Discovery(self): try: os.stat(self.optionDirectory) except OSError: fatal( "while attempting to read option dir, could not open %s for reading" % self.optionDirectory) files = os.listdir(self.optionDirectory) for f in files: if f.endswith(".ini"): parts = os.path.splitext(f) basename = parts[0] full_path = "%s/%s" % (self.optionDirectory, f) self.parsers[basename] = pyini.IniParser(full_path)
def setupTree(self, tree=None): if tree != None: self.IniTree = tree if self.IniTree == None: fatal("no decision tree defined.") fullFile = simlib.BuildPath(simenv.LIB_PATH, "dt", "%s.ini" % self.IniTree) if not (os.path.exists(fullFile)): fatal("could not open decision tree %s for reading." % fullFile) info("decision tree ini: %s" % fullFile) self.Parser = pyini.IniParser(fullFile) self.loadConfiguration()
def init(self, filename): importExisting = True self.Filename = filename if not (os.path.exists(filename)): importExisting = False self.parser = pyini.IniParser(self.Filename) if importExisting: ret = self.ImportProperties() if ret < 0: warning("Importing properties from %s failed." % self.Filename) if self.BaseProperties != None: for key in self.BaseProperties.keys(): self.AddProperty(key, self.BaseProperties[key])
def macro_CREATE_MACHINE(self): mm = self.DefineDatabase.Get('machine') srcPath = simlib.BuildPath(simenv.MDB_PATH, 'generic.ini') dstPath = simlib.BuildPath(simenv.MDB_PATH, '%s.ini' % mm) shutil.copy(srcPath, dstPath) self.tParser = pyini.IniParser(dstPath) self.tParser.parser.RenameSection('generic', mm) options = ['name', 'hostname', 'nickname'] for oo in options: io = self.tParser.GetOption(mm, oo) io.Value = io.value = mm self.tParser.parser.WriteKey(mm, oo, io) # sourcebasedir io = self.tParser.GetOption(mm, "sourcebasedir") sourcebasedir = self.macro_GET_SOURCEBASEDIR() io.Value = sourcebasedir self.tParser.parser.WriteKey(mm, "sourcebasedir", io) # basedir io = self.tParser.GetOption(mm, "basedir") io.Value = self.macro_GET_BASEDIR() self.tParser.parser.WriteKey(mm, "basedir", io) # optionlist if (simenv.OptionsManager.RawOptionDefined("optionlist")): io = self.tParser.GetOption(mm, "optionlist") io.Value = simlib.GetOptionList(False) self.tParser.parser.WriteKey(mm, "optionlist", io) # submitscript if (simenv.OptionsManager.RawOptionDefined("submitscript")): io = self.tParser.GetOption(mm, "submitscript") io.Value = simlib.GetSubmitScript(False) self.tParser.parser.WriteKey(mm, "submitscript", io) # runscript if (simenv.OptionsManager.RawOptionDefined("runscript")): io = self.tParser.GetOption(mm, "runscript") io.Value = simlib.GetRunScript(False) self.tParser.parser.WriteKey(mm, "runscript", io) # ppn if (simenv.OptionsManager.RawOptionDefined("ppn")): io = self.tParser.GetOption(mm, "ppn") io.Value = simenv.OptionsManager.GetOption('ppn') self.tParser.parser.WriteKey(mm, "ppn", io) # also set 'max-num-threads' io = self.tParser.GetOption(mm, "max-num-threads") io.Value = simenv.OptionsManager.GetOption('ppn') self.tParser.parser.WriteKey(mm, "max-num-threads", io) # also enable parallel make io = self.tParser.GetOption(mm, "make") io.Value = "nice make -j%d" % simenv.OptionsManager.GetOption( 'ppn') self.tParser.parser.WriteKey(mm, "make", io) # num-threads if (simenv.OptionsManager.RawOptionDefined("num-threads")): io = self.tParser.GetOption(mm, "num-threads") io.Value = simenv.OptionsManager.GetOption('num-threads') self.tParser.parser.WriteKey(mm, "num-threads", io) simlib.WriteContents(dstPath, self.tParser.GetIniAsString()) return "machine %s [%s] created successfully" % (mm, dstPath)
def InitBlank(self): self.parser = pyini.IniParser()
#!/usr/bin/env python import sim import simenv import sys import pyini ini = pyini.IniParser("../../etc/options/common.ini") essential_options = ["remote"] essential_options.sort() options = filter(lambda c: c not in essential_options, list(ini.GetSections())) options.sort() o = open("_auto/options/common-essential.txt", "w") #print >>o, ".. list-table::" #print >>o, "" for section in essential_options: s = ini.GetSectionAsDict(section) # print >>o, " * - "+s["long"].value # print >>o, " - "+s["desc"].value print >> o, ".. cmdoption:: %s" % (s["long"].value), if "argformat" in s: print >> o, s["argformat"].value else: print >> o print >> o print >> o, " %s" % s["desc"].value print >> o
sep += ("+" + "-" * (lengths[j] + 2)) sep += "+\n" s += sep for i in range(0, len(t)): for j in range(0, len(t[i])): s += "|" s += " " + t[i][j].ljust(lengths[j]) + " " s += "|\n" s += sep return s ini = pyini.IniParser() for f in os.listdir("../../etc/options"): if f != ".svn": ini.UpdateFromIni("../../etc/options/" + f, True) essential_commands = [ "build", "create", "submit", "create-submit", "purge", "setup", "stop", "sync" ] essential_commands.sort() cmds = filter(lambda c: c not in essential_commands, list(sim.known_commands)) cmds.sort()