Skip to content
Snippets Groups Projects
Commit bbd81728 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

ENH: If outprefix is set to LOAD, all outputs are loaded.

parent 6d16a2a8
No related branches found
No related tags found
No related merge requests found
...@@ -90,6 +90,8 @@ import os ...@@ -90,6 +90,8 @@ import os
import sys import sys
import glob import glob
import shutil import shutil
import random
import string
import fnmatch import fnmatch
import inspect import inspect
import logging import logging
...@@ -616,14 +618,16 @@ class _FileOrThing(object): ...@@ -616,14 +618,16 @@ class _FileOrThing(object):
for filename in allPrefixed: for filename in allPrefixed:
basename = op.basename(filename) basename = op.basename(filename)
for prefix in prefixes: for prefPat, prefName in prefixes.items():
if fnmatch.fnmatch(basename, '{}*'.format(prefix)): if fnmatch.fnmatch(basename, '{}*'.format(prefPat)):
log.debug('Loading prefixed output %s: %s', log.debug('Loading prefixed output %s [%s]: %s',
prefix, filename) prefPat, prefName, filename)
fval = self.__load(filename) fval = self.__load(filename)
basename = self.__removeExt(basename) basename = self.__removeExt(basename)
basename = basename.replace(prefPat,
prefName)
result[basename] = fval result[basename] = fval
break break
...@@ -669,15 +673,15 @@ class _FileOrThing(object): ...@@ -669,15 +673,15 @@ class _FileOrThing(object):
- A dictionary of ``{ name : filename }`` mappings, - A dictionary of ``{ name : filename }`` mappings,
for all arguments with a value of ``LOAD``. for all arguments with a value of ``LOAD``.
- A list ``[ filename ]`` paths, for all - A dictionary ``{ filepat : replstr }`` paths, for
output-prefix arguments with a value of ``LOAD``. all output-prefix arguments with a value of ``LOAD``.
""" """
# These containers keep track # These containers keep track
# of output files which are to # of output files which are to
# be loaded into memory # be loaded into memory
outfiles = dict() outfiles = dict()
prefixedFiles = [] prefixedFiles = dict()
allargs = {k : v for k, v in zip(argnames, args)} allargs = {k : v for k, v in zip(argnames, args)}
allargs.update(kwargs) allargs.update(kwargs)
...@@ -696,9 +700,23 @@ class _FileOrThing(object): ...@@ -696,9 +700,23 @@ class _FileOrThing(object):
# accept an output prefix which contains # accept an output prefix which contains
# a directory path. # a directory path.
if prefix is not None: if prefix is not None:
# If prefix is set to LOAD,
# all generated output files
# should be loaded - we use a
# randomly generated prefix,
# and add it to prefixedFiles,
# so that every file which
# starts with it will be
# loaded.
if prefix is LOAD:
prefix = random.sample(string.ascii_letters, 10)
prefix = ''.join(prefix)
realPrefix = prefix realPrefix = prefix
prefix = op.basename(prefix) prefix = op.basename(prefix)
allargs[self.__outprefix] = op.join(workdir, prefix) allargs[self.__outprefix] = op.join(workdir, prefix)
prefixedFiles[prefix] = self.__outprefix
if len(self.__things) > 0: things = self.__things if len(self.__things) > 0: things = self.__things
else: things = allargs.keys() else: things = allargs.keys()
...@@ -717,7 +735,8 @@ class _FileOrThing(object): ...@@ -717,7 +735,8 @@ class _FileOrThing(object):
# be given a value of LOAD # be given a value of LOAD
if isprefixed and val is not LOAD: if isprefixed and val is not LOAD:
raise ValueError('Cannot specify name of prefixed file - the ' raise ValueError('Cannot specify name of prefixed file - the '
'name is defined by the output prefix') 'name is defined by the output prefix: '
'{}'.format(name))
if val is LOAD: if val is LOAD:
...@@ -728,7 +747,7 @@ class _FileOrThing(object): ...@@ -728,7 +747,7 @@ class _FileOrThing(object):
# function. So we don't pass it # function. So we don't pass it
# through. # through.
if isprefixed: if isprefixed:
prefixedFiles.append(name) prefixedFiles[name] = name
allargs.pop(name) allargs.pop(name)
# regular output-file argument # regular output-file argument
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment