def uniqueName(name, othernames, exclude=None): _uniqueNameLock.acquire() others = othernames[:] try: if exclude is not None: try: others.remove(exclude) except ValueError: pass if name not in others: return name from ooflib.common.IO import automatic # delayed to avoid import loop auto = isinstance(name, automatic.AutomaticName) # Strip '<number>' suffix, if any. basename = re.split('<[0-9]+>$', name)[0] # Find any existing names of the form 'basename<number>'. expr = re.compile("^" + re.escape(basename) + "<[0-9]+>$") matches = filter(expr.match, others) if matches: # Find largest existing "<number>". suffixes = [x[len(basename) + 1:-1] for x in matches] lastsuffix = max(map(eval, suffixes)) else: lastsuffix = 1 newname = "%s<%d>" % (basename, lastsuffix + 1) if auto: return automatic.AutomaticName(newname) return newname finally: _uniqueNameLock.release()
def outputNameResolver(param, name): if param.automatic(): output = param.group['output'].value basename = automatic.AutomaticName(output.defaultName()) else: basename = name mesh = ooflib.engine.mesh.meshes[param.group['mesh'].value] return mesh.outputSchedule.uniqueName(basename)
def replace(self, name, output, scheduletype, schedule, destination): for i, o in enumerate(self.outputs): if o.name() == name: output.setSchedule(schedule, scheduletype) output.setDestination(destination) # If the old output was given an automatically # generated name, the name must be updated to reflect # changes in the output. if isinstance(o.name(), automatic.AutomaticName): output.setName(automatic.AutomaticName( self.uniqueName(output.defaultName(), exclude=name) )) else: output.setName(name) self.outputs[i] = output return raise ValueError("No such scheduled output: " + name)
def replace(self, name, output): for i, o in enumerate(self.outputs): if o.name() == name: output.setSchedule(o.schedule, o.scheduleType) # The old destination may be inappropriate for the new # output. If it is, silently delete it. try: output.setDestination(o.destination) except ooferror2.ErrInvalidDestination: pass # If the old output was given an automatically # generated name, the name must be updated to reflect # changes in the output. if isinstance(o.name(), automatic.AutomaticName): output.setName( automatic.AutomaticName( self.uniqueName(output.defaultName(), exclude=name))) else: output.setName(name) self.outputs[i] = output return raise ValueError("No such scheduled output: " + name)