def addOptions(self,withExecute=False):
        self.__blink1=None
        if hasBlink:
            self.blink1grp=OptionGroup(self.parser,
                                       "Blink(1)",
                                       "Options for signalling on a blink(1)-device")
            self.blink1grp.add_option("--use-blink1",
                                      action="store_true",
                                      default=False,
                                      dest="useBlink1",
                                      help="Should we use the blink1 for notifications on this utility")
            self.blink1grp.add_option("--blink-timestep-color",
                                      dest="blink1stepcolor",
                                      default=conf().get("Blink1","timestepcolor"),
                                      help="The default color for time-steps. Default: %default")
            if withExecute:
                self.blink1grp.add_option("--blink-execute-pattern",
                                          dest="blink1executepattern",
                                          default=conf().get("Blink1","executepattern"),
                                          help="The default pattern to play during execution. Default: %default")
                self.blink1grp.add_option("--blink-execute-interleave",
                                          dest="blink1executeinterleave",
                                          type=float,
                                          default=conf().getfloat("Blink1","executeinterleave"),
                                          help="The default pause between playing the pattern during execution. Default: %default")

            self.parser.add_option_group(self.blink1grp)
    def execNameFound(self,execName):
        if hasattr(self,"oldExecName"):
            if execName==self.oldExecName:
                return

        self.automaticCustom=[]
        self.oldExecName=execName
        from PyFoam import configuration as conf
        from PyFoam.Basics.CustomPlotInfo import CustomPlotInfo

        solvers=set([execName])

        for name,lst in conf().items("SolverBase"):
            if execName.lower().startswith(name):
                solvers|=set(eval(lst))

        import re
        autoplots=[a.lower() for a in conf().getList("Plotting","autoplots")]

        for name,dataString in conf().items("Autoplots"):
            found=False
            try:
                data=eval(dataString)
                solverPatterns=data["solvers"]
                info=data["plotinfo"]
                for s in solverPatterns:
                    try:
                        for eName in solvers:
                            if re.compile(s).fullmatch(eName):
                                found=True
                                break
                        if found:
                            break
                    except AttributeError:
                        # python 2 has no fullmatch
                        for eName in solvers:
                            if re.compile("(?:" + s + r")\Z").match(eName):
                                found=True
                                break
                        if found:
                            break
            except KeyError:
                import sys
                e = sys.exc_info()[1]
                warning("Miss-configured automatic expression",name,
                        "Missing key",e.args[0])
            except re.error:
                import sys
                warning("Problem with regular expression",s,"of",name,
                        ":",sys.exc_info()[1])
            except SyntaxError:
                warning("Syntax error in",dataString)

            if found or name.lower() in autoplots:
                self.automaticCustom.append(CustomPlotInfo(raw=info,
                                                           name=name))
    def packCase(self,tarname,last=False,exclude=[],additional=[],base=None):
        """Packs all the important files into a compressed tarfile.
        Uses the essential-list and excludes the .svn-directories.
        Also excludes files ending with ~
        @param tarname: the name of the tar-file
        @param last: add the last directory to the list of directories to be added
        @param exclude: List with additional glob filename-patterns to be excluded
        @param additional: List with additional glob filename-patterns
        that are to be added
        @param base: Different name that is to be used as the baseName for the case inside the tar"""

        ex=["*~",".svn"]+exclude
        members=list(self.essential)
        if last:
            if self.getLast()!=self.first:
                members.append(self.latestDir())
        for p in additional:
            for f in listdir(self.name):
                if (f not in members) and fnmatch.fnmatch(f,p):
                    members.append(path.join(self.name,f))

        tar=tarfile.open(tarname,"w:gz")

        for m in members:
            self.addToTar(tar,m,exclude=ex,base=base)

        additional=eval(conf().get("Cloning","addItem"))
        for a in additional:
            self.addToTar(tar,
                          path.join(self.name,a),
                          exclude=ex,
                          base=base)

        tar.close()
    def processPlotOptions(self):
        if self.opts.nodefault:
            self.opts.linear=False
            self.opts.continuity=False
            self.opts.bound=False
            self.opts.iterations=False
            self.opts.courant=False
            self.opts.execution=False
            self.opts.deltat=False

        if self.opts.withAll:
            self.opts.linear=True
            self.opts.continuity=True
            self.opts.bound=True
            self.opts.iterations=True
            self.opts.courant=True
            self.opts.execution=True
            self.opts.deltat=True

        if self.opts.hardcopy and self.opts.hardcopyTerminalOptions=="":
            from PyFoam import configuration as conf

            self.opts.hardcopyTerminalOptions=conf().get("Plotting",
                                                         "hardcopyOptions_"+self.opts.hardcopyformat,
                                                         default="")
        def addPlotOption(name,helpText):
            defaultValue=conf().getboolean("Plotting","plot"+name)

            plotItGroup.add_option("--"+("no" if defaultValue else "with")+"-"+name,
                                   action="store_"+("false" if defaultValue else "true"),
                                   default=defaultValue,
                                   dest=name,
                                   help=("Don't plot " if defaultValue else "Plot ")+helpText)
    def cloneCase(self,name,svnRemove=True,followSymlinks=False):
        """create a clone of this case directory. Remove the target directory, if it already exists

        @param name: Name of the new case directory
        @param svnRemove: Look for .svn-directories and remove them
        @param followSymlinks: Follow symbolic links instead of just copying them
        @rtype: L{SolutionDirectory} or correct subclass
        @return: The target directory"""

        additional=eval(conf().get("Cloning","addItem"))
        for a in additional:
            self.addToClone(a)

        if path.exists(name):
            self.rmtree(name)
        mkdir(name)
        if self.parallel:
            for i in range(self.nrProcs()):
                mkdir(path.join(name,"processor%d" % i))

        for d in self.essential:
            if d!=None:
                fs=followSymlinks
                if fs:
                    noForce=eval(conf().get("Cloning","noForceSymlink"))
                    pth,fl=path.split(d)
                    for n in noForce:
                        if fnmatch.fnmatch(fl,n):
                            fs=False
                            break

                if self.parallel:
                    pth,fl=path.split(d)
                    if path.exists(path.join(pth,"processor0",fl)):
                        for i in range(self.nrProcs()):
                            self.copytree(path.join(pth,"processor%d" % i,fl),
                                          path.join(name,"processor%d" % i),
                                          symlinks=not fs)

                if path.exists(d):
                    self.copytree(d,name,symlinks=not fs)

        if svnRemove:
            self.execute("find "+name+" -name .svn -exec rm -rf {} \\; -prune")

        return self.__class__(name,archive=self.archive)
 def __init__(self,
              ticColor=None):
     """Constructs the object. Tests for blink-device only in the beginning.
     If none is found an exception is thrown"""
     self.__baseURL=conf().get("Blink1","baseurl")
     self.__timeout=conf().getfloat("Blink1","allowedtimeout")
     try:
         response=self.__sendCommand("id")
     except requests.ConnectionError:
         e=sys.exc_info()[1]
         raise PyFoamException("No blink(1) at",self.__baseURL,":",e)
     if len(response["blink1_serialnums"])<1:
         raise PyFoamException("Seems that no blink(1) is plugged in")
     self.reloadPatterns()
     self.__threads=[]
     self.__tictocColor=ticColor if ticColor else conf().get("Blink1","tictoccolor")
     self.__lastTicTime=-1
     self.__ticToc=True
    def __init__(self,progress=False):
        """
        Constructs the analyzer

        @param progress: whether to print the time on the console
        """
        LogLineAnalyzer.__init__(self)
        self.exp=re.compile(conf().get("SolverOutput","timeRegExp"))

        self.fallback=re.compile("^(Time =|Iteration:) (.+)$")
        self.tryFallback=True

        self.progress=progress
    def __init__(self):
        """
        Constructs the analyzer
        """
        LogLineAnalyzer.__init__(self)
        self.exp=re.compile(conf().get("SolverOutput","timeRegExp"))
        self.registerRegexp(self.exp)
        self.createExpr=re.compile("^Create mesh for time = (%f%)$".replace("%f%",self.floatRegExp))
        self.registerRegexp(self.createExpr)

        self._createTime=None

        self.fallback=re.compile("^(Time =|Iteration:) (.+)$")
        self.registerRegexp(self.fallback)
        self.tryFallback=True
    def symlinkCase(self,
                    name,
                    followSymlinks=False,
                    maxLevel=1,
                    relPath=False):
        """create a clone of this case directory by creating a
        directory with symbolic links

        @param name: Name of the new case directory
        @param maxLevel: Maximum level down to which directories are created instead of symbolically linked
        @param followSymlinks: Follow symbolic links instead of just copying them
        @param relPath: the created symbolic links are relative (instead of absolute)
        @rtype: L{SolutionDirectory} or correct subclass
        @return: The target directory
        """
        here=path.abspath(self.name)
        polyDirs=[path.relpath(p,here) for p in self.find("polyMesh*",here)]

        additional=eval(conf().get("Cloning","addItem"))
        for a in additional:
            self.addToClone(a)

        if path.exists(name):
            self.rmtree(name)
        mkdir(name)
        toProcess=[]
        for d in self.essential:
            if d!=None:
                if self.parallel:
                    pth,fl=path.split(d)
                    if path.exists(path.join(pth,"processor0",fl)):
                        for i in range(self.nrProcs()):
                            toProcess.append("processor%d" % i)
                if path.exists(d):
                    toProcess.append(path.relpath(d,here))

        maxLevel=max(0,maxLevel)

        self.__symlinkDir(src=here,
                          dest=path.abspath(name),
                          toProcess=toProcess,
                          maxLevel=maxLevel,
                          relPath=relPath,
                          polyDirs=polyDirs,
                          symlinks=not followSymlinks)

        return self.__class__(name,archive=self.archive)
    def addOptions(self,haveServer=True):
        self.ensureGeneralOptions()
        from PyFoam import configuration as conf
        defaultForServer=conf().getboolean("Network","startServerThread")

        if haveServer and defaultForServer:
            self.generalOpts.add_option("--no-server-process",
                                        action="store_false",
                                        default=True,
                                        dest="server",
                                        help="Do not start a server process that can control the process")
        else:
            self.generalOpts.add_option("--start-server-process",
                                        action="store_true",
                                        default=True,
                                        dest="server",
                                        help="Start a server process that can control the process")
    def addOptions(self):
        debug=OptionGroup(self.parser,
                          "Run in Debugger",
                          "Run the executable in the debugger")
        self.parser.add_option_group(debug)

        debug.add_option("--run-in-debugger",
                         action="store_true",
                         dest="runInDebugger",
                         default=False,
                         help="Run the program in a debugger. Drops to the the shell o the debugger in the case of a problem")
        debug.add_option("--debugger-call",
                         action="store",
                         dest="debuggerCall",
                         default=conf().getArch("Execution","DebuggerCall"),
                         help="The command used to call the compiler. The string {exe} is replaced with the name of the executable. The string {args} with the arguments (if arguments were given). Default: '%default'")
        CommonBlink1.addOptions(self,withExecute=True)
Example #13
0
    def addOptions(self):
        behaveGroup = OptionGroup(
            self.parser, "Plot Behaviour",
            "How the plots should behave (most of these options are passed to gnuplot)"
        )

        behaveGroup.add_option(
            "--frequency",
            type="float",
            dest="frequency",
            default=1.,
            help=
            "The frequency with which output should be generated (in seconds). Default: %default"
        )
        behaveGroup.add_option("--persist",
                               action="store_true",
                               dest="persist",
                               default=self.persistDefault,
                               help="Gnuplot windows stay after interrupt")
        behaveGroup.add_option("--non-persist",
                               action="store_false",
                               dest="persist",
                               help="Gnuplot windows close after interrupt")
        behaveGroup.add_option(
            "--quiet-plot",
            action="store_true",
            dest="quietPlot",
            default=False,
            help=
            "The plot implementation should not print to the standard output (some implementations do this)"
        )
        behaveGroup.add_option(
            "--raise",
            action="store_true",
            dest="raiseit",
            help="Raise the Gnuplot windows after every replot")
        behaveGroup.add_option(
            "--implementation",
            default=None,
            dest="implementation",
            help="The implementation that should be used for plotting")
        behaveGroup.add_option(
            "--gnuplot-terminal",
            default=None,
            type="choice",
            dest="gnuplotTerminal",
            choices=validTerminals(),
            help="Terminal implementation of gnuplot to use. Options: " +
            ", ".join(validTerminals()))

        self.parser.add_option_group(behaveGroup)

        gnuplotInternalGroup = OptionGroup(
            self.parser, "Gnuplot internal",
            "These options control internal behavior of Gnuplot")
        useFifo = conf().getboolean("Gnuplot", "prefer_fifo")
        gnuplotInternalGroup.add_option(
            "--gnuplot-no-use-fifo",
            action="store_false",
            dest="gnuplotUseFifo",
            default=useFifo,
            help=
            "Do no use the FIFO-queues for plots. This may create files in /tmp that won't be removed."
            + (" This is already the default" if not useFifo else ""))
        gnuplotInternalGroup.add_option(
            "--gnuplot-use-fifo",
            action="store_true",
            dest="gnuplotUseFifo",
            default=useFifo,
            help="Use the FIFO-queues for plots. This reduces interactivity" +
            (" This is already the default" if useFifo else ""))

        self.parser.add_option_group(gnuplotInternalGroup)

        writeDGroup = OptionGroup(
            self.parser, "Write plot data",
            "How data and the plots themself should be written to disk")
        writeDGroup.add_option(
            "--hardcopy",
            action="store_true",
            default=False,
            dest="hardcopy",
            help="Writes hardcopies of the plot at the end of the run")
        hcChoices = ["postscript", "png", "pdf", "svg", "eps"]
        writeDGroup.add_option(
            "--format-of-hardcopy",
            type="choice",
            action="store",
            default="png",
            dest="hardcopyformat",
            choices=hcChoices,
            help="File-format the hardcopy should be written in (Formats: " +
            ", ".join(hcChoices) + ") Default: %default")
        writeDGroup.add_option("--prefix-hardcopy",
                               action="store",
                               default=None,
                               dest="hardcopyPrefix",
                               help="Prefix for the hardcopy-files")
        writeDGroup.add_option(
            "--terminal-hardcopy-options",
            action="store",
            default="",
            dest="hardcopyTerminalOptions",
            help=
            "Options for the gnuplot terminal that does the hardcopy. Overrides the setting in [Plotting] with the name 'hardcopyOptions_<term>' (with <term> being the value of --format-of-hardcopy)"
        )

        writeDGroup.add_option(
            "--no-pickled-file",
            action="store_false",
            default=True,
            dest="writePickled",
            help="Do not write a pickled file with the plot data")

        self.parser.add_option_group(writeDGroup)

        plotItGroup = OptionGroup(
            self.parser, "What to plot",
            "Predefined quantities that the program looks for and plots. Defaults for this can be set in the [Plotting]-section of the configuration"
        )

        def addPlotOption(name, helpText):
            defaultValue = conf().getboolean("Plotting", "plot" + name)

            plotItGroup.add_option(
                "--" + ("no" if defaultValue else "with") + "-" + name,
                action="store_" + ("false" if defaultValue else "true"),
                default=defaultValue,
                dest=name,
                help=("Don't plot " if defaultValue else "Plot ") + helpText)

        plotItGroup.add_option("--no-default",
                               action="store_true",
                               default=False,
                               dest="nodefault",
                               help="Switch off the default plots")
        addPlotOption("linear", "the linear solver initial residual")
        addPlotOption("continuity", "the continuity info")
        addPlotOption("bound", "the bounding of variables")
        addPlotOption("iterations",
                      "the number of iterations of the linear solver")
        addPlotOption("courant", "the courant-numbers of the flow")
        addPlotOption("execution", "the execution time of each time-step")
        addPlotOption("deltat", "the timestep-size time-step")

        plotItGroup.add_option("--with-all",
                               action="store_true",
                               default=False,
                               dest="withAll",
                               help="Switch all possible plots on")
        self.parser.add_option_group(plotItGroup)
            fname+="_"+str(self.prevCalls(name))

        f=self.getFile(fname)

        try:
            f.write(time,data)
        except IOError:
            e = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e'
            print_(self.openList)
            print_(len(self.files))
            print_(self.files)
            print_("Open:",end="")
            cnt=0
            for f in self.files:
                if self.files[f].handle!=None:
                    print_(f,end="")
                    cnt+=1
            print_()
            print_("Actually open",cnt,"of",len(self.files))
            raise e

    def close(self):
        """Force all files to be closed"""

        for f in self.files:
            self.files[f].close()

OutFileCollection.maxOpenFiles=int(conf().get("OutfileCollection","maximumOpenFiles"))

# Should work with Python3 and Python2
Example #15
0
    def clearResults(
        self, after=None, removeProcs=False, keepLast=False, vtk=True, keepRegular=False, functionObjectData=False
    ):
        """remove all time-directories after a certain time. If not time ist
        set the initial time is used
        @param after: time after which directories ar to be removed
        @param removeProcs: if True the processorX-directories are removed.
        Otherwise the timesteps after last are removed from the
        processor-directories
        @param keepLast: Keep the data from the last timestep
        @param vtk: Remove the VTK-directory if it exists
        @param keepRegular: keep all the times (only remove processor and other stuff)
        @param functionObjectData: tries do determine which data was written by function obejects and removes it"""

        self.reread()

        last = self.getLast()

        if after == None:
            try:
                time = float(self.first)
            except TypeError:
                warning("The first timestep in", self.name, " is ", self.first, "not a number. Doing nothing")
                return
        else:
            time = float(after)

        if not keepRegular:
            for f in self.times:
                if float(f) > time and not (keepLast and f == last):
                    self.rmtree(path.join(self.name, f))

        if path.exists(path.join(self.name, "VTK")) and vtk:
            self.rmtree(path.join(self.name, "VTK"))

        if self.nrProcs():
            for f in listdir(self.name):
                if re.compile("processor[0-9]+").match(f):
                    if removeProcs:
                        self.rmtree(path.join(self.name, f))
                    else:
                        pDir = path.join(self.name, f)
                        for t in listdir(pDir):
                            try:
                                val = float(t)
                                if val > time:
                                    self.rmtree(path.join(pDir, t))
                            except ValueError:
                                pass

        if functionObjectData:
            cd = ParsedParameterFile(self.controlDict())
            if "functions" in cd:
                for f in cd["functions"][0::2]:
                    pth = path.join(self.name, f)
                    if path.exists(pth):
                        self.rmtree(pth)

        additional = eval(conf().get("Clearing", "additionalpatterns"))
        for a in additional:
            self.clearPattern(a)
Example #16
0
 def addLocalConfig(self):
     """Add the local configuration file of the case to the configuration"""
     fName=path.join(self.name,"LocalConfigPyFoam")
     if path.exists(fName):
         conf().addFile(fName)
    def clearResults(self,
                     after=None,
                     removeProcs=False,
                     keepLast=False,
                     vtk=True,
                     keepRegular=False,
                     keepParallel=False,
                     keepInterval=None,
                     keepTimes=[],
                     functionObjectData=False,
                     dryRun=False,
                     verbose=False,
                     additional=[]):
        """remove all time-directories after a certain time. If not time ist
        set the initial time is used
        :param after: time after which directories ar to be removed
        :param removeProcs: if True the processorX-directories are removed.
        Otherwise the timesteps after last are removed from the
        processor-directories
        :param keepLast: Keep the data from the last timestep
        :param keepInterval: if set: keep timesteps that are this far apart
        :param vtk: Remove the VTK-directory if it exists
        :param keepRegular: keep all the times (only remove processor and other stuff)
        :param functionObjectData: tries do determine which data was written by function obejects and removes it
        :param additional: List with glob-patterns that are removed too"""

        self.reread()

        last = self.getLast()

        if after == None:
            try:
                time = float(self.first)
            except TypeError:
                warning("The first timestep in", self.name, " is ", self.first,
                        "not a number. Doing nothing")
                return
        else:
            time = float(after)

        lastKeptIndex = int(-1e5)

        if keepInterval != None:
            if keepInterval <= 0:
                error("The keeping interval", keepInterval,
                      "is smaller that 0")

        if not keepRegular:
            for f in self.times:
                keep = False
                if keepInterval != None:
                    thisIndex = int((float(f) + 1e-10) / keepInterval)
                    if thisIndex != lastKeptIndex:
                        keep = True
                for k in keepTimes:
                    if self.timeIndex(float(f),
                                      True) == self.timeIndex(k, True):
                        keep = True
                if float(f) > time and not (keepLast
                                            and f == last) and not keep:
                    #                   print "Removing",path.join(self.name,f)
                    if path.exists(path.join(self.name, f)):
                        if verbose:
                            print_("Clearing", path.join(self.name, f))
                        if not dryRun:
                            self.rmtree(path.join(self.name, f))
                elif keepInterval != None:
                    lastKeptIndex = int((float(f) + 1e-10) / keepInterval)

        if path.exists(path.join(self.name, "VTK")) and vtk:
            if verbose:
                print_("Clearing", path.join(self.name, "VTK"))
            if not dryRun:
                self.rmtree(path.join(self.name, "VTK"))

        if self.nrProcs(
        ) and not keepParallel and not self.firstParallel is None:
            lastKeptIndex = int(-1e5)
            time = max(time, float(self.firstParallel))
            for f in listdir(self.name):
                if re.compile("processor[0-9]+").match(f):
                    if removeProcs:
                        if verbose:
                            print_("Clearing", path.join(self.name, f))
                        if not dryRun:
                            self.rmtree(path.join(self.name, f))
                    else:
                        pDir = path.join(self.name, f)
                        for t in listdir(pDir):
                            try:
                                keep = False
                                val = float(t)
                                if keepInterval != None:
                                    thisIndex = int(
                                        (float(t) + 1e-10) / keepInterval)
                                    if thisIndex != lastKeptIndex:
                                        keep = True
                                for k in keepTimes:
                                    if self.timeIndex(val,
                                                      True) == self.timeIndex(
                                                          k, True):
                                        keep = True
                                if val > time and not (keepLast and t
                                                       == last) and not keep:
                                    if path.exists(path.join(pDir, t)):
                                        if verbose:
                                            print_("Clearing",
                                                   path.join(pDir, t))
                                        if not dryRun:
                                            self.rmtree(path.join(pDir, t))
                                elif keepInterval != None:
                                    lastKeptIndex = int(
                                        (float(t) + 1e-10) / keepInterval)
                            except ValueError:
                                pass

        if functionObjectData:
            cd = ParsedParameterFile(self.controlDict(), doMacroExpansion=True)
            if "functions" in cd:
                if type(cd["functions"]) in [DictProxy, dict]:
                    for f in cd["functions"]:
                        pth = path.join(self.name, f)
                        if path.exists(pth):
                            if verbose:
                                print_("Clearing", pth)
                            if not dryRun:
                                self.rmtree(pth)
                else:
                    for f in cd["functions"][0::2]:
                        pth = path.join(self.name, f)
                        if path.exists(pth):
                            if verbose:
                                print_("Clearing", pth)
                            if not dryRun:
                                self.rmtree(pth)

        additional += eval(conf().get("Clearing", "additionalpatterns"))
        for a in additional:
            self.clearPattern(a, dryRun=dryRun, verbose=verbose)
 def addLocalConfig(self):
     """Add the local configuration file of the case to the configuration"""
     fName=path.join(self.name,"LocalConfigPyFoam")
     if path.exists(fName):
         conf().addFile(fName)
    def clearResults(self,
                     after=None,
                     removeProcs=False,
                     keepLast=False,
                     vtk=True,
                     keepRegular=False,
                     keepParallel=False,
                     keepInterval=None,
                     functionObjectData=False,
                     additional=[]):
        """remove all time-directories after a certain time. If not time ist
        set the initial time is used
        @param after: time after which directories ar to be removed
        @param removeProcs: if True the processorX-directories are removed.
        Otherwise the timesteps after last are removed from the
        processor-directories
        @param keepLast: Keep the data from the last timestep
        @param keepInterval: if set: keep timesteps that are this far apart
        @param vtk: Remove the VTK-directory if it exists
        @param keepRegular: keep all the times (only remove processor and other stuff)
        @param functionObjectData: tries do determine which data was written by function obejects and removes it
        @param additional: List with glob-patterns that are removed too"""

        self.reread()

        last=self.getLast()

        if after==None:
            try:
                time=float(self.first)
            except TypeError:
                warning("The first timestep in",self.name," is ",self.first,"not a number. Doing nothing")
                return
        else:
            time=float(after)

        lastKeptIndex=int(-1e5)

        if keepInterval!=None:
            if keepInterval<=0:
                error("The keeping interval",keepInterval,"is smaller that 0")

        if not keepRegular:
            for f in self.times:
                keep=False
                if keepInterval!=None:
                    thisIndex=int((float(f)+1e-10)/keepInterval)
                    if thisIndex!=lastKeptIndex:
                        keep=True
                if float(f)>time and not (keepLast and f==last) and not keep:
                    #                   print "Removing",path.join(self.name,f)
                    if path.exists(path.join(self.name,f)):
                        self.rmtree(path.join(self.name,f))
                elif keepInterval!=None:
                    lastKeptIndex=int((float(f)+1e-10)/keepInterval)

        if path.exists(path.join(self.name,"VTK")) and vtk:
            self.rmtree(path.join(self.name,"VTK"))

        if self.nrProcs() and not keepParallel:
            lastKeptIndex=int(-1e5)
            for f in listdir(self.name):
                if re.compile("processor[0-9]+").match(f):
                    if removeProcs:
                        self.rmtree(path.join(self.name,f))
                    else:
                        pDir=path.join(self.name,f)
                        for t in listdir(pDir):
                            try:
                                keep=False
                                val=float(t)
                                if keepInterval!=None:
                                    thisIndex=int((float(f)+1e-10)/keepInterval)
                                    if thisIndex!=lastKeptIndex:
                                        keep=True
                                if val>time and not (keepLast and t==last) and not keep:
                                    if path.exists(path.join(pDir,t)):
                                        self.rmtree(path.join(pDir,t))
                                elif keepInterval!=None:
                                    lastKeptIndex=int((float(f)+1e-10)/keepInterval)
                            except ValueError:
                                pass

        if functionObjectData:
            cd=ParsedParameterFile(self.controlDict(),doMacroExpansion=True)
            if "functions" in cd:
                if type(cd["functions"]) in [DictProxy,dict]:
                    for f in cd["functions"]:
                        pth=path.join(self.name,f)
                        if path.exists(pth):
                            self.rmtree(pth)
                else:
                    for f in cd["functions"][0::2]:
                        pth=path.join(self.name,f)
                        if path.exists(pth):
                            self.rmtree(pth)

        additional+=eval(conf().get("Clearing","additionalpatterns"))
        for a in additional:
            self.clearPattern(a)
Example #20
0
        f = self.getFile(fname)

        try:
            f.write(time, data)
        except IOError:
            e = sys.exc_info()[
                1]  # Needed because python 2.5 does not support 'as e'
            print_(self.openList)
            print_(len(self.files))
            print_(self.files)
            print_("Open:", end="")
            cnt = 0
            for f in self.files:
                if self.files[f].handle != None:
                    print_(f, end="")
                    cnt += 1
            print_()
            print_("Actually open", cnt, "of", len(self.files))
            raise e

    def close(self):
        """Force all files to be closed"""

        for f in self.files:
            self.files[f].close()

OutFileCollection.maxOpenFiles = int(conf().get("OutfileCollection",
                                                "maximumOpenFiles"))

# Should work with Python3 and Python2