Beispiel #1
0
def _load(file_name):
    try:
        _kale_load_file_name = _get_files(file_name)
        _kale_load_folder_name = _get_folders(file_name)

        if len(_kale_load_file_name) > 1:
            raise ValueError("Found multiple files with name %s: %s" %
                             (file_name, str(_kale_load_file_name)))
        if len(_kale_load_folder_name) > 1:
            raise ValueError("Found multiple folders with name %s: %s" %
                             (file_name, str(_kale_load_folder_name)))

        _names = _kale_load_file_name + _kale_load_folder_name
        _kale_load_file_name = _names[0]

        return resource_load(
            os.path.join(KALE_DATA_DIRECTORY, _kale_load_file_name))
    except ValueError as e:
        raise KaleMarshalException(
            original_exc=e,
            original_traceback=sys.exc_info()[EXC_INFO_TRACEBACK],
            msg=KALE_LOAD_ERROR_MSG % (file_name, e),
            obj_name=file_name,
            operation="load")
    except Exception as e:
        raise KaleMarshalException(
            original_exc=e,
            original_traceback=sys.exc_info()[EXC_INFO_TRACEBACK],
            msg=KALE_UNKNOWN_MARSHALLING_ERROR % e,
            obj_name=file_name,
            operation="load")
Beispiel #2
0
def _load(file_name):
    try:
        _kale_load_file_name = [
            f for f in os.listdir(KALE_DATA_DIRECTORY)
            if (os.path.isfile(os.path.join(KALE_DATA_DIRECTORY, f))
                and os.path.splitext(f)[0] == file_name)
        ]
        if len(_kale_load_file_name) > 1:
            raise ValueError("Found multiple files with name %s: %s" %
                             (file_name, str(_kale_load_file_name)))
        _kale_load_file_name = _kale_load_file_name[0]

        return resource_load(
            os.path.join(KALE_DATA_DIRECTORY, _kale_load_file_name))
    except ValueError as e:
        raise KaleMarshalException(
            original_exc=e,
            original_traceback=sys.exc_info()[EXC_INFO_TRACEBACK],
            msg=KALE_LOAD_ERROR_MSG % (file_name, e),
            obj_name=file_name,
            operation="load")
    except Exception as e:
        raise KaleMarshalException(
            original_exc=e,
            original_traceback=sys.exc_info()[EXC_INFO_TRACEBACK],
            msg=KALE_UNKNOWN_MARSHALLING_ERROR % e,
            obj_name=file_name,
            operation="load")
Beispiel #3
0
def unmarshal_data(source_notebook_path):
    """Unmarshal data from the marshal directory."""
    source_notebook_path = os.path.expanduser(source_notebook_path)
    kale_marshal_dir = _get_kale_marshal_dir(source_notebook_path)
    if not os.path.exists(kale_marshal_dir):
        return {}

    load_file_names = [f for f in os.listdir(kale_marshal_dir)
                       if os.path.isfile(os.path.join(kale_marshal_dir, f))]

    return {os.path.splitext(f)[0]:
            resource_load(os.path.join(kale_marshal_dir, f))
            for f in load_file_names}
Beispiel #4
0
def unmarshal_data(source_notebook_path):
    kale_marshal_dir = _get_kale_marshal_dir(source_notebook_path)
    if not os.path.exists(kale_marshal_dir):
        return {}

    load_file_names = [
        f for f in os.listdir(kale_marshal_dir)
        if os.path.isfile(os.path.join(kale_marshal_dir, f))
    ]

    return {
        os.path.splitext(f)[0]:
        resource_load(os.path.join(kale_marshal_dir, f))
        for f in load_file_names
    }
Beispiel #5
0
Datei: nb.py Projekt: zlapp/kale
def unmarshal_data(source_notebook_path):
    kale_marshal_dir = ".%s%s" % (source_notebook_path,
                                  KALE_MARSHAL_DIR_POSTFIX)
    if not os.path.exists(kale_marshal_dir):
        return {}

    load_file_names = [
        f for f in os.listdir(kale_marshal_dir)
        if os.path.isfile(os.path.join(kale_marshal_dir, f))
    ]

    return {
        os.path.splitext(f)[0]:
        resource_load(os.path.join(kale_marshal_dir, f))
        for f in load_file_names
    }
def load(var_name):
    """Load an object using Kale's marshalling backends.

    Args:
        var_name: The name of the object to be loaded

    Returns: loaded object
    """
    # First check that the variable exists in the path
    if var_name not in KALE_DIRECTORY_FILE_NAMES:
        raise ValueError("Failed to load variable %s" % var_name)

    # Load variable
    _kale_load_file_name = [
        f for f in os.listdir(KALE_DATA_DIRECTORY)
        if (os.path.isfile(os.path.join(KALE_DATA_DIRECTORY, f))
            and os.path.splitext(f)[0] == var_name)
    ]
    if len(_kale_load_file_name) > 1:
        raise ValueError("Found multiple files with name %s: %s" %
                         (var_name, str(_kale_load_file_name)))
    _kale_load_file_name = _kale_load_file_name[0]
    return resource_load(
        os.path.join(KALE_DATA_DIRECTORY, _kale_load_file_name))