pub async fn kernels_pull(
        &self,
        pull: KernelPullRequest,
    ) -> anyhow::Result<(PathBuf, Option<PathBuf>)> {
        let (owner_slug, kernel_slug) = self.get_user_and_identifier_slug(&pull.name)?;

        let resp = self.kernel_pull(&pull.name).await?;

        let folder = pull.output.unwrap_or_else(|| {
            self.download_dir
                .join(format!("kernels/{}/{}", owner_slug, kernel_slug))
        });
        fs::create_dir_all(&folder)?;

        let metadata_path = folder.join(Self::KERNEL_METADATA_FILE);

        let file_name = if metadata_path.exists() {
            let existing_meta = Self::read_kernel_metadata_file(&metadata_path).await?;
            if Some("INSERT_CODE_FILE_PATH_HERE") == existing_meta.code_file.as_deref() {
                None
            } else {
                existing_meta.code_file
            }
        } else {
            resp.code_file_name()
        }
        .unwrap_or_else(|| "script.py".to_string());

        let output = folder.join(file_name);

        tokio::fs::write(&output, resp.blob.source).await?;

        if pull.with_metadata {
            tokio::fs::write(
                &metadata_path,
                serde_json::to_string_pretty(&resp.metadata)?,
            )
            .await?;

            Ok((output, Some(metadata_path)))
        } else {
            Ok((output, None))
        }
    }
/// Pull a kernel, including a metadata file (if metadata is True) and
/// associated files to a specified path.
Pull a kernel, including a metadata file (if metadata is True) and
associated files to a specified path.
Pull a kernel including a metadata file ( if metadata is True ) and associated files to a specified path .
pub async fn kernels_pull(
        &self,
        pull: KernelPullRequest,
    ) -> anyhow::Result<(PathBuf, Option<PathBuf>)> {
        let (owner_slug, kernel_slug) = self.get_user_and_identifier_slug(&pull.name)?;
        let resp = self.kernel_pull(&pull.name).await?;
        let folder = pull.output.unwrap_or_else(|| {
            self.download_dir
                .join(format!("kernels/{}/{}", owner_slug, kernel_slug))
        });
        fs::create_dir_all(&folder)?;
        let metadata_path = folder.join(Self::KERNEL_METADATA_FILE);
        let file_name = if metadata_path.exists() {
            let existing_meta = Self::read_kernel_metadata_file(&metadata_path).await?;
            if Some("INSERT_CODE_FILE_PATH_HERE") == existing_meta.code_file.as_deref() {
                None
            } else {
                existing_meta.code_file
            }
        } else {
            resp.code_file_name()
        }
        .unwrap_or_else(|| "script.py".to_string());
        let output = folder.join(file_name);
        tokio::fs::write(&output, resp.blob.source).await?;
        if pull.with_metadata {
            tokio::fs::write(
                &metadata_path,
                serde_json::to_string_pretty(&resp.metadata)?,
            )
            .await?;
            Ok((output, Some(metadata_path)))
        } else {
            Ok((output, None))
        }
    }
pub async fn kernels_pull ( & self , pull : KernelPullRequest , ) -> anyhow :: Result < ( PathBuf , Option < PathBuf > ) > { let ( owner_slug , kernel_slug ) = self . get_user_and_identifier_slug ( & pull . name ) ? ; let resp = self . kernel_pull ( & pull . name ) . await ? ; let folder = pull . output . unwrap_or_else ( | | { self . download_dir . join ( format ! ( " " owner_slug kernel_slug ) ) } ) ; fs :: create_dir_all ( & folder ) ? ; let metadata_path = folder . join ( Self :: KERNEL_METADATA_FILE ) ; let file_name = if metadata_path . exists ( ) { let existing_meta = Self :: read_kernel_metadata_file ( & metadata_path ) . await ? ; if Some ( " " ) == existing_meta . code_file . as_deref ( ) { None } else { existing_meta . code_file } } else { resp . code_file_name ( ) } . unwrap_or_else ( | | " " . to_string ( ) ) ; let output = folder . join ( file_name ) ; tokio :: fs :: write ( & output , resp . blob . source ) . await ? ; if pull . with_metadata { tokio :: fs :: write ( & metadata_path , serde_json :: to_string_pretty ( & resp . metadata ) ? , ) . await ? ; Ok ( ( output , Some ( metadata_path ) ) ) } else { Ok ( ( output , None ) ) } }
Pull a kernel, including a metadata file (if metadata is True) and
associated files to a specified path.
Pull a kernel including a metadata file ( if metadata is True ) and associated files to a specified path .
&self
pull
KernelPullRequest
&self
pull
KernelPullRequest