|
From: <mk...@us...> - 2003-03-18 10:04:17
|
Update of /cvsroot/csp/APPLICATIONS/SimData/Tools/DataCompiler In directory sc8-pr-cvs1:/tmp/cvs-serv11687/Tools/DataCompiler Modified Files: Compile.py Parse.py make_simdar Log Message: see CHANGES.current Index: Compile.py =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Tools/DataCompiler/Compile.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Compile.py 10 Feb 2003 05:11:44 -0000 1.3 --- Compile.py 18 Mar 2003 10:04:06 -0000 1.4 *************** *** 37,40 **** --- 37,41 ---- print "http://csp.sourcforge.net/forum" sys.exit(1) + SimData.log().setLogLevels(SimData.LOG_ALL, SimData.LOG_ALERT) original_path = sys.path[:] new_path = "" *************** *** 75,79 **** --- 76,124 ---- import os.path, time + class Cache: + def __init__(self, fn): + self.timestamp = None + self.source = None + if os.path.exists(fn): + try: + # open archive for reading, but disable chaining + self.source = DataArchive(fn, 1, 0) + self.timestamp = os.path.getmtime(fn) + except: + self.source = None + self.timestamp = None + + def close(self): + self.source = None + + def getObject(self, id): + if self.source is not None: + try: + return self.source.getObject(id) + except: + pass + return None + def isNewer(self, fn): + if self.timestamp is None: + return 1 + try: + mtime = os.path.getmtime(fn) + except: + return 1 + return mtime > self.timestamp + + + class CompilerUsageError: + def __init__(self, msg=None): + self.msg = msg + def getMessage(self): + if self.msg is None: + return "Usage error" + return "Usage error: %s\n" % self.msg + def __repr__(self): + return self.getMessage() + + class Compiler: *************** *** 81,93 **** print print "Compiling '%s' from '%s'" % (self.outfile, self.infile) ! print "Opening output archive" ! compiled = DataArchive(self.outfile, 0) ! print "Opening input archive" master = ObjectXMLArchive(self.infile); ! print "Loading all objects" resetWarnings() all = master.loadAll() warnings, level = getWarnings() ! print "XML parse completed." if warnings > 0: print "%d warnings (severity=%d)." % (warnings, level) --- 126,141 ---- print print "Compiling '%s' from '%s'" % (self.outfile, self.infile) ! DEBUG(1, "Opening input archive") master = ObjectXMLArchive(self.infile); ! DEBUG(1, "Loading all objects") resetWarnings() + if not self.rebuild: + cache = Cache(self.outfile) + master.setCache(cache) all = master.loadAll() + if not self.rebuild: + cache.close() warnings, level = getWarnings() ! DEBUG(1, "XML parse completed.") if warnings > 0: print "%d warnings (severity=%d)." % (warnings, level) *************** *** 97,104 **** sys.exit(1) paths = master.getPaths() ! print "Compiling all objects" for id in all.keys(): object = all[id] DEBUG(2, "Compiling object '%s' [%s] %s" % (id, hash_string(id), str(object))) compiled.addObject(object, id) self.dumpBadPaths(all, paths) --- 145,159 ---- sys.exit(1) paths = master.getPaths() ! DEBUG(1,"Compiling all objects") ! compiled = DataArchive(self.outfile, 0) for id in all.keys(): object = all[id] DEBUG(2, "Compiling object '%s' [%s] %s" % (id, hash_string(id), str(object))) + # objects cached from the original archive are Pointers, so we need to + # dereference them. this should be cleaned up a bit. + try: + object = object.__get__() + except: + pass compiled.addObject(object, id) self.dumpBadPaths(all, paths) *************** *** 119,143 **** print def usage(self, msg=None): ! print ! if msg is not None: ! print "Usage error:", msg ! print "SimData XML Compiler" ! print self._name, "[--warn=level] [--debug=level] sourcepath output" ! sys.exit(1) ! def parse(self, args): args = args[1:] for arg in args: if arg.startswith('--'): try: if arg.startswith('--warn='): ! setWarningLevel(int(arg[7:])) elif arg.startswith('--debug='): ! setDebugLevel(int(arg[8:])) else: ! self.usage("unknown option '%s'" % arg) except: ! self.usage("invalid option '%s'" % arg) else: if self.infile is None: --- 174,222 ---- print + def printUsage(self, out=sys.stdout): + print >>out, "SimData XML Compiler" + if self.standalone: + print >>out, self._name, "[--warn=level] [--debug=level] [--rebuild] sourcepath output" + else: + print >>out, "" + print >>out, " Options:" + print >>out, " --warn=level show warning message (< level)" + print >>out, " --debug=level show debug messages (< level)" + print >>out, " --rebuild rebuild entire archive" + def usage(self, msg=None): ! if self.standalone: ! if msg is not None: ! print "Usage error:", msg ! self.printUsage() ! sys.exit(1) ! else: ! raise CompilerUsageError(msg) ! def parse(self, args): + self._name = args[0] args = args[1:] for arg in args: if arg.startswith('--'): try: + unknown = 0 if arg.startswith('--warn='): ! level = int(arg[7:]) ! setWarningLevel(level) ! if level > 0: ! SimData.log().setLogLevels(SimData.LOG_ALL, SimData.LOG_WARN) elif arg.startswith('--debug='): ! level = int(arg[8:]) ! setDebugLevel(level) ! if level > 0: ! SimData.log().setLogLevels(SimData.LOG_ALL, SimData.LOG_DEBUG) ! elif arg == '--rebuild': ! self.rebuild = 1 else: ! unknown = 1 except: ! self.usage("invalid option '%s'" % arg) ! if unknown: ! self.usage("unknown option '%s'" % arg) else: if self.infile is None: *************** *** 150,163 **** self.usage() ! def __init__(self, args): setWarningLevel(1) self.infile = None self.outfile = None ! self._name = args[0] ! self.parse(args) ! self.compileAll() if __name__ == "__main__": ! import profile ! profile.run('Compiler(sys.argv)', 'profile.out') --- 229,243 ---- self.usage() ! def __init__(self, standalone=0): setWarningLevel(1) + self.rebuild = 0 self.infile = None self.outfile = None ! self._name = "" ! self.standalone = standalone if __name__ == "__main__": ! c = Compiler(1) ! c.parse(sys.argv) ! c.compileAll() Index: Parse.py =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Tools/DataCompiler/Parse.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Parse.py 10 Feb 2003 05:11:44 -0000 1.3 --- Parse.py 18 Mar 2003 10:04:06 -0000 1.4 *************** *** 385,389 **** def getElement(self): ! p = SimData.PathPointer() p.setPath(self._element.encode('ascii')) return p --- 385,389 ---- def getElement(self): ! p = SimData.PointerBase() p.setPath(self._element.encode('ascii')) return p *************** *** 585,594 **** print " ", "\n ".join(interface_names) raise NameError, msg ! try: obj = self._interface.createObject() ! except: ! print "ERROR Creating class", self._class ! msg = "ERROR Creating class %s" % self._class ! raise msg self._object = obj self._assigned = {} --- 585,597 ---- print " ", "\n ".join(interface_names) raise NameError, msg ! if getDebugLevel() > 0: obj = self._interface.createObject() ! else: ! try: ! obj = self._interface.createObject() ! except: ! print "ERROR Creating class", self._class ! msg = "ERROR Creating class %s" % self._class ! raise msg self._object = obj self._assigned = {} *************** *** 604,607 **** --- 607,611 ---- self._assigned[name] = 1 self._handler.assign(self._interface, self._object, name) + #print name, self._handler.getElement() self.checkName(name) *************** *** 646,649 **** --- 650,654 ---- self._paths = {} self._externals = {} + self._cache = None def getObject(self, id): *************** *** 664,667 **** --- 669,676 ---- if not os.path.exists(path): raise IOError, "Unable to find data for %s" % id + if self._cache and not self._cache.isNewer(path): + obj = self._cache.getObject(id) + if obj is not None: + return obj if path.endswith('.gz'): f = GzipFile(path, "rb") *************** *** 710,713 **** --- 719,725 ---- def getExternals(self): return self._externals + + def setCache(self, cache): + self._cache = cache def loadAll(self, path = ""): Index: make_simdar =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/SimData/Tools/DataCompiler/make_simdar,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** make_simdar 28 Jan 2003 23:26:09 -0000 1.2 --- make_simdar 18 Mar 2003 10:04:06 -0000 1.3 *************** *** 1 **** ! ./Compile.py ../../../CSPSim/Data/XML ../../../CSPSim/Data/Sim.dar --- 1 ---- ! ./Compile.py $* ../../../CSPSim/Data/XML ../../../CSPSim/Data/Sim.dar |