From: <ror...@us...> - 2007-07-23 10:31:04
|
Revision: 113 http://roreditor.svn.sourceforge.net/roreditor/?rev=113&view=rev Author: rorthomas Date: 2007-07-23 03:31:00 -0700 (Mon, 23 Jul 2007) Log Message: ----------- * improved UnZIP * added 'n' option to truckparser.py * improved ror_mesh with timeout for waiting on ogrexmlconverter * installmod now callable from outside * checkmods commands added to automate the installmod command for all the files in it Modified Paths: -------------- trunk/installmod.py trunk/lib/UnZIP/__init__.py trunk/lib/ror/depchecker.py trunk/lib/ror/depcheckerplugins/ror_mesh.py trunk/lib/ror/truckparser.py Added Paths: ----------- trunk/checkmods.bat trunk/checkmods.py Added: trunk/checkmods.bat =================================================================== --- trunk/checkmods.bat (rev 0) +++ trunk/checkmods.bat 2007-07-23 10:31:00 UTC (rev 113) @@ -0,0 +1 @@ +%systemdrive%\python25\python.exe checkmods.py %1 %2 %3 %4 %5 %6 %7 %8 %9 Added: trunk/checkmods.py =================================================================== --- trunk/checkmods.py (rev 0) +++ trunk/checkmods.py 2007-07-23 10:31:00 UTC (rev 113) @@ -0,0 +1,43 @@ +import os.path, sys, installmod, time + + +def getFiles(top): + fl = {} + for root, dirs, files in os.walk(top): + for f in files: + fn = os.path.join(root, f) + fl[fn] = {} + for fk in fl.keys(): + print "%10s %s" % ("", os.path.basename(fk)) + + print "found %d files!" % (len(fl.keys())) + return fl + +def main(): + dir = sys.argv[1] + mode = sys.argv[2] + files = getFiles(dir) + valid={} + counter = 0 + countervalid = 0 + for file in files.keys(): + print "## %s (%d/%d)##############################################" % (os.path.basename(file), counter, len(files)) + counter += 1 + mods = installmod.work(mode, file, True, False) + if len(mods) == 0: + print "!!! INVALID: ", os.path.basename(file) + else: + print "VALID: ", os.path.basename(file) + valid[file] = mods + print "#######################################################################" + time.sleep(0.01) + print "################################################" + print "################################################" + print "################################################" + for f in valid.keys(): + print f, valid[f] + print "%d of %d files containing valid mods!" % (len(valid), len(files)) + + +if __name__=="__main__": + main() \ No newline at end of file Modified: trunk/installmod.py =================================================================== --- trunk/installmod.py 2007-07-23 08:40:03 UTC (rev 112) +++ trunk/installmod.py 2007-07-23 10:31:00 UTC (rev 113) @@ -11,6 +11,7 @@ if os.path.isdir(TEMPDIR): try: shutil.rmtree(TEMPDIR) + #os.rmdir(TEMPDIR) except Exception, err: if not reporterrors: return @@ -20,14 +21,18 @@ def ExtractToTemp(filename): file, extension = os.path.splitext(filename) - removetemp() + removetemp(False) + os.mkdir(TEMPDIR) if extension.lower() == ".rar": import UnRAR - os.mkdir(TEMPDIR) dst = os.path.join(TEMPDIR, os.path.basename(filename)) shutil.copyfile(filename, dst) os.chdir(TEMPDIR) - UnRAR.Archive(os.path.basename(filename)).extract() + UnRAR.Archive(os.path.basename(filename)).extract() + + # remove .rar file instantly + os.unlink(os.path.join(TEMPDIR, os.path.basename(filename))) + # change back to current path os.chdir(os.path.dirname(os.path.abspath(__file__))) return True @@ -36,7 +41,8 @@ UnZIP.unzip(filename, TEMPDIR) return True else: - shutil.copyfile(filename, dst) + print filename, " to ", os.path.join(TEMPDIR, os.path.basename(filename)) + shutil.copyfile(filename, os.path.join(TEMPDIR, os.path.basename(filename))) return False def installfile(maintarget, srcfile, dryrun): @@ -81,7 +87,7 @@ def getTargets(verbose): import ror.depchecker - dc = ror.depchecker.RoRDepChecker(TEMPDIR, "getfiles", "", verbose) + dc = ror.depchecker.RoRDepChecker(TEMPDIR, "getfiles", "", False) targets = [] for file in dc.files: filename, extension = os.path.splitext(file) @@ -98,52 +104,14 @@ invalidtargets.append(target) return validtargets, invalidtargets - -def main(): - if len(sys.argv) < 3: - usage() - - targetfile = sys.argv[1] - if not os.path.isfile(targetfile): - log().error("%s is not a valid target filename!" % targetfile) - usage() - mode = sys.argv[2] - if not mode in ['list', 'listall', 'install', 'installall']: - usage() - if len(sys.argv) < 4 and mode in ['install']: - usage() - - # get optional flags - verbose = False - dryrun = False - for option in sys.argv: - if option == "--verbose": - verbose = True - if option == "--dryrun": - dryrun = True - - - import ror.settingsManager - path = ror.settingsManager.getSettingsManager().getSetting("RigsOfRods", "BasePath") - if not os.path.isfile(os.path.join(path,"RoR.exe")): - import ror.starter - ror.starter.startApp() - - # Import Psyco if available - try: - import psyco - psyco.full() - except ImportError: - pass - +def work(mode, targetfile, verbose, dryrun, installtarget=None): filename = os.path.abspath(targetfile) - ExtractToTemp(filename) - + ExtractToTemp(targetfile) if mode == "install": - target = sys.argv[3] + target = installtarget + log().info("### validating target ...") import ror.depchecker - log().info("### validating target ...") dc = ror.depchecker.RoRDepChecker(TEMPDIR, "dtree", target, verbose) if dc.invalid: log().error("### target invalid!") @@ -165,14 +133,20 @@ log().info("### would install %d files." % installcounter) else: log().info("### %d files installed, finished!" % installcounter) - + removetemp(False) + return [target] + elif mode == "installall": validtargets, invalidtargets = getTargets(verbose) log().info("### installing %d found modifications:" % (len(validtargets))) installcounter = 0 for target in validtargets: log().info("### installing modification '%s'" % target) + import ror.depchecker dc = ror.depchecker.RoRDepChecker(TEMPDIR, "dtree", target, verbose) + if dc.dstree is None: + log().error("no dependenytree for File %s!" % (filename)) + continue for file in dc.dstree: filename = file['filename'] filenamefound = searchFile(filename, TEMPDIR) @@ -185,26 +159,74 @@ log().info("### would install %d files." % installcounter) else: log().info("### %d files installed, finished!" % installcounter) - + removetemp(False) + return validtargets elif mode in ["list", "listall"]: validtargets, invalidtargets = getTargets(verbose) if mode == "listall": if len(invalidtargets) > 0: - print "broken modifications found:" + log().info("broken modifications found:") for v in invalidtargets: - print " %-20s" % v - print "use the --verbose flag to find the missing files!" + log().info(" %-20s" % v) + log().info("use the --verbose flag to find the missing files!") else: - print "no broken modifications found:" + log().info("no broken modifications found") if len(validtargets) > 0: - print "installable modifications found: " + log().info("installable modifications found:") for v in validtargets: - print " %-20s" % v + log().info(" %-20s" % v) else: - print "no installable modifications found! :(" - removetemp(False) + log().info("no installable modifications found! :(") + # todo : remove workaround! + removetemp(False) + return validtargets + return None + +def main(): + if len(sys.argv) < 3: + usage() + targetfile = sys.argv[1] + if not os.path.isfile(targetfile): + log().error("%s is not a valid target filename!" % targetfile) + usage() + mode = sys.argv[2] + if not mode in ['list', 'listall', 'install', 'installall']: + usage() + if len(sys.argv) < 4 and mode in ['install']: + usage() + + # get optional flags + verbose = False + dryrun = False + for option in sys.argv: + if option == "--verbose": + verbose = True + if option == "--dryrun": + dryrun = True + + import ror.settingsManager + path = ror.settingsManager.getSettingsManager().getSetting("RigsOfRods", "BasePath") + if not os.path.isfile(os.path.join(path,"RoR.exe")): + import ror.starter + ror.starter.startApp() + + # Import Psyco if available + try: + import psyco + psyco.full() + except ImportError: + pass + + if len(sys.argv) == 4: + installtarget = sys.argv[3] + else: + installtarget = None + work(mode, targetfile, verbose, dryrun, installtarget) + + + if __name__=="__main__": main() \ No newline at end of file Modified: trunk/lib/UnZIP/__init__.py =================================================================== --- trunk/lib/UnZIP/__init__.py 2007-07-23 08:40:03 UTC (rev 112) +++ trunk/lib/UnZIP/__init__.py 2007-07-23 10:31:00 UTC (rev 113) @@ -1,12 +1,27 @@ import sys, zipfile, os, os.path def unzip(file, dir): - os.mkdir(dir) - zfobj = zipfile.ZipFile(file) - for name in zfobj.namelist(): - if name.endswith('/'): - os.mkdir(os.path.join(dir, name)) - else: - outfile = open(os.path.join(dir, name), 'wb') - outfile.write(zfobj.read(name)) - outfile.close() + try: + os.mkdir(dir) + except: + pass + try: + zfobj = zipfile.ZipFile(file) + for name in zfobj.namelist(): + if name.endswith('/'): + os.mkdir(os.path.join(dir, name)) + else: + dirnow = dir + dirnow = dirnow.replace("/", "\\") + subdirs = name.split("/") + if len(subdirs) > 0: + for subdir in subdirs: + dirnow = os.path.join(dirnow, subdir) + if not os.path.isdir(os.path.dirname(dirnow)): + os.mkdir(os.path.dirname(dirnow)) + outfile = open(dirnow, 'wb') + outfile.write(zfobj.read(name)) + outfile.close() + except Exception, err: + print str(err) + return \ No newline at end of file Modified: trunk/lib/ror/depchecker.py =================================================================== --- trunk/lib/ror/depchecker.py 2007-07-23 08:40:03 UTC (rev 112) +++ trunk/lib/ror/depchecker.py 2007-07-23 10:31:00 UTC (rev 113) @@ -359,7 +359,7 @@ fl[fn]['md5'] = self.md5Sum(fn) if self.verbose: for fk in fl.keys(): - infostr = "%10s %s" % ("", fk) + infostr = "%10s %s" % ("", os.path.basename(fk)) log().info(infostr) log().info("found %d files!" % (len(fl.keys()))) self.files = fl Modified: trunk/lib/ror/depcheckerplugins/ror_mesh.py =================================================================== --- trunk/lib/ror/depcheckerplugins/ror_mesh.py 2007-07-23 08:40:03 UTC (rev 112) +++ trunk/lib/ror/depcheckerplugins/ror_mesh.py 2007-07-23 10:31:00 UTC (rev 113) @@ -1,5 +1,5 @@ import sys, os, os.path, re -import subprocess +import subprocess,os,sys,signal,pty,time,errno,thread from deptools import * @@ -19,12 +19,58 @@ print "calling " + cmd p = subprocess.Popen(cmd, shell = False, cwd = os.path.dirname(CONVERTERBIN), stderr = subprocess.PIPE, stdout = subprocess.PIPE) - p.wait() + smart_wait_for_subprocess(p, 10) if not os.path.isfile(os.path.join(os.path.dirname(filename), os.path.basename(filename)+".xml")): print "conversion of mesh file %s failed!" % filename print "mesh converted: " + filename +def smart_wait_for_subprocess(sp,timeout=30): + """ + Will wait for Process given to expire, and then kill it if + the time elapses (or never if timeout==0). + @param sp: Subprocess to watch + @param timeout: timeout length in seconds + """ + running=1 + try: + sleeps=timeout*4 + #Just wait around for termination... + + while sp.poll()==None: + #print>>efp,"WAITING:",sleeps + sleeps-=1 + time.sleep(.25) + os.kill(sp.pid,0) + if sleeps<=0 and timeout>0: + os.kill(sp.pid,signal.SIGTERM) + break + elif sleeps<=0: + break + #Did it REALLY exit? + try: + os.kill(sp.pid,0) + sleeps=20 + while sp.poll()==None: + #print>>efp,"KILLING:",sleeps + sleeps-=1 + time.sleep(.25) + + #No? KILL IT! + if sleeps<=0 and timeout>0: + #print>>efp,"KILLING2:",sleeps + os.kill(sp.pid,signal.SIGKILL) + break + elif sleeps<=0: + break + except: + running=0 + except: + #Make REALLY effing sure it exited. + os.kill(sp.pid,signal.SIGKILL) + #print>>efp,"KILLING2:",sleeps + + def parseRE(content): deps = [] for line in content: Modified: trunk/lib/ror/truckparser.py =================================================================== --- trunk/lib/ror/truckparser.py 2007-07-23 08:40:03 UTC (rev 112) +++ trunk/lib/ror/truckparser.py 2007-07-23 10:31:00 UTC (rev 113) @@ -169,8 +169,9 @@ {'name':'second node', 'type':'node'}, {'name':'options', 'type':'string', 'required':False, - 'default':None, + 'default':'n', 'validvalues':[ + 'n', # visible, default 'v', # visible, default 'i', # this beam is invisible. Very usefull to hide "cheating" structural beam, or to improve performances once the truck is textured. 'r', # this beam is a rope (opposes no force to compression) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |