add debian backend

This commit is contained in:
steven-omaha
2023-02-27 17:21:56 +01:00
parent 1dced07619
commit 7c4741753e
6 changed files with 261 additions and 7 deletions
@@ -0,0 +1,67 @@
use std::collections::HashSet;
use std::process::Command;
use std::process::ExitStatus;
use anyhow::{Context, Result};
use rust_apt::cache::PackageSort;
use rust_apt::new_cache;
use crate::backend::backend_trait::{Backend, Switches, Text};
use crate::{impl_backend_constants, Group, Package};
#[derive(Debug, Clone)]
pub struct Debian {
pub(crate) packages: HashSet<Package>,
}
const BINARY: Text = "apt";
const SECTION: Text = "debian";
const SWITCHES_INFO: Switches = &["show"];
const SWITCHES_INSTALL: Switches = &["install"];
const SWITCHES_MAKE_DEPENDENCY: Switches = &[]; // not needed
const SWITCHES_REMOVE: Switches = &["remove"];
impl Backend for Debian {
impl_backend_constants!();
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
let cache = new_cache!()?;
let sort = PackageSort::default().installed();
let mut result = HashSet::new();
for pkg in cache.packages(&sort) {
result.insert(Package::from(pkg.name().to_string()));
}
Ok(result)
}
fn get_explicitly_installed_packages(&self) -> Result<HashSet<Package>> {
let cache = new_cache!()?;
let sort = PackageSort::default().installed().manually_installed();
let mut result = HashSet::new();
for pkg in cache.packages(&sort) {
result.insert(Package::from(pkg.name().to_string()));
}
Ok(result)
}
fn make_dependency(&self, packages: &[Package]) -> Result<ExitStatus> {
let mut cmd = Command::new("apt-mark");
cmd.arg("auto");
for p in packages {
cmd.arg(format!("{p}"));
}
cmd.status()
.with_context(|| format!("running command [{cmd:?}]"))
}
}
impl Debian {
pub(crate) fn new() -> Self {
Self {
packages: HashSet::new(),
}
}
}
@@ -1,3 +1,5 @@
#[cfg(feature = "arch")]
pub mod arch;
#[cfg(feature = "debian")]
pub mod debian;
pub mod rust;
+2
View File
@@ -14,5 +14,7 @@ use pacdef_macros::Register;
pub enum Backends {
#[cfg(feature = "arch")]
Arch,
#[cfg(feature = "debian")]
Debian,
Rust,
}
+1 -1
View File
@@ -432,7 +432,7 @@ pub const fn get_version_string() -> &'static str {
fn get_included_backends() -> Vec<&'static str> {
let mut result = vec![];
for backend in Backends::iter() {
result.push(backend.get_section())
result.push(backend.get_section());
}
result.sort_unstable();
result