Exemplo n.º 1
0
def mydict(request, tmpdir):
    if request.param == 'tmpdir':
        persist_path = tmpdir.strpath
        print(persist_path)
    else:
        persist_path = None
    return PickleDict(persist_path=persist_path)
Exemplo n.º 2
0
def nodebook(line):
    """
    ipython magic for initializing nodebook, expects name for nodebook database
    """
    args = line.lstrip().split(' ')

    try:
        mode = args[0]
        assert mode in ALLOWED_MODES
    except (IndexError, AssertionError):
        raise SyntaxError("Must specify mode as %s" % str(ALLOWED_MODES))

    if mode == MODE_MEMORY:
        persist = False
    else:
        persist = True

    if persist:
        NODEBOOK_STATE['cache_dir'] = 'nodebook_cache/'
        try:
            NODEBOOK_STATE['cache_dir'] += args[1]
        except IndexError:
            NODEBOOK_STATE['cache_dir'] += 'default'

        try:
            os.makedirs(NODEBOOK_STATE['cache_dir'])
        except OSError as exc:  # Python >2.5
            if exc.errno == errno.EEXIST and os.path.isdir(NODEBOOK_STATE['cache_dir']):
                pass
            else:
                raise
        try:
            with open(os.path.join(NODEBOOK_STATE['cache_dir'], 'nodebook.p'), 'rb') as f:
                NODEBOOK_STATE['nodebook'] = pickle.load(f)
        except IOError:
            var_store = PickleDict(NODEBOOK_STATE['cache_dir'])
            NODEBOOK_STATE['nodebook'] = Nodebook(var_store)
    else:
        var_store = PickleDict()
        NODEBOOK_STATE['nodebook'] = Nodebook(var_store)

    if len(NODEBOOK_STATE['nodebook'].nodes) > 0:
        NODEBOOK_STATE['nodebook'].update_all_prompts(get_ipython().payload_manager)
Exemplo n.º 3
0
 def nb(self):
     var_store = PickleDict()
     return Nodebook(var_store)