@contextmanager
def update_storage(ctx):

    deployment_id = ctx.deployment.id
    plugin_name = ctx.plugin.name
    if not plugin_name:

        # hack for tasks that are executed locally.
        if ctx.task_name.startswith('cloudify_agent'):
            plugin_name = 'agent'

    storage_file_path = os.path.join(
        os.environ['TEST_WORKING_DIR'],
        'plugins-storage',
        '{0}.json'.format(plugin_name)
    )

    with fasteners.InterProcessLock('{0}.lock'.format(storage_file_path)):
        # create storage file
        # if it doesn't exist
        if not os.path.exists(storage_file_path):
            with open(storage_file_path, 'w') as f:
                json.dump({}, f)

        with open(storage_file_path, 'r') as f:
            data = json.load(f)
            if deployment_id not in data:
                data[deployment_id] = {}
            yield data.get(deployment_id)
        with open(storage_file_path, 'w') as f:
            json.dump(data, f, indent=2)
            f.write(os.linesep)
Reimplemented to use the 'run' magic.
dataset/ETHPy150Open cloudify-cosmo/cloudify-manager/tests/testenv/utils.py/update_storage--crossover with--dataset/ETHPy150Open ipython/ipython-py3k/IPython/frontend/qt/console/ipython_widget.py/IPythonWidget.execute_file