# HG changeset patch # User Matthew Turk # Date 1188162536 25200 # Branch trunk # Node ID 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b # Parent 965aeb33157cb092f6c567d70cd03b33cac03d9a [svn r239] Changed the symlinks to be actual symlinks in SVN. Branching, Importing, DigUpping, Burying all work. Next up is a proper fido standalone. diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b scripts/basic.py --- a/scripts/basic.py Sat Aug 25 22:06:06 2007 -0700 +++ b/scripts/basic.py Sun Aug 26 14:08:56 2007 -0700 @@ -1,4 +1,4 @@ #!python2.5 import yt.fido -yt.fido.run() +yt.fido.runAction() diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b scripts/fbranch --- a/scripts/fbranch Sat Aug 25 22:06:06 2007 -0700 +++ b/scripts/fbranch Sun Aug 26 14:08:56 2007 -0700 @@ -1,4 +1,1 @@ -#!python2.5 -import yt.fido - -yt.fido.run() +basic.py \ No newline at end of file diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b scripts/fbury --- a/scripts/fbury Sat Aug 25 22:06:06 2007 -0700 +++ b/scripts/fbury Sun Aug 26 14:08:56 2007 -0700 @@ -1,4 +1,1 @@ -#!python2.5 -import yt.fido - -yt.fido.run() +basic.py \ No newline at end of file diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b scripts/fdigup --- a/scripts/fdigup Sat Aug 25 22:06:06 2007 -0700 +++ b/scripts/fdigup Sun Aug 26 14:08:56 2007 -0700 @@ -1,4 +1,1 @@ -#!python2.5 -import yt.fido - -yt.fido.run() +basic.py \ No newline at end of file diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b scripts/fimport --- a/scripts/fimport Sat Aug 25 22:06:06 2007 -0700 +++ b/scripts/fimport Sun Aug 26 14:08:56 2007 -0700 @@ -1,4 +1,1 @@ -#!python2.5 -import yt.fido - -yt.fido.run() +basic.py \ No newline at end of file diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b scripts/frecomp --- a/scripts/frecomp Sat Aug 25 22:06:06 2007 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -#!python2.5 -import yt.fido - -yt.fido.run() diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b scripts/frevert --- a/scripts/frevert Sat Aug 25 22:06:06 2007 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -#!python2.5 -import yt.fido - -yt.fido.run() diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b src/fido/FileHandling.py --- a/src/fido/FileHandling.py Sat Aug 25 22:06:06 2007 -0700 +++ b/src/fido/FileHandling.py Sun Aug 26 14:08:56 2007 -0700 @@ -24,6 +24,13 @@ from yt.fido import * +def copyOutput(basename, newLocation, extraFiles=None): + if extraFiles == None: extraFiles = [] + copyGlob("%s*" % (basename), newLocation) + for file in extraFiles: + copyGlob(file, location) + return os.path.join(newLocation, os.path.basename(basename)) + def moveOutput(basename, newLocation, extraFiles=None): if extraFiles == None: extraFiles = [] moveGlob("%s*" % (basename), newLocation) @@ -50,11 +57,17 @@ if extraFiles == None: extraFiles = [] if not newLocation: newLocation = getParentDir(filename) - print newLocation else: # Make sure we have no relative references newLocation = os.path.normpath(newLocation) moveGlob("%s*" % filename, newLocation) + +def copyGlob(globPattern, newLocation): + if not os.path.isdir(newLocation): + os.makedirs(newLocation) + for file in glob.glob(globPattern): + mylog.debug("Copying %s to %s", file, newLocation) + shutil.copy(file, newLocation) def moveGlob(globPattern, newLocation): if not os.path.isdir(newLocation): diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b src/fido/OutputCollection.py --- a/src/fido/OutputCollection.py Sat Aug 25 22:06:06 2007 -0700 +++ b/src/fido/OutputCollection.py Sun Aug 26 14:08:56 2007 -0700 @@ -50,8 +50,10 @@ self.outputTimeIDs = na.array(outputTimeIDs, nT.Int64) self.outputTimes = na.array(outputTimes, nT.Float64) - def writeOut(self, filename): - f = open(filename, "w") + def writeOut(self): + path=ytcfg.get("Fido","rundir") + fn = os.path.join(path, "runF_%s" % (self.title)) + f = open(fn, "w") for i, output in enumerate(self.outputNames): f.write("Output:%s:%s:%s\n" % ( \ os.path.abspath(output), \ @@ -86,7 +88,10 @@ return na.where(self.outputTimes > time)[0] def __delitem__(self, key): - id = self.index(key) + if isinstance(key, types.StringType): + id = self.index(key) + elif isinstance(key, types.IntType): + id = key self.outputNames = na.array(self.outputNames[:id].tolist() \ + self.outputNames[id+1:].tolist()) self.outputTimes = na.array(self.outputTimes[:id].tolist() \ @@ -103,6 +108,7 @@ index = self.index(key) elif isinstance(key, types.IntType): index = key + # This fails, but I don't know how to fix it. return self.outputs[index] def index(self, key): @@ -110,7 +116,8 @@ # Find out the index index = None for i in range(self.outputNames.shape[0]): - if self.outputNames[i] == t: + if os.path.basename(self.outputNames[i]) \ + == os.path.basename(t): index = i break if index == None: @@ -188,10 +195,11 @@ function(*args, **kwargs) def GrabCollections(path=None): - if not path: path=ytcfg.get("fido","rundir") + if not path: path=ytcfg.get("Fido","rundir") ocs = [] - for file in glob.glob(os.path.join(path,"yt_*")): + for file in glob.glob(os.path.join(path,"runF_*")): title=os.path.basename(file) + if title.startswith("runF_"): title = title[5:] ocs.append(OutputCollection(title)) ocs[-1].readIn(file) return ocs diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b src/fido/OutputWatcher.py --- a/src/fido/OutputWatcher.py Sat Aug 25 22:06:06 2007 -0700 +++ b/src/fido/OutputWatcher.py Sun Aug 26 14:08:56 2007 -0700 @@ -40,12 +40,11 @@ self.process = process self.newPrefix = newPrefix self.skipFiles = [] # Forward compatible - if functionHandler == None: - self.functionHandler = lambda a: None - else: + self.functionHandler = None + if functionHandler != None: self.functionHandler = functionHandler() - def run(self): + def run(self, runOnce=False): mylog.info("Entering main Fido loop (CTRL-C or touch 'stopFido' to end)") while not self.checkForStop(): nn = self.checkForOutput() @@ -53,11 +52,14 @@ newName = buryOutput(bn) self.dealWithOutput(newName) time.sleep(WAITBETWEEN) + if runOnce: break def dealWithOutput(self, filename): # First, add it to the OutputCollection self.oc.addOutput(filename) - self.oc.writeOut("runF_%s" % (self.title)) + self.oc.writeOut() + if self.functionHandler == None: + return # Now, we pass it to our function handler pid = os.fork() if pid: diff -r 965aeb33157cb092f6c567d70cd03b33cac03d9a -r 6ca95e61d7bbf5829ffb21a4e53569ac9ed9109b src/fido/__init__.py --- a/src/fido/__init__.py Sat Aug 25 22:06:06 2007 -0700 +++ b/src/fido/__init__.py Sun Aug 26 14:08:56 2007 -0700 @@ -33,7 +33,7 @@ from yt.config import ytcfg from yt.arraytypes import * -mylog.warning("shutil used in FileHandling may lead to sub-optimal performance") +mylog.debug("shutil used in FileHandling may lead to sub-optimal performance") import os, os.path, shutil, time, sys, glob, types WAITBETWEEN=5 @@ -57,3 +57,4 @@ from OutputCollection import * from FileHandling import * from OutputWatcher import * +from RunStandalones import *