Example #1
0
def _pickle(p, arg, n):
    '''Create structure of all data recursively and replace objects with name.
    It also saves non-sequences.

    Returns tuple of next number and either list, dictionary or name
    '''
    if isinstance(arg, dict):
        d = dict()
        for k in arg:
            n, d[k] = _pickle(p, arg[k], n)
        return n, d
    elif isinstance(arg, (list, tuple)):
        l = list()
        for a in arg:
            n, o = _pickle(p, a, n)
            l.append(o)
        if isinstance(arg, tuple):
            return n, tuple(l)
        return n, l
    elif isinstance(arg, ndarray):
        name = "p%03d.npy" % n
        _asave(_path.join(p, name), arg)
        return n + 1, name
    else:
        name = "p%03d.pkl" % n
        if isinstance(arg, ndgeneric):
            arg = scalarToPython(arg)
        try:
            f = open(_path.join(p, name), 'w')
            _psave(arg, f)
        except:
            raise
        else:
            f.close()
        return n + 1, name
Example #2
0
def _pickle(p, arg, n):
    '''Create structure of all data recursively and replace objects with name.
    It also saves non-sequences.

    Returns tuple of next number and either list, dictionary or name
    '''
    if isinstance(arg, dict):
        d = dict()
        for k in arg:
            n, d[k] = _pickle(p, arg[k], n)
        return n, d
    elif isinstance(arg, (list, tuple)):
        l = list()
        for a in arg:
            n, o = _pickle(p, a, n)
            l.append(o)
        if isinstance(arg, tuple):
            return n, tuple(l)
        return n, l
    elif isinstance(arg, ndarray):
        name = "p%03d.npy" % n
        _asave(_path.join(p, name), arg)
        return n+1, name
    else:
        name = "p%03d.pkl" % n
        if isinstance(arg, ndgeneric):
            arg = scalarToPython(arg)
        try:
            f = open(_path.join(p, name), 'w')
            _psave(arg, f)
        except:
            raise
        else:
            f.close()
        return n+1, name
Example #3
0
def save_args(arg, dir=None):  #@ReservedAssignment
    '''Save arguments as files in a temporary directory
    Use pickle for most objects but use NumPy's npy format for arrays
    arg -- sequence of arguments
    
    Return name of directory used
    '''
    import tempfile as _tmp
    d = _tmp.mkdtemp(prefix='ef-args', dir=dir)
    _n, tree = _pickle(d, arg, 0)  # pickle non-sequences
    try:  # now do argument structure
        f = open(_path.join(d, "tree.pkl"), 'w')
        _psave(tree, f)
    except:
        raise
    else:
        f.close()

    return d
Example #4
0
def save_args(arg, dir=None): #@ReservedAssignment
    '''Save arguments as files in a temporary directory
    Use pickle for most objects but use NumPy's npy format for arrays
    arg -- sequence of arguments
    
    Return name of directory used
    '''
    import tempfile as _tmp
    d = _tmp.mkdtemp(prefix='ef-args', dir=dir)
    _n, tree = _pickle(d, arg, 0) # pickle non-sequences
    try: # now do argument structure
        f = open(_path.join(d, "tree.pkl"), 'w')
        _psave(tree, f)
    except:
        raise
    else:
        f.close()

    return d