use crate::branch::PyBranch;
use crate::debian::error::Error;
use crate::debian::upstream::PyUpstreamSource;
use crate::debian::TarballKind;
use crate::tree::PyTree;
use crate::workingtree::PyWorkingTree;
use crate::RevisionId;
use pyo3::prelude::*;
use pyo3::types::PyDict;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
pub fn do_import(
tree: &dyn PyWorkingTree,
subpath: &Path,
tarball_filenames: &[&Path],
package: &str,
version: &str,
current_version: Option<&str>,
upstream_branch: &dyn PyBranch,
upstream_revisions: HashMap<TarballKind, (RevisionId, PathBuf)>,
merge_type: Option<&str>,
force: bool,
force_pristine_tar: bool,
committer: Option<&str>,
files_excluded: Option<&[&Path]>,
) -> Result<Vec<(TarballKind, String, RevisionId, Option<bool>, PathBuf)>, Error> {
Python::attach(|py| {
let m = PyModule::import(py, "breezy.plugins.debian.merge_upstream").unwrap();
let do_import = m.getattr("do_import").unwrap();
let kwargs = PyDict::new(py);
kwargs.set_item("tree", tree.to_object(py))?;
kwargs.set_item("subpath", subpath.to_string_lossy().to_string())?;
kwargs.set_item("tarball_filenames", tarball_filenames.to_vec())?;
kwargs.set_item("package", package)?;
kwargs.set_item("version", version)?;
kwargs.set_item("current_version", current_version)?;
kwargs.set_item("upstream_branch", upstream_branch.to_object(py))?;
kwargs.set_item("upstream_revisions", upstream_revisions)?;
kwargs.set_item("merge_type", merge_type)?;
kwargs.set_item("force", force)?;
kwargs.set_item("force_pristine_tar", force_pristine_tar)?;
kwargs.set_item("committer", committer)?;
kwargs.set_item("files_excluded", files_excluded)?;
Ok(do_import.call((), Some(&kwargs))?.extract()?)
})
}
pub fn get_tarballs(
orig_dir: &Path,
tree: &dyn PyTree,
package: &str,
version: &str,
locations: &[&Path],
) -> Result<Vec<PathBuf>, Error> {
Python::attach(|py| {
let m = PyModule::import(py, "breezy.plugins.debian.merge_upstream").unwrap();
let get_tarballs = m.getattr("get_tarballs").unwrap();
Ok(get_tarballs
.call1((
orig_dir,
tree.to_object(py),
package,
version,
locations.to_vec(),
))?
.extract()?)
})
}
pub fn get_existing_imported_upstream_revids<T: PyUpstreamSource>(
upstream_source: &T,
package: &str,
new_upstream_version: &str,
) -> Result<Vec<(TarballKind, String, RevisionId, Option<bool>, PathBuf)>, Error> {
Python::attach(|py| {
let m = PyModule::import(py, "breezy.plugins.debian.merge_upstream").unwrap();
let get_existing_imported_upstream_revids =
m.getattr("get_existing_imported_upstream_revids").unwrap();
Ok(get_existing_imported_upstream_revids
.call1((upstream_source.as_pyobject(), package, new_upstream_version))?
.extract()?)
})
}